Altafo commited on
Commit
09a5167
·
verified ·
1 Parent(s): 64662b3

Upload 3 files

Browse files
Files changed (3) hide show
  1. README .md +13 -0
  2. app.py +67 -0
  3. requirements.txt +2 -0
README .md ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ title: Free-TTS unlimited words
3
+ emoji: 👁
4
+ colorFrom: pink
5
+ colorTo: yellow
6
+ sdk: gradio
7
+ sdk_version: 5.9.1
8
+ app_file: app.py
9
+ pinned: false
10
+ license: gpl-2.0
11
+ ---
12
+
13
+ Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
app.py ADDED
@@ -0,0 +1,67 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import edge_tts
3
+ import asyncio
4
+ import tempfile
5
+ import os
6
+
7
+ async def get_voices():
8
+ voices = await edge_tts.list_voices()
9
+ return {f"{v['ShortName']} - {v['Locale']} ({v['Gender']})": v['ShortName'] for v in voices}
10
+
11
+ async def text_to_speech(text, voice, rate, pitch):
12
+ if not text.strip():
13
+ return None, "Please enter text to convert."
14
+ if not voice:
15
+ return None, "Please select a voice."
16
+
17
+ voice_short_name = voice.split(" - ")[0]
18
+ rate_str = f"{rate:+d}%"
19
+ pitch_str = f"{pitch:+d}Hz"
20
+ communicate = edge_tts.Communicate(text, voice_short_name, rate=rate_str, pitch=pitch_str)
21
+ with tempfile.NamedTemporaryFile(delete=False, suffix=".mp3") as tmp_file:
22
+ tmp_path = tmp_file.name
23
+ await communicate.save(tmp_path)
24
+ return tmp_path, None
25
+
26
+ async def tts_interface(text, voice, rate, pitch):
27
+ audio, warning = await text_to_speech(text, voice, rate, pitch)
28
+ if warning:
29
+ return audio, gr.Warning(warning)
30
+ return audio, None
31
+
32
+ async def create_demo():
33
+ voices = await get_voices()
34
+
35
+ description = """
36
+ Convert text to speech using Free-TTS_unlimited-words Adjust speech rate and pitch: 0 is default, positive values increase, negative values decrease.
37
+
38
+ """
39
+
40
+ demo = gr.Interface(
41
+ fn=tts_interface,
42
+ inputs=[
43
+ gr.Textbox(label="Input Text", lines=5),
44
+ gr.Dropdown(choices=[""] + list(voices.keys()), label="Select Voice", value=""),
45
+ gr.Slider(minimum=-50, maximum=50, value=0, label="Speech Rate Adjustment (%)", step=1),
46
+ gr.Slider(minimum=-20, maximum=20, value=0, label="Pitch Adjustment (Hz)", step=1)
47
+ ],
48
+ outputs=[
49
+ gr.Audio(label="Generated Audio", type="filepath"),
50
+ gr.Markdown(label="Warning", visible=False)
51
+ ],
52
+ title="Free-TTS_unlimited-words",
53
+ description=description,
54
+ article="Experience the power of Edge TTS for text-to-speech conversion, and explore our advanced Text-to-Video Converter for even more creative possibilities!",
55
+ analytics_enabled=False,
56
+ allow_flagging="manual",
57
+ api_name=None
58
+ )
59
+ return demo
60
+
61
+ async def main():
62
+ demo = await create_demo()
63
+ demo.queue(default_concurrency_limit=5)
64
+ demo.launch(show_api=False)
65
+
66
+ if __name__ == "__main__":
67
+ asyncio.run(main())
requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ edge_tts==6.1.12
2
+ gradio==4.36.1