| import gradio as gr | |
| from transformers import pipeline | |
| from TTS.api import TTS | |
| translator = pipeline( | |
| "translation_en_to_es", | |
| model="Helsinki-NLP/opus-mt-en-es" | |
| ) | |
| # Load YOUR trained model | |
| tts = TTS(model_path="./my_voice_model") | |
| def translate_and_speak(text): | |
| translated = translator(text)[0]['translation_text'] | |
| output = "output.wav" | |
| tts.tts_to_file( | |
| text=translated, | |
| language="es", | |
| file_path=output | |
| ) | |
| return translated, output | |
| demo = gr.Interface( | |
| fn=translate_and_speak, | |
| inputs="text", | |
| outputs=["text", "audio"] | |
| ) | |
| demo.launch() |