利用 python 获取一段音频的时长信息

为了统计大量音频的时长信息,比如总时长、平均时长、最大最小时长等,采用人工进行逐个的统计是不现实的,这就需要利用python进行批量处理。

那如何利用python获取一段音频的时长信息呢。具体如下:

wav_path =  ''
with open(wav_path, 'rb') as f:
    time_count = f.getparams().nframes/f.getparams().framerate
print(time_count)

那如何统计大量音频的总时长、数量、平均时长、最大最小时长等信息呢。具体如下:

import os

# 音频存放文件夹路径
filedir = ''
 
time_count = 0
wav_num = 0 
wav_time_max = 0
wav_time_min = 5

list = os.listdir(filedir)
for file in list:
    if '.wav' in file:
        wav_num += 1
        wav_path = os.path.join(filedir, fille)
        with wave.open(wav_path,'rb') as f:
            wav_time = f.getparams().nframes/f.getparams().framerate
            time_count += wav_time
            if wav_time > wav_time_max:
                wav_time_max = wav_time
            if wav_time < wav_time_min:
                wav_time_min = wav_time 
        time_ave = time_count / wav_num
print(time_count/60,wav_num,time_ave,wav_time_max,wav_time_min)

你可能感兴趣的:(语音合成,音视频,语音识别,人工智能)