python-sounddevice icon indicating copy to clipboard operation
python-sounddevice copied to clipboard

Does SoundDevice keeps recording while executing callback?

Open yichengye310 opened this issue 3 years ago • 1 comments

Hi,

I am currently using SoundDevice to record with a callback. I am trying to do real-time detection to the sound recording. My question is, does SoundDevice keeps recording while executing callback? Because the callback maybe takes some time if the blocksize is large. Thank you.

def callback(indata, frames, time, status):
    outdata = np.reshape(indata, (len(indata),))
    predict_x = extract_feature_soundclip(outdata)
    with graph.as_default():
        predictions = model_a2.predict(predict_x)
    if len(predictions) == 0:
        print("Model A Test No Prediction!")
        return
    predictions_mean_a = np.mean(predictions, axis=0)
    print(predictions_mean_a)

stream = sd.InputStream(channels=1, callback=callback, dtype='float32', blocksize=256000)
stream.start()

yichengye310 avatar Apr 03 '21 00:04 yichengye310

Did you read the last 2 paragraphs in the documentation of the callback argument at https://python-sounddevice.readthedocs.io/en/0.4.1/api/streams.html#sounddevice.Stream?

You should always check the status argument, which will tell you if an over-/underflow happened.

mgeier avatar Apr 05 '21 17:04 mgeier