Added check if audio file exists in getDatasetSpeechRate

This commit is contained in:
Thorsten Mueller 2021-12-19 18:44:01 +01:00
parent 29238f2a31
commit b536dfd958

View File

@ -6,11 +6,12 @@
# Changelog:
# v0.1 - 26.09.2021 - Initial version
from genericpath import exists
import os
import librosa
import csv
dataset_dir = "/Users/thorsten/Downloads/thorsten-export-20210909/" # Directory where metadata.csv is in
dataset_dir = "/home/thorsten/___dev/tts/dataset/Thorsten-neutral-Dec2021-44k/" # Directory where metadata.csv is in
out_csv_file = os.path.join(dataset_dir,"speech_rate_report.csv")
decimal_use_comma = True # False: Splitting decimal value with a dot (.); True: Comma (,)
@ -23,6 +24,7 @@ with open(os.path.join(dataset_dir,"metadata.csv")) as csvfile:
for row in reader:
wav_file = os.path.join(dataset_dir,"wavs",row[0] + ".wav")
if exists(wav_file):
# Gather values for report.csv output
phrase_len = len(row[1]) - 1 # Do not count punctuation marks.
duration = round(librosa.get_duration(filename=wav_file),2)
@ -33,5 +35,7 @@ with open(os.path.join(dataset_dir,"metadata.csv")) as csvfile:
char_per_sec = str(char_per_sec).replace(".",",")
out_csv.write(row[0] + ".wav;" + str(duration) + ";" + str(phrase_len) + ";" + str(char_per_sec) + ";no\n")
else:
print("File " + wav_file + " does not exist.")
out_csv.close()