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

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章