Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -317,10 +317,32 @@ async def transcript_to_speech(transcript_text, voice, rate, pitch, speed_adjust
|
|
| 317 |
if not timed_audio_segments:
|
| 318 |
return None, "No processable audio segments found."
|
| 319 |
|
|
|
|
| 320 |
final_audio = AudioSegment.silent(duration=max_end_time_ms, frame_rate=24000)
|
| 321 |
for segment in timed_audio_segments:
|
| 322 |
final_audio = final_audio.overlay(segment['audio'], position=segment['start'])
|
|
|
|
|
|
|
| 323 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 324 |
combined_audio_path = tempfile.mktemp(suffix=".mp3")
|
| 325 |
final_audio.export(combined_audio_path, format="mp3")
|
| 326 |
return combined_audio_path, None
|
|
|
|
| 317 |
if not timed_audio_segments:
|
| 318 |
return None, "No processable audio segments found."
|
| 319 |
|
| 320 |
+
oldx= '''
|
| 321 |
final_audio = AudioSegment.silent(duration=max_end_time_ms, frame_rate=24000)
|
| 322 |
for segment in timed_audio_segments:
|
| 323 |
final_audio = final_audio.overlay(segment['audio'], position=segment['start'])
|
| 324 |
+
'''
|
| 325 |
+
final_audio = AudioSegment.silent(duration=int(max_end_time_ms * 1000 + 500), frame_rate=24000)
|
| 326 |
|
| 327 |
+
for segment in timed_audio_segments:
|
| 328 |
+
start_position_ms = int(segment['start'] * 1000)
|
| 329 |
+
audio_to_overlay = segment['audio']
|
| 330 |
+
|
| 331 |
+
if start_position_ms + len(audio_to_overlay) > len(final_audio):
|
| 332 |
+
padding_needed = (start_position_ms + len(audio_to_overlay)) - len(final_audio)
|
| 333 |
+
final_audio += AudioSegment.silent(duration=padding_needed + 100, frame_rate=final_audio.frame_rate)
|
| 334 |
+
|
| 335 |
+
try:
|
| 336 |
+
final_audio = final_audio.overlay(audio_to_overlay, position=start_position_ms)
|
| 337 |
+
except Exception as e:
|
| 338 |
+
print(f"Error during overlay: {e}")
|
| 339 |
+
print(f" - Start position (ms): {start_position_ms}")
|
| 340 |
+
print(f" - Length of audio to overlay (ms): {len(audio_to_overlay)}")
|
| 341 |
+
print(f" - Length of final_audio (ms): {len(final_audio)}")
|
| 342 |
+
# Consider adding logic here to handle the error, e.g., truncating audio_to_overlay
|
| 343 |
+
# or skipping the overlay if it consistently fails.
|
| 344 |
+
|
| 345 |
+
|
| 346 |
combined_audio_path = tempfile.mktemp(suffix=".mp3")
|
| 347 |
final_audio.export(combined_audio_path, format="mp3")
|
| 348 |
return combined_audio_path, None
|