Spaces:
Running
Running
Michael Hu
commited on
Commit
·
e734196
1
Parent(s):
cb90410
fix
Browse files- utils/tts.py +17 -0
utils/tts.py
CHANGED
|
@@ -35,6 +35,23 @@ def get_best_engine(lang_code: str = 'z') -> TTSEngineBase:
|
|
| 35 |
"""
|
| 36 |
return TTSFactory.create_engine(None, lang_code)
|
| 37 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 38 |
# Legacy function for backward compatibility
|
| 39 |
def generate_speech(text: str, language: str = "z", voice: str = "af_heart", speed: float = 1.0) -> str:
|
| 40 |
"""Generate speech using the best available TTS engine
|
|
|
|
| 35 |
"""
|
| 36 |
return TTSFactory.create_engine(None, lang_code)
|
| 37 |
|
| 38 |
+
# Function to get a TTS engine instance (for backward compatibility)
|
| 39 |
+
def get_tts_engine(engine_type: str = None, lang_code: str = 'z') -> TTSEngineBase:
|
| 40 |
+
"""Get a TTS engine instance
|
| 41 |
+
|
| 42 |
+
This function is maintained for backward compatibility with app.py.
|
| 43 |
+
New code should use the factory pattern implementation directly.
|
| 44 |
+
|
| 45 |
+
Args:
|
| 46 |
+
engine_type (str, optional): Type of engine to create ('kokoro', 'kokoro_space', 'dia', 'dummy')
|
| 47 |
+
If None, the best available engine will be used
|
| 48 |
+
lang_code (str): Language code for the engine
|
| 49 |
+
|
| 50 |
+
Returns:
|
| 51 |
+
TTSEngineBase: An instance of a TTS engine
|
| 52 |
+
"""
|
| 53 |
+
return TTSFactory.create_engine(engine_type, lang_code)
|
| 54 |
+
|
| 55 |
# Legacy function for backward compatibility
|
| 56 |
def generate_speech(text: str, language: str = "z", voice: str = "af_heart", speed: float = 1.0) -> str:
|
| 57 |
"""Generate speech using the best available TTS engine
|