usuario101 commited on
Commit
ec4f68d
1 Parent(s): 51b2300

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -7
app.py CHANGED
@@ -6,13 +6,14 @@ import os
6
  from typing import Dict, Tuple
7
  from collections import defaultdict
8
 
9
- async def text_to_speech(text: str, voice: str, rate: float, volume: float) -> str:
10
  output_file = tempfile.NamedTemporaryFile(delete=False, suffix=".mp3")
11
  communicate = edge_tts.Communicate(
12
  text,
13
  voice,
14
- rate=f"{'+' if rate >= 0 else ''}{rate}%",
15
- volume=f"+{volume}%"
 
16
  )
17
  await communicate.save(output_file.name)
18
  return output_file.name
@@ -29,11 +30,11 @@ def process_voices(voices: Dict[str, Dict]) -> Dict[str, Dict[str, str]]:
29
  processed_voices[language][speaker_name] = full_name
30
  return dict(processed_voices)
31
 
32
- async def generate_speech(text_input, selected_language, selected_speaker, rate, volume, processed_voices):
33
  if not text_input:
34
  return "Por favor, introduce un texto."
35
  selected_voice = processed_voices[selected_language][selected_speaker]
36
- output_file = await text_to_speech(text_input, selected_voice, rate, volume)
37
  return output_file
38
 
39
  async def main():
@@ -53,7 +54,7 @@ async def main():
53
  with gr.Row():
54
  # Idiomas filtrados y "es-US" como predeterminado
55
  selected_language = gr.Dropdown(filtered_languages, label="Selecciona el idioma:", value="es-US")
56
-
57
  # Obtener la lista de hablantes para "es-US"
58
  initial_speakers = list(processed_voices["es-US"].keys())
59
  # Seleccionar "Alonso" si está disponible, de lo contrario, el primer hablante de la lista
@@ -63,6 +64,7 @@ async def main():
63
  with gr.Row():
64
  rate_slider = gr.Slider(minimum=-20, maximum=20, value=0, step=1, label="Velocidad (%)")
65
  volume_slider = gr.Slider(minimum=0, maximum=100, value=0, step=1, label="Volumen (%)")
 
66
 
67
  btn = gr.Button("Generar voz")
68
 
@@ -74,7 +76,7 @@ async def main():
74
 
75
  btn.click(
76
  generate_speech,
77
- inputs=[text_input, selected_language, selected_speaker, rate_slider, volume_slider, gr.State(processed_voices)],
78
  outputs=audio_output
79
  )
80
 
 
6
  from typing import Dict, Tuple
7
  from collections import defaultdict
8
 
9
+ async def text_to_speech(text: str, voice: str, rate: float, volume: float, pitch: float) -> str:
10
  output_file = tempfile.NamedTemporaryFile(delete=False, suffix=".mp3")
11
  communicate = edge_tts.Communicate(
12
  text,
13
  voice,
14
+ rate=f"{'+' if rate >= 0 else ''}{rate}%",
15
+ volume=f"+{volume}%",
16
+ pitch=f"{'+' if pitch >= 0 else ''}{pitch}Hz"
17
  )
18
  await communicate.save(output_file.name)
19
  return output_file.name
 
30
  processed_voices[language][speaker_name] = full_name
31
  return dict(processed_voices)
32
 
33
+ async def generate_speech(text_input, selected_language, selected_speaker, rate, volume, pitch, processed_voices):
34
  if not text_input:
35
  return "Por favor, introduce un texto."
36
  selected_voice = processed_voices[selected_language][selected_speaker]
37
+ output_file = await text_to_speech(text_input, selected_voice, rate, volume, pitch)
38
  return output_file
39
 
40
  async def main():
 
54
  with gr.Row():
55
  # Idiomas filtrados y "es-US" como predeterminado
56
  selected_language = gr.Dropdown(filtered_languages, label="Selecciona el idioma:", value="es-US")
57
+
58
  # Obtener la lista de hablantes para "es-US"
59
  initial_speakers = list(processed_voices["es-US"].keys())
60
  # Seleccionar "Alonso" si está disponible, de lo contrario, el primer hablante de la lista
 
64
  with gr.Row():
65
  rate_slider = gr.Slider(minimum=-20, maximum=20, value=0, step=1, label="Velocidad (%)")
66
  volume_slider = gr.Slider(minimum=0, maximum=100, value=0, step=1, label="Volumen (%)")
67
+ pitch_slider = gr.Slider(minimum=-20, maximum=20, value=0, step=1, label="Tono (Hz)")
68
 
69
  btn = gr.Button("Generar voz")
70
 
 
76
 
77
  btn.click(
78
  generate_speech,
79
+ inputs=[text_input, selected_language, selected_speaker, rate_slider, volume_slider, pitch_slider, gr.State(processed_voices)],
80
  outputs=audio_output
81
  )
82