Spaces:
Runtime error
Runtime error
Update tts_engine.py
Browse files1234457891067891011128 unmodified lines212223252425261 unmodified line28293033343531323334353642373839404142431 unmodified line454647484950515253545559565758import osfrom TTS.api import TTS
# Map our app languages → Coqui TTS codesLANG_MAP = { "english": "en", "yoruba": "en", # no native Yoruba model, fallback to English phonemes "hausa": "en", # same here, fallback "igbo": "en", # same here "pidgin": "en", # close enough to English "yoruba": "en", "hausa": "en", "igbo": "en", "pidgin": "en", "esan": "en", "tiv": "en", "calabar": "en",8 unmodified lines self.tts = None
if self.use_coqui: # Multilingual model (limited codes available) self.tts = TTS( "tts_models/multilingual/multi-dataset/your_tts", progress_bar=False,1 unmodified line )
def speak(self, text, lang="english", voice_clone=False): """ Returns path to generated audio file (for Gradio playback). """ if not text: return None
out_file = "output.wav"
if self.use_coqui: # normalize language lang_code = LANG_MAP.get(lang.lower(), "en")
if voice_clone and os.path.exists("my_voice.wav"): # clone your own voice self.tts.tts_to_file( text=text, file_path=out_file,1 unmodified line language=lang_code ) else: # fallback to a neutral synthetic voice self.tts.tts_to_file( text=text, file_path=out_file, speaker_wav=None, # Let model pick default embedding language=lang_code ) else: # Lazy import to avoid HF crash import pyttsx3 engine = pyttsx3.init() engine.save_to_file(text, out_file)tts_engine.py+7-11