|
import os |
|
import csv |
|
import tqdm |
|
import ffmpeg |
|
import hashlib |
|
|
|
|
|
|
|
|
|
|
|
transcriptions_file = "./files/TEDx_Spanish.transcription" |
|
audio_dir = "./speech" |
|
output_dir = "./cuts" |
|
|
|
lines = open(transcriptions_file).readlines() |
|
|
|
transcriptions = [ [line.split("TEDX_")[0], "TEDX_"+line.split("TEDX_")[1].replace("\n", "")] for line in lines] |
|
transcriptions = {k:v for v,k in transcriptions} |
|
|
|
output = [] |
|
|
|
|
|
for filename in tqdm.tqdm(list(os.scandir(audio_dir))): |
|
|
|
if filename.name.endswith(".wav"): |
|
|
|
if filename.name.replace(".wav", "") in transcriptions: |
|
|
|
digest = hashlib.sha256(open(filename.path, 'rb').read()).hexdigest() |
|
ffmpeg.input(filename.path).output(f"{output_dir}/{digest}.opus").overwrite_output().run(quiet=True) |
|
output.append([f"{digest}.opus", ffmpeg.probe(filename.path)['streams'][0]['duration'] , transcriptions[filename.name.replace(".wav", "")]]) |
|
|
|
|
|
with open('output.csv', 'w', newline='') as csvfile: |
|
|
|
csv_writer = csv.writer(csvfile,delimiter='\t') |
|
csv_writer.writerows(output) |
|
|