lelafav502 commited on
Commit
a854603
1 Parent(s): 4fa3442

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +44 -0
app.py ADDED
@@ -0,0 +1,44 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import edge_tts
2
+ import gradio as gr
3
+ import tempfile
4
+
5
+ language_dict = {
6
+ 'English-Jenny (Female)': 'en-US-JennyNeural',
7
+ }
8
+
9
+ async def text_to_speech_edge(text, language_code, rate, volume, pitch):
10
+ voice = language_dict.get(language_code, "default_voice")
11
+
12
+ rates = "+" + str(rate) + "%" if rate >= 0 else str(rate) + "%"
13
+ volumes = "+" + str(volume) + "%" if volume >= 0 else str(volume) + "%"
14
+ pitchs = "+" + str(pitch) + "Hz" if pitch >= 0 else str(pitch) + "Hz"
15
+
16
+ communicate = edge_tts.Communicate(text, voice, rate=rates, volume=volumes, pitch=pitchs, proxy=None)
17
+
18
+ with tempfile.NamedTemporaryFile(delete=False, suffix=".wav") as tmp_file:
19
+ tmp_path = tmp_file.name
20
+ await communicate.save(tmp_path)
21
+ return f"Speech synthesis completed for: {text}", tmp_path
22
+
23
+ input_text = gr.Textbox(lines=5, label="Input Text")
24
+ output_text = gr.Textbox(label="Output Text")
25
+ output_audio = gr.Audio(type="filepath", label="Exported Audio")
26
+ language = gr.Dropdown(choices=list(language_dict.keys()), label="Choose the Voice Model")
27
+ rate = gr.Slider(-100, 100,step=1,value=0,label="Rate",info="Rate",interactive=True)
28
+
29
+ volume = gr.Slider(-100,100,step=1,value=0,label="Volume",info="Volume",interactive=True)
30
+
31
+ pitch = gr.Slider(-100,100,step=1,value=0,label="Pitch",info="Pitch",interactive=True)
32
+
33
+
34
+
35
+ interface = gr.Interface(
36
+ fn=text_to_speech_edge,
37
+ inputs=[input_text, language, rate, volume,pitch],
38
+ outputs=[output_text, output_audio],
39
+ title="Edge-TTS",
40
+ description="Microsoft Edge Text-To-Speech (Created by Yash Chouhan)",
41
+
42
+ )
43
+
44
+ interface.launch(share=True)