Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from transformers import pipeline
|
| 3 |
+
|
| 4 |
+
# Load the 3 TTS models from your E-motionAssistant Org
|
| 5 |
+
eng_tts = pipeline("text-to-speech", model="E-motionAssistant/text-to-speech-VITS-english")
|
| 6 |
+
sin_tts = pipeline("text-to-speech", model="E-motionAssistant/text-to-speech-VITS-sinhala")
|
| 7 |
+
tam_tts = pipeline("text-to-speech", model="E-motionAssistant/text-to-speech-VITS-tamil")
|
| 8 |
+
|
| 9 |
+
def generate_audio(text, language):
|
| 10 |
+
try:
|
| 11 |
+
if language == "English":
|
| 12 |
+
out = eng_tts(text)
|
| 13 |
+
elif language == "Sinhala":
|
| 14 |
+
out = sin_tts(text)
|
| 15 |
+
elif language == "Tamil":
|
| 16 |
+
out = tam_tts(text)
|
| 17 |
+
else:
|
| 18 |
+
return None
|
| 19 |
+
|
| 20 |
+
# Returns (sampling_rate, audio_data)
|
| 21 |
+
return (out["sampling_rate"], out["audio"][0])
|
| 22 |
+
|
| 23 |
+
except Exception as e:
|
| 24 |
+
print(f"Error: {e}")
|
| 25 |
+
return None
|
| 26 |
+
|
| 27 |
+
# The 'Interface' defines how Vercel will talk to this Space
|
| 28 |
+
demo = gr.Interface(
|
| 29 |
+
fn=generate_audio,
|
| 30 |
+
inputs=[
|
| 31 |
+
gr.Textbox(label="Input Text"),
|
| 32 |
+
gr.Dropdown(["English", "Sinhala", "Tamil"], label="Select Language")
|
| 33 |
+
],
|
| 34 |
+
outputs=gr.Audio(label="Output Audio"),
|
| 35 |
+
api_name="predict"
|
| 36 |
+
)
|
| 37 |
+
|
| 38 |
+
demo.launch()
|