Spaces:
Running
Running
File size: 454 Bytes
81e781d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
from gtts import gTTS
import tempfile
# Language dictionary for dropdown
LANGUAGES = {
"English (US)": "en",
"Spanish": "es",
"French": "fr",
"Portuguese": "pt",
"Mandarin (China Mainland)": "zh-CN",
"Mandarin (Taiwan)": "zh-TW",
}
def generate_tts(text, lang_code):
tts = gTTS(text, lang=lang_code)
with tempfile.NamedTemporaryFile(suffix=".mp3", delete=False) as fp:
tts.save(fp.name)
return fp.name
|