我正在使用提供连续数据的定制信号采集系统。 我在使用pyaudio实时传输处理的数据时遇到问题。 代码如下:
import pyaudio as pya
import numpy as np
import threading
import MyAcq
fs = 50000
NbEch = 5000
CHUNK = 1000
NbCHUNK = NbEch/CHUNK
def processing(Acq, strm):
while MyAcq.AcqActiv:
data = Acq.get_data(NbEch)
Sig = MyAcq.MyProcess(data).astype('float32')
for i in range(NbCHUNK) :
Buffer = Sig[i*CHUNK + np.arange(CHUNK)]
strm.write(Buffer)
if __name__ == '__main__':
Acq = MyAcq.MyAcqSystem()
Acq.start()
pa = pya.PyAudio()
stream = pa.open(format = pya.paFloat32,
channels = 1,
rate = fs,
frames_per_buffer = CHUNK,
input = False,
output = True)
t = threading.Thread(target = processing, args =(Acq, stream))
t.start()
MyAcq.close()
stream.stop_stream()
stream.close()
pa.terminate()
尽管输入数据流是连续的,但信号输出会被斩波和失真。 我没有弄清楚如何使用回调模式。 使用队列共享已处理的信号不再成功。
有任何线索吗?