WAV/W64/RF64文件中出现错误。格式错误';fmt&x27;在python中使用声音文件库时出现块错误

WAV/W64/RF64文件中出现错误。格式错误';fmt&x27;在python中使用声音文件库时出现块错误,python,runtime-error,soundfile,Python,Runtime Error,Soundfile,当我试图读取wav文件的分钟数时出错 import soundfile as sf f = sf.SoundFile('swearing_Service_1.14.20.wav') print('samples = {}'.format(len(f))) print('sample rate = {}'.format(f.samplerate)) print('seconds = {}'.format(len(f) / f.samplerate))

当我试图读取wav文件的分钟数时出错

    import soundfile as sf
    f = sf.SoundFile('swearing_Service_1.14.20.wav')
    print('samples = {}'.format(len(f)))
    print('sample rate = {}'.format(f.samplerate))
    print('seconds = {}'.format(len(f) / f.samplerate))

  File "C:\Users\jj\AppData\Local\Continuum\anaconda3\lib\site-packages\soundfile.py", line 1357, in _error_check
    raise RuntimeError(prefix + _ffi.string(err_str).decode('utf-8', 'replace'))

RuntimeError: Error opening 'swearing_Service_1.14.20.wav': Error in WAV/W64/RF64 file. Malformed 'fmt ' chunk.

我无法调试这个。我只想找到一个wav文件的持续时间(分/秒)

我遇到了相同的错误,我的原因是假定的wav文件不是一个完全的wav文件(我使用ffmpeg将aac文件转换为wav,但参数错误)。当我使用一个真正的wav文件时,错误消失了。

就像@holibut所说的那样,我遇到了这个问题,因为我试图用
-rf64 auto
将一堆.aac文件转换成一个.wav文件


我首先将所有的.aac文件转换为.wav文件,然后将wav文件合并,从而解决了这个问题。

我也遇到了同样的错误。 我建议使用
librosa
而不是
soundfile
。首先确保系统中安装了
ffmpeg
,然后运行以下操作:

>>> import librosa
>>> signal, sr = librosa.load('swearing_Service_1.14.20.wav', sr=None)
要获取
wav
文件的持续时间,可以使用以下命令:

>>> duration = librosa.get_duration(signal, sr)
>>> duration
30388.89
要以
hh:mm:ss
格式获取时间,可以执行以下操作:

>>> import time
>>> time.strftime('%H:%M:%S', time.gmtime(duration))
'08:26:28'