Spaces:
Running
Running
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import librosa
|
| 3 |
+
from asr import transcribe, ASR_EXAMPLES, ASR_LANGUAGES, ASR_NOTE
|
| 4 |
+
from tts import synthesize, TTS_EXAMPLES, TTS_LANGUAGES
|
| 5 |
+
from lid import identify, LID_EXAMPLES
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
mms_transcribe = gr.Interface(
|
| 10 |
+
fn=transcribe,
|
| 11 |
+
inputs=[
|
| 12 |
+
gr.Audio(),
|
| 13 |
+
gr.Dropdown(
|
| 14 |
+
[f"{k} ({v})" for k, v in ASR_LANGUAGES.items()],
|
| 15 |
+
label="Language",
|
| 16 |
+
value="eng English",
|
| 17 |
+
),
|
| 18 |
+
# gr.Checkbox(label="Use Language Model (if available)", default=True),
|
| 19 |
+
],
|
| 20 |
+
outputs="text",
|
| 21 |
+
examples=ASR_EXAMPLES,
|
| 22 |
+
title="Speech-to-text",
|
| 23 |
+
description=(
|
| 24 |
+
"Transcribe audio from a microphone or input file in your desired language."
|
| 25 |
+
),
|
| 26 |
+
article=ASR_NOTE,
|
| 27 |
+
allow_flagging="never",
|
| 28 |
+
)
|
| 29 |
+
|
| 30 |
+
mms_synthesize = gr.Interface(
|
| 31 |
+
fn=synthesize,
|
| 32 |
+
inputs=[
|
| 33 |
+
gr.Text(label="Input text"),
|
| 34 |
+
gr.Dropdown(
|
| 35 |
+
[f"{k} ({v})" for k, v in TTS_LANGUAGES.items()],
|
| 36 |
+
label="Language",
|
| 37 |
+
value="eng English",
|
| 38 |
+
),
|
| 39 |
+
gr.Slider(minimum=0.1, maximum=4.0, value=1.0, step=0.1, label="Speed"),
|
| 40 |
+
],
|
| 41 |
+
outputs=[
|
| 42 |
+
gr.Audio(label="Generated Audio", type="numpy"),
|
| 43 |
+
gr.Text(label="Filtered text after removing OOVs"),
|
| 44 |
+
],
|
| 45 |
+
examples=TTS_EXAMPLES,
|
| 46 |
+
title="Text-to-speech",
|
| 47 |
+
description=("Generate audio in your desired language from input text."),
|
| 48 |
+
allow_flagging="never",
|
| 49 |
+
)
|
| 50 |
+
|
| 51 |
+
mms_identify = gr.Interface(
|
| 52 |
+
fn=identify,
|
| 53 |
+
inputs=[
|
| 54 |
+
gr.Audio(),
|
| 55 |
+
],
|
| 56 |
+
outputs=gr.Label(num_top_classes=10),
|
| 57 |
+
examples=LID_EXAMPLES,
|
| 58 |
+
title="Language Identification",
|
| 59 |
+
description=("Identity the language of input audio."),
|
| 60 |
+
allow_flagging="never",
|
| 61 |
+
)
|
| 62 |
+
|
| 63 |
+
tabbed_interface = gr.TabbedInterface(
|
| 64 |
+
[mms_transcribe, mms_synthesize, mms_identify],
|
| 65 |
+
["Speech-to-text", "Text-to-speech", "Language Identification"],
|
| 66 |
+
)
|
| 67 |
+
|
| 68 |
+
with gr.Blocks() as demo:
|
| 69 |
+
gr.Markdown(
|
| 70 |
+
"<p align='center' style='font-size: 20px;'>MMS</p>"
|
| 71 |
+
)
|
| 72 |
+
gr.HTML(
|
| 73 |
+
"""<center>Text-to-Speech, Speech-to-Text, and Language Recognition for 1,100+ languages.</center>"""
|
| 74 |
+
)
|
| 75 |
+
|
| 76 |
+
tabbed_interface.render()
|
| 77 |
+
|
| 78 |
+
if __name__ == "__main__":
|
| 79 |
+
demo.queue()
|
| 80 |
+
demo.launch()
|