我想每 4096 个样本对音频进行一次简单的实时处理。但是此代码每 1024 个样本调用一次回调函数。我只想将 frame_count 更改为 4096。
import pyaudio
import time
WIDTH = 2
CHANNELS = 1
RATE = 44100
p = pyaudio.PyAudio()
def callback(in_data, frame_count, time_info, status):
out=do_something(in_data)
print(frame_count)#1024
return (out, 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()