Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -7,6 +7,7 @@ import os
|
|
7 |
import re
|
8 |
from pathlib import Path
|
9 |
from pydub import AudioSegment
|
|
|
10 |
|
11 |
def get_silence(duration_ms=1000):
|
12 |
# Create silent audio segment with specified parameters
|
@@ -61,7 +62,7 @@ async def generate_audio_with_voice_prefix(text_segment, default_voice, rate, pi
|
|
61 |
voice4_full = "en-GB-ThomasNeural - en-GB (Male)"
|
62 |
voice4_short = voice4_full.split(" - ")[0]
|
63 |
voice4F_full ="en-US-EmmaNeural - en-US (Female)"
|
64 |
-
voice4F_short =
|
65 |
voice5_full = "en-GB-RyanNeural - en-GB (Male)" #Old Man
|
66 |
voice5_short = voice5_full.split(" - ")[0]
|
67 |
voice6_full = "en-GB-MaisieNeural - en-GB (Female)" #Child
|
@@ -211,6 +212,8 @@ async def transcript_to_speech(transcript_text, voice, rate, pitch):
|
|
211 |
for path in audio_paths:
|
212 |
try:
|
213 |
audio = AudioSegment.from_mp3(path)
|
|
|
|
|
214 |
combined_line_audio += audio
|
215 |
os.remove(path)
|
216 |
except FileNotFoundError:
|
@@ -239,6 +242,8 @@ async def transcript_to_speech(transcript_text, voice, rate, pitch):
|
|
239 |
for next_path in next_audio_paths:
|
240 |
try:
|
241 |
next_audio = AudioSegment.from_mp3(next_path)
|
|
|
|
|
242 |
combined_line_audio += next_audio
|
243 |
os.remove(next_path)
|
244 |
except FileNotFoundError:
|
|
|
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 |
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 |
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)
|
219 |
except FileNotFoundError:
|
|
|
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:
|