Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -17,6 +17,12 @@ default_voice_short= ""
|
|
| 17 |
check1 = False # set global variable to check to see if process_text is begin of transcript line or not.
|
| 18 |
|
| 19 |
def strip_silence(audio: AudioSegment, silence_thresh=-40, min_silence_len=100, silence_padding_ms=100):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
from pydub.silence import detect_nonsilent
|
| 21 |
# Detect non-silent regions
|
| 22 |
nonsilent = detect_nonsilent(audio, min_silence_len=min_silence_len, silence_thresh=silence_thresh)
|
|
@@ -137,11 +143,11 @@ async def generate_audio_with_voice_prefix(text_segment, default_voice, rate, pi
|
|
| 137 |
|
| 138 |
audio = AudioSegment.from_mp3(audio_path)
|
| 139 |
if check1:
|
| 140 |
-
print(f"
|
| 141 |
audio = strip_silence(audio, silence_thresh=-40, min_silence_len=50, silence_padding_ms=50) ##silence between sentences
|
| 142 |
else:
|
| 143 |
-
audio = strip_silence(audio, silence_thresh=-40, min_silence_len=50, silence_padding_ms=
|
| 144 |
-
print(f"
|
| 145 |
stripped_path = tempfile.mktemp(suffix=".mp3")
|
| 146 |
audio.export(stripped_path, format="mp3")
|
| 147 |
return stripped_path
|
|
@@ -180,9 +186,8 @@ async def process_transcript_line(line, default_voice, rate, pitch):
|
|
| 180 |
process_next = not process_next
|
| 181 |
continue
|
| 182 |
if process_next and part.strip():
|
| 183 |
-
if
|
| 184 |
-
|
| 185 |
-
check1 = False # After first iteration, set it to False
|
| 186 |
audio_path = await generate_audio_with_voice_prefix(part, default_voice, rate, pitch)
|
| 187 |
if audio_path:
|
| 188 |
audio_segments.append(audio_path)
|
|
|
|
| 17 |
check1 = False # set global variable to check to see if process_text is begin of transcript line or not.
|
| 18 |
|
| 19 |
def strip_silence(audio: AudioSegment, silence_thresh=-40, min_silence_len=100, silence_padding_ms=100):
|
| 20 |
+
# Debugging: print input arguments
|
| 21 |
+
print(f"Audio length: {len(audio)} ms")
|
| 22 |
+
print(f"Silence threshold: {silence_thresh} dB")
|
| 23 |
+
print(f"Minimum silence length: {min_silence_len} ms")
|
| 24 |
+
print(f"Silence padding: {silence_padding_ms} ms")
|
| 25 |
+
|
| 26 |
from pydub.silence import detect_nonsilent
|
| 27 |
# Detect non-silent regions
|
| 28 |
nonsilent = detect_nonsilent(audio, min_silence_len=min_silence_len, silence_thresh=silence_thresh)
|
|
|
|
| 143 |
|
| 144 |
audio = AudioSegment.from_mp3(audio_path)
|
| 145 |
if check1:
|
| 146 |
+
print(f"not last part of sentence - SHORT silence")
|
| 147 |
audio = strip_silence(audio, silence_thresh=-40, min_silence_len=50, silence_padding_ms=50) ##silence between sentences
|
| 148 |
else:
|
| 149 |
+
audio = strip_silence(audio, silence_thresh=-40, min_silence_len=50, silence_padding_ms=100) ##less silence for mid-sentence segments
|
| 150 |
+
print(f"Last part of sentence - long silence")
|
| 151 |
stripped_path = tempfile.mktemp(suffix=".mp3")
|
| 152 |
audio.export(stripped_path, format="mp3")
|
| 153 |
return stripped_path
|
|
|
|
| 186 |
process_next = not process_next
|
| 187 |
continue
|
| 188 |
if process_next and part.strip():
|
| 189 |
+
if if part == split_parts[-1]: # check if this is laster iteration,
|
| 190 |
+
check1 = False # set it to False
|
|
|
|
| 191 |
audio_path = await generate_audio_with_voice_prefix(part, default_voice, rate, pitch)
|
| 192 |
if audio_path:
|
| 193 |
audio_segments.append(audio_path)
|