我目前正在开发一个小项目,涉及Python中的麦克风输入,我正在使用PyAudio库(绑定PortAudio)。当我尝试第一个“ Wire”示例(阻塞)时,一切都可以正常工作,但是一旦我尝试运行第二个示例“ Wire(回调)”,Python就会说:
Traceback (most recent call last):
File "main.py", line 24, in <module>
stream_callback=callback)
TypeError: __init__() got an unexpected keyword argument 'stream_callback'
虽然在绑定中正确定义了它。任何帮助吗?
完整的代码是:
import pyaudio
import time
WIDTH = 2
CHANNELS = 2
RATE = 44100
p = pyaudio.PyAudio()
def callback(in_data, frame_count, time_info, status):
return (in_data, pyaudio.paContinue)
stream = p.open(format=p.get_format_from_width(WIDTH),
channels=CHANNELS,
rate=RATE,
input=True,
output=True,
stream_callback=callback)
stream.start_stream()
while stream.is_active():
time.sleep(0.1)
stream.stop_stream()
stream.close()
p.terminate()
谢谢!
更新PyAudio和PortAudio解决了该问题。
在PyAudio的Mac OSX安装上,有效arg中看起来不像stream_callback:(