pyAudio 在调用 start_stream 之前开始流式传输
pyAudio starts streaming before start_stream is called
我想在回调模式下使用 pyAudio 并使用 stream = pyaudio.PyAudio().open(...)
准备一个流。我希望在使用 stream.start_stream()
启动流后调用我的 callback
方法。但是,我的回调函数在创建流对象后立即被调用(参见演示代码)。
我是不是用错了 pyAudio 或者这是一个错误?
import time
import pyaudio
def callback(in_data, frame_count, time_info, status):
print("CALLBACK")
return (in_data, pyaudio.paContinue)
p = pyaudio.PyAudio()
stream = p.open(format=p.get_format_from_width(2), channels=1, rate=44100,
input=True, output=False, stream_callback=callback,
frames_per_buffer=5000)
# XXX: Note that I do not call stream.start_stream() here
time.sleep(5)
stream.close()
我正在使用 python 3.6.5 和 pyaudio 0.2.11 以及 portaudio 19.6.0
pyaudio.Stream
的初始化程序(open
初始化)默认启动流。如果你不希望它以 PyAudio.open
开头,你可以传递 start=False
.
摘自the documentation(强调我的):
__init__(PA_manager, rate, channels, ... , start=True, ...)
Parameters:
...
start
– Start the stream running immediately. Defaults to True
. In general, there is no reason to set this to False.
我想在回调模式下使用 pyAudio 并使用 stream = pyaudio.PyAudio().open(...)
准备一个流。我希望在使用 stream.start_stream()
启动流后调用我的 callback
方法。但是,我的回调函数在创建流对象后立即被调用(参见演示代码)。
我是不是用错了 pyAudio 或者这是一个错误?
import time
import pyaudio
def callback(in_data, frame_count, time_info, status):
print("CALLBACK")
return (in_data, pyaudio.paContinue)
p = pyaudio.PyAudio()
stream = p.open(format=p.get_format_from_width(2), channels=1, rate=44100,
input=True, output=False, stream_callback=callback,
frames_per_buffer=5000)
# XXX: Note that I do not call stream.start_stream() here
time.sleep(5)
stream.close()
我正在使用 python 3.6.5 和 pyaudio 0.2.11 以及 portaudio 19.6.0
pyaudio.Stream
的初始化程序(open
初始化)默认启动流。如果你不希望它以 PyAudio.open
开头,你可以传递 start=False
.
摘自the documentation(强调我的):
__init__(PA_manager, rate, channels, ... , start=True, ...)
Parameters:
...
start
– Start the stream running immediately. Defaults toTrue
. In general, there is no reason to set this to False.