asdaswadefswefr commited on
Commit
6d93611
·
verified ·
1 Parent(s): d81bde6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -39
app.py CHANGED
@@ -2,19 +2,18 @@ import gradio as gr
2
  import edge_tts
3
  import asyncio
4
  import tempfile
5
- import os
6
 
7
- # Get all available voices
8
  async def get_voices():
9
  voices = await edge_tts.list_voices()
10
  return {f"{v['ShortName']} - {v['Locale']} ({v['Gender']})": v['ShortName'] for v in voices}
11
 
12
- # Text-to-speech function
13
  async def text_to_speech(text, voice, rate, pitch):
14
  if not text.strip():
15
- return None, gr.Warning("Please enter text to convert.")
16
  if not voice:
17
- return None, gr.Warning("Please select a voice.")
18
 
19
  voice_short_name = voice.split(" - ")[0]
20
  rate_str = f"{rate:+d}%"
@@ -25,55 +24,33 @@ async def text_to_speech(text, voice, rate, pitch):
25
  await communicate.save(tmp_path)
26
  return tmp_path, None
27
 
28
- # Gradio interface function
29
  def tts_interface(text, voice, rate, pitch):
30
  audio, warning = asyncio.run(text_to_speech(text, voice, rate, pitch))
31
  return audio, warning
32
 
33
- # Create Gradio application
34
- import gradio as gr
35
-
36
  async def create_demo():
37
  voices = await get_voices()
38
 
39
- description = """
40
- Convert text to speech using Microsoft Edge TTS. Adjust speech rate and pitch: 0 is default, positive values increase, negative values decrease.
41
-
42
- 🎥 **Exciting News: Introducing our Text-to-Video Converter!** 🎥
43
-
44
- Take your content creation to the next level with our cutting-edge Text-to-Video Converter!
45
- Transform your words into stunning, professional-quality videos in just a few clicks.
46
-
47
- ✨ Features:
48
- • Convert text to engaging videos with customizable visuals
49
- • Choose from 40+ languages and 300+ voices
50
- • Perfect for creating audiobooks, storytelling, and language learning materials
51
- • Ideal for educators, content creators, and language enthusiasts
52
-
53
- Ready to revolutionize your content? [Click here to try our Text-to-Video Converter now!](https://text2video.wingetgui.com/)
54
- """
55
-
56
  demo = gr.Interface(
57
  fn=tts_interface,
58
  inputs=[
59
- gr.Textbox(label="Input Text", lines=5),
60
- gr.Dropdown(choices=[""] + list(voices.keys()), label="Select Voice", value=""),
61
- gr.Slider(minimum=-50, maximum=50, value=0, label="Speech Rate Adjustment (%)", step=1),
62
- gr.Slider(minimum=-20, maximum=20, value=0, label="Pitch Adjustment (Hz)", step=1)
63
  ],
64
  outputs=[
65
- gr.Audio(label="Generated Audio", type="filepath"),
66
- gr.Markdown(label="Warning", visible=False)
67
  ],
68
- title="Edge TTS Text-to-Speech",
69
- description=description,
70
- 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!",
71
- analytics_enabled=False,
72
- allow_flagging=False
73
  )
74
  return demo
75
 
76
- # Run the application
77
  if __name__ == "__main__":
78
  demo = asyncio.run(create_demo())
79
- demo.launch()
 
2
  import edge_tts
3
  import asyncio
4
  import tempfile
 
5
 
6
+ # Função para listar as vozes disponíveis
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
+ # Função de texto para fala
12
  async def text_to_speech(text, voice, rate, pitch):
13
  if not text.strip():
14
+ return None, "Por favor, insira um texto para converter."
15
  if not voice:
16
+ return None, "Por favor, selecione uma voz."
17
 
18
  voice_short_name = voice.split(" - ")[0]
19
  rate_str = f"{rate:+d}%"
 
24
  await communicate.save(tmp_path)
25
  return tmp_path, None
26
 
27
+ # Função da interface Gradio
28
  def tts_interface(text, voice, rate, pitch):
29
  audio, warning = asyncio.run(text_to_speech(text, voice, rate, pitch))
30
  return audio, warning
31
 
32
+ # Criar a aplicação Gradio
 
 
33
  async def create_demo():
34
  voices = await get_voices()
35
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
36
  demo = gr.Interface(
37
  fn=tts_interface,
38
  inputs=[
39
+ gr.Textbox(label="Texto de Entrada", lines=5),
40
+ gr.Dropdown(choices=[""] + list(voices.keys()), label="Selecionar Voz", value=""),
41
+ gr.Slider(minimum=-50, maximum=50, value=0, label="Ajuste de Taxa de Fala (%)", step=1),
42
+ gr.Slider(minimum=-20, maximum=20, value=0, label="Ajuste de Tom (Hz)", step=1)
43
  ],
44
  outputs=[
45
+ gr.Audio(label="Áudio Gerado", type="filepath"),
46
+ gr.Markdown(label="Aviso", visible=False)
47
  ],
48
+ title="Texto para Fala com Edge TTS",
49
+ description="Converta texto em fala usando Microsoft Edge TTS."
 
 
 
50
  )
51
  return demo
52
 
53
+ # Executar a aplicação
54
  if __name__ == "__main__":
55
  demo = asyncio.run(create_demo())
56
+ demo.launch()