我使用Python来操作WAV文件。此代码用于:
from pydub import AudioSegment
fp = "/Volumes/.../generic.wav"
sound = AudioSegment.from_wav(fp)现在我得到了一个错误:
Traceback (most recent call last):
File "/usr/local/lib/python3.7/site-packages/pydub/audio_segment.py", line 670, in from_file
return cls._from_safe_wav(file)
File "/usr/local/lib/python3.7/site-packages/pydub/audio_segment.py", line 818, in _from_safe_wav
file.seek(0)
AttributeError: 'NoneType' object has no attribute 'seek'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "cassandra.py", line 992, in md2episode
sound = AudioSegment.from_wav(fp)
File "/usr/local/lib/python3.7/site-packages/pydub/audio_segment.py", line 808, in from_wav
return cls.from_file(file, 'wav', parameters=parameters)
File "/usr/local/lib/python3.7/site-packages/pydub/audio_segment.py", line 678, in from_file
file.seek(0)
AttributeError: 'NoneType' object has no attribute 'seek'该文件播放它的22秒,使用ffprobe检查它似乎还可以:
$ ffprobe "/Volumes/.../generic.wav"
ffprobe version 4.3.1 Copyright (c) 2007-2020 the FFmpeg developers
built with Apple clang version 11.0.0 (clang-1100.0.33.17)
configuration: --prefix=/usr/local/Cellar/ffmpeg/4.3.1_1 --enable-shared --enable-pthreads --enable-version3 --enable-avresample --cc=clang --host-cflags= --host-ldflags= --enable-ffplay --enable-gnutls --enable-gpl --enable-libaom --enable-libbluray --enable-libdav1d --enable-libmp3lame --enable-libopus --enable-librav1e --enable-librubberband --enable-libsnappy --enable-libsrt --enable-libtesseract --enable-libtheora --enable-libvidstab --enable-libvorbis --enable-libvpx --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libxvid --enable-lzma --enable-libfontconfig --enable-libfreetype --enable-frei0r --enable-libass --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-librtmp --enable-libspeex --enable-libsoxr --enable-videotoolbox --disable-libjack --disable-indev=jack
libavutil 56. 51.100 / 56. 51.100
libavcodec 58. 91.100 / 58. 91.100
libavformat 58. 45.100 / 58. 45.100
libavdevice 58. 10.100 / 58. 10.100
libavfilter 7. 85.100 / 7. 85.100
libavresample 4. 0. 0 / 4. 0. 0
libswscale 5. 7.100 / 5. 7.100
libswresample 3. 7.100 / 3. 7.100
libpostproc 55. 7.100 / 55. 7.100
Input #0, wav, from '/Volumes/.../generic.wav':
Duration: 00:00:22.16, bitrate: 384 kb/s
Stream #0:0: Audio: pcm_s16le ([1][0][0][0] / 0x0001), 24000 Hz, 1 channels, s16, 384 kb/s我已经检查过pydub是最新的:
$ python3 -m pip install --upgrade pydub
Requirement already up-to-date: pydub in /usr/local/lib/python3.7/site-packages (0.25.1)我的Python版本是:
$ python3 --version
Python 3.7.9如何使用PyDub加载WAV文件?或者我在哪里能找到一个等价的替代品呢?
发布于 2022-03-20 17:28:57
今天我不能再重复这个问题了。输入文件是Google语音合成的结果,所以这可能是一个错误。今天再次运行代码解决了问题。
https://stackoverflow.com/questions/71452554
复制相似问题