cnph001 commited on
Commit
3d757e5
·
verified ·
1 Parent(s): 2681b4c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -6
app.py CHANGED
@@ -1,3 +1,5 @@
 
 
1
  import spaces
2
  import gradio as gr
3
  import edge_tts
@@ -6,8 +8,15 @@ import tempfile
6
  import os
7
  import re
8
  from pathlib import Path
 
9
  from pydub import AudioSegment
10
- from pydub.silence import strip_silence
 
 
 
 
 
 
11
 
12
  def get_silence(duration_ms=1000):
13
  # Create silent audio segment with specified parameters
@@ -62,7 +71,7 @@ async def generate_audio_with_voice_prefix(text_segment, default_voice, rate, pi
62
  voice4_full = "en-GB-ThomasNeural - en-GB (Male)"
63
  voice4_short = voice4_full.split(" - ")[0]
64
  voice4F_full ="en-US-EmmaNeural - en-US (Female)"
65
- voice4F_short = voice4F_full.split(" - ")[0]
66
  voice5_full = "en-GB-RyanNeural - en-GB (Male)" #Old Man
67
  voice5_short = voice5_full.split(" - ")[0]
68
  voice6_full = "en-GB-MaisieNeural - en-GB (Female)" #Child
@@ -212,7 +221,6 @@ async def transcript_to_speech(transcript_text, voice, rate, pitch):
212
  for path in audio_paths:
213
  try:
214
  audio = AudioSegment.from_mp3(path)
215
- # Remove silence before and after the audio
216
  audio = strip_silence(audio, silence_thresh=-40, min_silence_len=100)
217
  combined_line_audio += audio
218
  os.remove(path)
@@ -242,8 +250,6 @@ async def transcript_to_speech(transcript_text, voice, rate, pitch):
242
  for next_path in next_audio_paths:
243
  try:
244
  next_audio = AudioSegment.from_mp3(next_path)
245
- # Remove silence before and after the audio
246
- next_audio = strip_silence(next_audio, silence_thresh=-40, min_silence_len=100)
247
  combined_line_audio += next_audio
248
  os.remove(next_path)
249
  except FileNotFoundError:
@@ -343,4 +349,4 @@ async def create_demo():
343
 
344
  if __name__ == "__main__":
345
  demo = asyncio.run(create_demo())
346
- demo.launch()
 
1
+ ##fix overlap
2
+
3
  import spaces
4
  import gradio as gr
5
  import edge_tts
 
8
  import os
9
  import re
10
  from pathlib import Path
11
+ from pydub.silence import detect_nonsilent
12
  from pydub import AudioSegment
13
+
14
+ def strip_silence(audio: AudioSegment, silence_thresh=-40, min_silence_len=100):
15
+ nonsilent_ranges = detect_nonsilent(audio, min_silence_len=min_silence_len, silence_thresh=silence_thresh)
16
+ if not nonsilent_ranges:
17
+ return AudioSegment.silent(duration=0)
18
+ return sum([audio[start:end] for start, end in nonsilent_ranges])
19
+
20
 
21
  def get_silence(duration_ms=1000):
22
  # Create silent audio segment with specified parameters
 
71
  voice4_full = "en-GB-ThomasNeural - en-GB (Male)"
72
  voice4_short = voice4_full.split(" - ")[0]
73
  voice4F_full ="en-US-EmmaNeural - en-US (Female)"
74
+ voice4F_short = voice4_full.split(" - ")[0]
75
  voice5_full = "en-GB-RyanNeural - en-GB (Male)" #Old Man
76
  voice5_short = voice5_full.split(" - ")[0]
77
  voice6_full = "en-GB-MaisieNeural - en-GB (Female)" #Child
 
221
  for path in audio_paths:
222
  try:
223
  audio = AudioSegment.from_mp3(path)
 
224
  audio = strip_silence(audio, silence_thresh=-40, min_silence_len=100)
225
  combined_line_audio += audio
226
  os.remove(path)
 
250
  for next_path in next_audio_paths:
251
  try:
252
  next_audio = AudioSegment.from_mp3(next_path)
 
 
253
  combined_line_audio += next_audio
254
  os.remove(next_path)
255
  except FileNotFoundError:
 
349
 
350
  if __name__ == "__main__":
351
  demo = asyncio.run(create_demo())
352
+ demo.launch()