今天在处理音频的时候,需要判断音频是否为空,我分享一下我的python代码:
import librosa
import os
def check_audio_durations(file_name):
"""
check whether the audio file is empty
"""
len_file=os.path.getsize(file_name)
if(len_file==0):
return False
time = librosa.get_duration(filename=file_name)
if(time>0):
return True
return False
需要安装librosa哈,安装方法:
pip install librosa