python統計wav文件的時長

 

import wave
import os.path

# 音頻存放文件夾絕對路徑
filedir = '/Users/111/PycharmProjects/TextClassify/wav'

list = os.listdir(filedir)

time_count = 0

for file in list:
    if '.wav' in file:
        wav_path = filedir+'/'+file
        with wave.open(wav_path,'rb') as f:
            f = wave.open(wav_path)
            time_count += f.getparams().nframes/f.getparams().framerate

print(time_count/60/60)
相關文章
相關標籤/搜索