Refactor TTS loading logic for lazy loading and error handling
Browse files- kitt/core/tts.py +7 -5
kitt/core/tts.py
CHANGED
@@ -99,15 +99,17 @@ def load_melo_tts():
|
|
99 |
return model
|
100 |
|
101 |
|
102 |
-
|
103 |
-
melo_tts = load_melo_tts()
|
104 |
-
except ImportError as e:
|
105 |
-
logger.error(f"Error loading MeloTTS: {e}")
|
106 |
-
melo_tts = None
|
107 |
|
108 |
|
109 |
def run_melo_tts(text: str, voice: str):
|
|
|
110 |
if melo_tts is None:
|
|
|
|
|
|
|
|
|
|
|
111 |
raise ValueError("MeloTTS not available.")
|
112 |
|
113 |
speed = 1.0
|
|
|
99 |
return model
|
100 |
|
101 |
|
102 |
+
melo_tts = None
|
|
|
|
|
|
|
|
|
103 |
|
104 |
|
105 |
def run_melo_tts(text: str, voice: str):
|
106 |
+
global melo_tts
|
107 |
if melo_tts is None:
|
108 |
+
try:
|
109 |
+
melo_tts = load_melo_tts()
|
110 |
+
except ImportError as e:
|
111 |
+
logger.error(f"Error loading MeloTTS: {e}")
|
112 |
+
melo_tts = None
|
113 |
raise ValueError("MeloTTS not available.")
|
114 |
|
115 |
speed = 1.0
|