我目前正在开发一个涉及 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()
谢谢 !