gpt4 book ai didi

python - 音频 : AttributeError: 'module' object has no attribute 'PyAudio'

转载 作者:太空宇宙 更新时间:2023-11-04 05:56:18 24 4
gpt4 key购买 nike

今天我按照 http://people.csail.mit.edu/hubert/pyaudio/ 上的说明安装了 Pyaudio并尝试运行一些这样的示例。

import pyaudio
import wave

CHUNK = 1024
FORMAT = pyaudio.paInt16
CHANNELS = 2
RATE = 44100
RECORD_SECONDS = 5
WAVE_OUTPUT_FILENAME = "output.wav"

p = pyaudio.PyAudio()

stream = p.open(format=FORMAT,
channels=CHANNELS,
rate=RATE,
input=True,
frames_per_buffer=CHUNK)

print("* recording")

frames = []

for i in range(0, int(RATE / CHUNK * RECORD_SECONDS)):
data = stream.read(CHUNK)
frames.append(data)

print("* done recording")

stream.stop_stream()
stream.close()
p.terminate()

wf = wave.open(WAVE_OUTPUT_FILENAME, 'wb')
wf.setnchannels(CHANNELS)
wf.setsampwidth(p.get_sample_size(FORMAT))
wf.setframerate(RATE)
wf.writeframes(b''.join(frames))
wf.close()

当我尝试运行它时

AttributeError: 'module' object has no attribute 'PyAudio'

这怎么可能?

最佳答案

您是否将示例文件命名为 pyaudio.py?当我这样做时,我得到了同样的错误。在这种情况下,只需重命名您的工作文件即可。

关于python - 音频 : AttributeError: 'module' object has no attribute 'PyAudio' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27584742/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com