|
from pydub import AudioSegment |
|
from tqdm import tqdm |
|
import os |
|
|
|
def create_translated_audio(result_diarize, audio_files, Output_name_file): |
|
total_duration = result_diarize['segments'][-1]['end'] |
|
|
|
|
|
combined_audio = AudioSegment.silent(duration=int(total_duration * 1000)) |
|
print(round((total_duration / 60),2), 'minutes of video') |
|
|
|
for line, audio_file in tqdm(zip(result_diarize['segments'], audio_files)): |
|
start = float(line['start']) |
|
|
|
|
|
try: |
|
audio = AudioSegment.from_file(audio_file) |
|
|
|
start_time = start * 1000 |
|
combined_audio = combined_audio.overlay(audio, position=start_time) |
|
except: |
|
print(f'ERROR AUDIO FILE {audio_file}') |
|
|
|
os.system("rm -rf audio/*") |
|
|
|
|
|
combined_audio.export(Output_name_file, format="wav") |