| from pydub import AudioSegment | |
| def mix_speech_with_background(original_audio_path: str, speech_segments: list) -> str: | |
| background = AudioSegment.from_wav(original_audio_path) | |
| output = background | |
| for seg in speech_segments: | |
| speech = AudioSegment.from_wav(seg["file"]) | |
| output = output.overlay(speech, position=seg["start_ms"]) | |
| final_audio = "final_audio.wav" | |
| output.export(final_audio, format="wav") | |
| return final_audio | |