为什么scipy.io.wavfile.read不返回元组?

5 投票
1 回答
3215 浏览
提问于 2025-04-15 18:00

我正在尝试使用scipy读取一个*.wav文件。我这样做:

import scipy
x = scipy.io.wavfile.read('/usr/share/sounds/purple/receive.wav')

运行这段代码后,我得到了:

Traceback (most recent call last):
  File "test3.py", line 2, in <module>
    x = scipy.io.wavfile.read('/usr/share/sounds/purple/receive.wav')
AttributeError: 'module' object has no attribute 'io'

有没有人知道这里出了什么问题?提前谢谢大家。

1 个回答

8

根据错误提示,scipy模块里没有'io'这个东西。

io.wavfile是一个子模块,你需要先用from scipy.io import wavfile来导入它,然后再用wavfile.read("/usr/share/sounds/purple/receive.wav")来读取文件。

不过,这样做在你用的示例文件上会出现错误……

撰写回答