How to handle in_data in Pyaudio callback mode?

后端 未结 2 1257
[愿得一人]
[愿得一人] 2020-12-18 04:50

I\'m doing a project on Signal Processing in python. So far I\'ve had a little succes with the nonblocking mode, but it gave a considerable amount of delay and clipping to t

2条回答
  •  再見小時候
    2020-12-18 05:25

    Found the answer to my question in the meantime, the callback looks like this:

    def callback(in_data, frame_count, time_info, flag):
        global b,a,fulldata #global variables for filter coefficients and array
        audio_data = np.fromstring(in_data, dtype=np.float32)
        #do whatever with data, in my case I want to hear my data filtered in realtime
        audio_data = signal.filtfilt(b,a,audio_data,padlen=200).astype(np.float32).tostring()
        fulldata = np.append(fulldata,audio_data) #saves filtered data in an array
        return (audio_data, pyaudio.paContinue)
    

提交回复
热议问题