chore: Update TTS functionality with MeloTTS and handle import errors
Browse files- kitt/core/tts.py +10 -2
kitt/core/tts.py
CHANGED
@@ -4,7 +4,6 @@ from collections import namedtuple
|
|
4 |
import soundfile as sf
|
5 |
import torch
|
6 |
from loguru import logger
|
7 |
-
from melo.api import TTS as MeloTTS
|
8 |
from parler_tts import ParlerTTSForConditionalGeneration
|
9 |
from replicate import Client
|
10 |
from transformers import AutoTokenizer
|
@@ -121,15 +120,24 @@ def run_tts_fast(text: str):
|
|
121 |
|
122 |
|
123 |
def load_melo_tts():
|
|
|
|
|
124 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
125 |
model = MeloTTS(language="EN", device=device)
|
126 |
return model
|
127 |
|
128 |
|
129 |
-
|
|
|
|
|
|
|
|
|
130 |
|
131 |
|
132 |
def run_melo_tts(text: str, voice: str):
|
|
|
|
|
|
|
133 |
speed = 1.0
|
134 |
speaker_ids = melo_tts.hps.data.spk2id
|
135 |
audio = melo_tts.tts_to_file(text, speaker_ids["EN-Default"], None, speed=speed)
|
|
|
4 |
import soundfile as sf
|
5 |
import torch
|
6 |
from loguru import logger
|
|
|
7 |
from parler_tts import ParlerTTSForConditionalGeneration
|
8 |
from replicate import Client
|
9 |
from transformers import AutoTokenizer
|
|
|
120 |
|
121 |
|
122 |
def load_melo_tts():
|
123 |
+
from melo.api import TTS as MeloTTS
|
124 |
+
|
125 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
126 |
model = MeloTTS(language="EN", device=device)
|
127 |
return model
|
128 |
|
129 |
|
130 |
+
try:
|
131 |
+
melo_tts = load_melo_tts()
|
132 |
+
except ImportError as e:
|
133 |
+
logger.error(f"Error loading MeloTTS: {e}")
|
134 |
+
melo_tts = None
|
135 |
|
136 |
|
137 |
def run_melo_tts(text: str, voice: str):
|
138 |
+
if melo_tts is None:
|
139 |
+
raise ValueError("MeloTTS not available.")
|
140 |
+
|
141 |
speed = 1.0
|
142 |
speaker_ids = melo_tts.hps.data.spk2id
|
143 |
audio = melo_tts.tts_to_file(text, speaker_ids["EN-Default"], None, speed=speed)
|