feat(preprocess): add error context for wave error

This commit is contained in:
magic-akari 2023-07-27 16:01:39 +08:00
parent a5dac31f43
commit a936231e9a
No known key found for this signature in database
GPG Key ID: EC005B1159285BDD
1 changed files with 11 additions and 8 deletions

View File

@ -13,14 +13,17 @@ import diffusion.logger.utils as du
pattern = re.compile(r'^[\.a-zA-Z0-9_\/]+$')
def get_wav_duration(file_path):
with wave.open(file_path, 'rb') as wav_file:
# 获取音频帧数
n_frames = wav_file.getnframes()
# 获取采样率
framerate = wav_file.getframerate()
# 计算时长(秒)
duration = n_frames / float(framerate)
return duration
try:
with wave.open(file_path, 'rb') as wav_file:
# 获取音频帧数
n_frames = wav_file.getnframes()
# 获取采样率
framerate = wav_file.getframerate()
# 计算时长(秒)
return n_frames / float(framerate)
except Exception as e:
logger.error(f"Reading {file_path}")
raise e
if __name__ == "__main__":
parser = argparse.ArgumentParser()