Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from transformers import pipeline
|
| 3 |
+
from TTS.api import TTS
|
| 4 |
+
|
| 5 |
+
translator = pipeline(
|
| 6 |
+
"translation_en_to_es",
|
| 7 |
+
model="Helsinki-NLP/opus-mt-en-es"
|
| 8 |
+
)
|
| 9 |
+
|
| 10 |
+
# Load YOUR trained model
|
| 11 |
+
tts = TTS(model_path="./my_voice_model")
|
| 12 |
+
|
| 13 |
+
def translate_and_speak(text):
|
| 14 |
+
translated = translator(text)[0]['translation_text']
|
| 15 |
+
|
| 16 |
+
output = "output.wav"
|
| 17 |
+
tts.tts_to_file(
|
| 18 |
+
text=translated,
|
| 19 |
+
language="es",
|
| 20 |
+
file_path=output
|
| 21 |
+
)
|
| 22 |
+
|
| 23 |
+
return translated, output
|
| 24 |
+
|
| 25 |
+
demo = gr.Interface(
|
| 26 |
+
fn=translate_and_speak,
|
| 27 |
+
inputs="text",
|
| 28 |
+
outputs=["text", "audio"]
|
| 29 |
+
)
|
| 30 |
+
|
| 31 |
+
demo.launch()
|