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