keshav6936 commited on
Commit
33959c0
·
verified ·
1 Parent(s): 90fb465

Upload 2 files

Browse files
Files changed (2) hide show
  1. app.py +68 -0
  2. requirements.txt +2 -0
app.py ADDED
@@ -0,0 +1,68 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import spaces
2
+ import gradio as gr
3
+ import edge_tts
4
+ import asyncio
5
+ import tempfile
6
+ import os
7
+
8
+ # Get all available voices
9
+ async def get_voices():
10
+ voices = await edge_tts.list_voices()
11
+ return {f"{v['ShortName']} - {v['Locale']} ({v['Gender']})": v['ShortName'] for v in voices}
12
+
13
+ # Text-to-speech function
14
+ async def text_to_speech(text, voice, rate, pitch):
15
+ if not text.strip():
16
+ return None, gr.Warning("Please enter text to convert.")
17
+ if not voice:
18
+ return None, gr.Warning("Please select a voice.")
19
+
20
+ voice_short_name = voice.split(" - ")[0]
21
+ rate_str = f"{rate:+d}%"
22
+ pitch_str = f"{pitch:+d}Hz"
23
+ communicate = edge_tts.Communicate(text, voice_short_name, rate=rate_str, pitch=pitch_str)
24
+ with tempfile.NamedTemporaryFile(delete=False, suffix=".mp3") as tmp_file:
25
+ tmp_path = tmp_file.name
26
+ await communicate.save(tmp_path)
27
+ return tmp_path, None
28
+
29
+ # Gradio interface function
30
+ @spaces.GPU
31
+ def tts_interface(text, voice, rate, pitch):
32
+ audio, warning = asyncio.run(text_to_speech(text, voice, rate, pitch))
33
+ return audio, warning
34
+
35
+ # Create Gradio application
36
+ import gradio as gr
37
+
38
+ async def create_demo():
39
+ voices = await get_voices()
40
+
41
+ description = """
42
+ Experience the power of Voicecloning.be for text-to-speech conversion.
43
+ """
44
+
45
+ demo = gr.Interface(
46
+ fn=tts_interface,
47
+ inputs=[
48
+ gr.Textbox(label="Input Text", lines=5),
49
+ gr.Dropdown(choices=[""] + list(voices.keys()), label="Select Voice", value=""),
50
+ gr.Slider(minimum=-50, maximum=50, value=0, label="Speech Rate Adjustment (%)", step=1),
51
+ gr.Slider(minimum=-20, maximum=20, value=0, label="Pitch Adjustment (Hz)", step=1)
52
+ ],
53
+ outputs=[
54
+ gr.Audio(label="Generated Audio", type="filepath"),
55
+ gr.Markdown(label="Warning", visible=False)
56
+ ],
57
+ title="Voicecloning.be Text-to-Speech",
58
+ description=description,
59
+ article="Experience the power of Voicecloning.be for text-to-speech conversion.",
60
+ analytics_enabled=False,
61
+ allow_flagging=False
62
+ )
63
+ return demo
64
+
65
+ # Run the application
66
+ if __name__ == "__main__":
67
+ demo = asyncio.run(create_demo())
68
+ demo.launch()
requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ edge_tts==6.1.12
2
+ gradio==4.36.1