python 判断音频的是否为空

今天在处理音频的时候,需要判断音频是否为空,我分享一下我的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

猜你喜欢

转载自blog.csdn.net/w5688414/article/details/106193829
今日推荐