def get_audio_duration(file_path):
    with contextlib.closing(wave.open(file_path, 'r')) as f:
        frames = f.getnframes()
        rate = f.getframerate()
        wav_length = frames / float(rate)
        print("音频长度:", wav_length, "秒")
        return wav_length

或者使用:

def get_audio_duration(file_path):
    from scipy.io import wavfile
    Fs, x = wavfile.read(file_path)
    print('音频长度: ', len(x) / Fs)
    return len(x) / Fs