bestoai commited on
Commit
099a00c
·
verified ·
1 Parent(s): ad91a22

Update app.py

Browse files

paramterize output path

Files changed (1) hide show
  1. app.py +20 -5
app.py CHANGED
@@ -11,7 +11,7 @@ async def get_voices():
11
  return {f"{v['ShortName']} ({v['Locale']}, {v['Gender']})": v['ShortName'] for v in voices}
12
 
13
  # Text to speech functionality
14
- async def text_to_speech(text, voice, rate, pitch):
15
  if not text.strip():
16
  return None, gr.Warning("Please enter the text to convert.")
17
  if not voice:
@@ -21,10 +21,25 @@ async def text_to_speech(text, voice, rate, pitch):
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
  # Generate SRT file with specified lines of subtitles
30
  def generate_srt(words, audio_duration, srt_path, num_lines):
 
11
  return {f"{v['ShortName']} ({v['Locale']}, {v['Gender']})": v['ShortName'] for v in voices}
12
 
13
  # Text to speech functionality
14
+ async def text_to_speech(text, voice, rate, pitch, output_path):
15
  if not text.strip():
16
  return None, gr.Warning("Please enter the text to convert.")
17
  if not voice:
 
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
+
25
+ # Save to the specified output path
26
+ await communicate.save(output_path)
27
+ return output_path, None
28
+
29
+ # async def text_to_speech(text, voice, rate, pitch):
30
+ # if not text.strip():
31
+ # return None, gr.Warning("Please enter the text to convert.")
32
+ # if not voice:
33
+ # return None, gr.Warning("Please select a voice.")
34
+
35
+ # voice_short_name = voice.split(" (")[0]
36
+ # rate_str = f"{rate:+d}%"
37
+ # pitch_str = f"{pitch:+d}Hz"
38
+ # communicate = edge_tts.Communicate(text, voice_short_name, rate=rate_str, pitch=pitch_str)
39
+ # with tempfile.NamedTemporaryFile(delete=False, suffix=".mp3") as tmp_file:
40
+ # tmp_path = tmp_file.name
41
+ # await communicate.save(tmp_path)
42
+ # return tmp_path, None
43
 
44
  # Generate SRT file with specified lines of subtitles
45
  def generate_srt(words, audio_duration, srt_path, num_lines):