Yuyang2022 commited on
Commit
7cd7a60
1 Parent(s): 1ff5f6d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -16
app.py CHANGED
@@ -1,24 +1,24 @@
1
  from transformers import pipeline
 
2
  import gradio as gr
3
- from gtts import gTTS
4
 
5
  pipe = pipeline(model="Yuyang2022/yue") # change to "your-username/the-name-you-picked"
6
- language = "en"
 
7
 
8
-
9
- def translate(audio, language):
10
  text = pipe(audio)["text"]
11
-
12
- myobj = gTTS(text=text,lang=language, slow=False, lang_check=True)
13
-
14
- return myobj.write_to_fp("wav")
 
 
 
15
 
16
- iface = gr.Interface(
17
- fn=translate,
18
- inputs=[gr.Audio(source="microphone", type="filepath"), gr.Textbox(value = "en")],
19
- outputs="audio",
20
- title="translation-speeh to speech",
21
- description="Realtime demo for speech translation.",
22
- )
23
 
24
- iface.launch()
 
1
  from transformers import pipeline
2
+ import tempfile
3
  import gradio as gr
4
+ from neon_tts_plugin_coqui import CoquiTTS
5
 
6
  pipe = pipeline(model="Yuyang2022/yue") # change to "your-username/the-name-you-picked"
7
+ LANGUAGES = list(CoquiTTS.langs.keys())
8
+ coquiTTS = CoquiTTS()
9
 
10
+ def audio_tts(audio, language: str):
 
11
  text = pipe(audio)["text"]
12
+ with tempfile.NamedTemporaryFile(suffix=".wav", delete=False) as fp:
13
+ coquiTTS.get_tts(text, fp, speaker = {"language" : language})
14
+ return fp.name
15
+
16
+ inputs = [gr.Audio(source="microphone", type="filepath"),
17
+ gr.Dropdown(label="Language", LANGUAGES, value="en")]
18
+ outputs = gr.Audio(label="Output")
19
 
20
+ demo = gr.Interface(fn=audio_tts, inputs=inputs, outputs=outputs,
21
+ title="translation-speeh to speech",
22
+ description="Realtime demo for speech translation.",)
 
 
 
 
23
 
24
+ demo.launch()