I created stream
CHUNK=48000
RATE=48000
p = pa.PyAudio()
stream = p.open(
rate=RATE,
channels=CHANNELS,
format=FORMAT,
input=True,
frames_per_buffer=CHUNK
)
And I take data from the buffer if the number of frames has reached 48000
def get_mic_data(s, num_frames):
while True:
if s.get_read_available() > CHUNK:
available = s.get_read_available()
mic_data = np.frombuffer(s.read(num_frames, exception_on_overflow=False), dtype=np.int32)
return mic_data, available
else:
time.sleep(0.1)
But this code doesn't give 48000 frames every second Sometimes 48,000 frames accumulate in 1.4 seconds, sometimes in 0.4 But I need 48000 frames per second