问题
Today I installed Pyaudio by using instruction on http://people.csail.mit.edu/hubert/pyaudio/ and trying to run some examples like this one.
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()
and when I'm trying to run it
AttributeError: 'module' object has no attribute 'PyAudio'
How can this be?
回答1:
Did you name your example file pyaudio.py
? When I did, I got the same error. In this case just rename your working file.
回答2:
I have never used PyAudio, but I have used SpeechRecogition, and in that, you may have to use PortAudio, based off of operating system. Download homebrew(brew) first.
Debian Linux
$ brew install portaudio
$ pip install pyaudio
MacOS
$ brew install portaudio
$ pip install pyaudio
If a windows user, then I don't know the answer.
回答3:
try typing in terminal
pip install pyaudio
来源:https://stackoverflow.com/questions/27584742/pyaudio-attributeerror-module-object-has-no-attribute-pyaudio