Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -17,12 +17,6 @@ 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 |
-
# 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)
|
@@ -35,10 +29,16 @@ def strip_silence(audio: AudioSegment, silence_thresh=-40, min_silence_len=100,
|
|
35 |
# Add padding before and after the trimmed audio
|
36 |
# Ensure the padding doesn't exceed the trimmed boundaries
|
37 |
start_trim = max(0, start_trim - silence_padding_ms) # Ensure no negative start
|
38 |
-
|
39 |
-
|
40 |
end_trim = min(len(audio), end_trim + silence_padding_ms) # Ensure end doesn't go past audio length
|
41 |
# Return the trimmed and padded audio
|
|
|
|
|
|
|
|
|
|
|
|
|
42 |
return audio[start_trim:end_trim]
|
43 |
|
44 |
|
@@ -142,7 +142,7 @@ async def generate_audio_with_voice_prefix(text_segment, default_voice, rate, pi
|
|
142 |
await communicate.save(audio_path)
|
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:
|
@@ -182,12 +182,13 @@ async def process_transcript_line(line, default_voice, rate, pitch):
|
|
182 |
check1 = True
|
183 |
process_next = False
|
184 |
for part in split_parts:
|
185 |
-
if part == '"':
|
186 |
process_next = not process_next
|
|
|
187 |
continue
|
188 |
if process_next and part.strip():
|
189 |
-
if part == split_parts[-1]: # check if this is laster iteration,
|
190 |
-
|
191 |
audio_path = await generate_audio_with_voice_prefix(part, default_voice, rate, pitch)
|
192 |
if audio_path:
|
193 |
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 |
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)
|
|
|
29 |
# Add padding before and after the trimmed audio
|
30 |
# Ensure the padding doesn't exceed the trimmed boundaries
|
31 |
start_trim = max(0, start_trim - silence_padding_ms) # Ensure no negative start
|
32 |
+
if not check1:
|
33 |
+
silence_padding_ms=00
|
34 |
end_trim = min(len(audio), end_trim + silence_padding_ms) # Ensure end doesn't go past audio length
|
35 |
# Return the trimmed and padded audio
|
36 |
+
# Debugging: print input arguments
|
37 |
+
print(f"Audio length: {len(audio)} ms")
|
38 |
+
print(f"Silence threshold: {silence_thresh} dB")
|
39 |
+
print(f"Minimum silence length: {min_silence_len} ms")
|
40 |
+
print(f"Silence padding: {silence_padding_ms} ms")
|
41 |
+
print(f"Check1: {check1}**")
|
42 |
return audio[start_trim:end_trim]
|
43 |
|
44 |
|
|
|
142 |
await communicate.save(audio_path)
|
143 |
|
144 |
audio = AudioSegment.from_mp3(audio_path)
|
145 |
+
if not 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:
|
|
|
182 |
check1 = True
|
183 |
process_next = False
|
184 |
for part in split_parts:
|
185 |
+
if part == '"': #process text that are inside quote
|
186 |
process_next = not process_next
|
187 |
+
check1 = False # set it to False
|
188 |
continue
|
189 |
if process_next and part.strip():
|
190 |
+
#if part == split_parts[-1]: # check if this is laster iteration,
|
191 |
+
# check1 = False # set it to False
|
192 |
audio_path = await generate_audio_with_voice_prefix(part, default_voice, rate, pitch)
|
193 |
if audio_path:
|
194 |
audio_segments.append(audio_path)
|