Spaces:
Running
Running
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# app.py — Space 5
|
| 2 |
+
# requirements.txt: transformers, torch, gradio, TTS, numpy, soundfile
|
| 3 |
+
|
| 4 |
+
import gradio as gr
|
| 5 |
+
from transformers import pipeline
|
| 6 |
+
from TTS.api import TTS
|
| 7 |
+
import numpy as np
|
| 8 |
+
|
| 9 |
+
asr = pipeline("automatic-speech-recognition", model="E-motionAssistant/mms-300m-multilingual-ser")
|
| 10 |
+
|
| 11 |
+
tts_english = TTS(model_name="E-motionAssistant/text-to-speech-VITS-english", progress_bar=False)
|
| 12 |
+
tts_sinhala = TTS(model_name="E-motionAssistant/Text-to-speech-VITS-sinhala", progress_bar=False)
|
| 13 |
+
tts_tamil = TTS(model_name="E-motionAssistant/text-to-speech-VITS-tamil", progress_bar=False)
|
| 14 |
+
|
| 15 |
+
def transcribe(audio):
|
| 16 |
+
return asr(audio)["text"]
|
| 17 |
+
|
| 18 |
+
def speak_english(text): return (22050, np.array(tts_english.tts(text)))
|
| 19 |
+
def speak_sinhala(text): return (22050, np.array(tts_sinhala.tts(text)))
|
| 20 |
+
def speak_tamil(text): return (22050, np.array(tts_tamil.tts(text)))
|
| 21 |
+
|
| 22 |
+
with gr.Blocks() as demo:
|
| 23 |
+
gr.TabbedInterface(
|
| 24 |
+
[
|
| 25 |
+
gr.Interface(fn=transcribe, inputs=gr.Audio(type="filepath"), outputs=gr.Textbox(), title="ASR"),
|
| 26 |
+
gr.Interface(fn=speak_english, inputs=gr.Textbox(), outputs=gr.Audio(), title="TTS English"),
|
| 27 |
+
gr.Interface(fn=speak_sinhala, inputs=gr.Textbox(), outputs=gr.Audio(), title="TTS Sinhala"),
|
| 28 |
+
gr.Interface(fn=speak_tamil, inputs=gr.Textbox(), outputs=gr.Audio(), title="TTS Tamil"),
|
| 29 |
+
],
|
| 30 |
+
["ASR (MMS)", "TTS English", "TTS Sinhala", "TTS Tamil"]
|
| 31 |
+
)
|
| 32 |
+
|
| 33 |
+
demo.launch()
|