You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm trying to get the current audio level of the wav file thats playing using a callback function. When ran it results in, sounddevice.PortAudioError: Can't write to a callback stream [PaErrorCode -9976]
The audio plays correctly when the callback parameter is removed.
Here's the code...
importsoundfileassfimportsounddeviceassdimportnumpyasnppath_to_audio="add audio path here"defprint_audio_level(outdata, frames, time, status):
# Calculate the audio level as the RMS of the audio dataaudio_level=20*np.log10(np.sqrt(np.mean(np.square(outdata))))
# Print the current audio levelprint("Current audio level:", audio_level, "dB")
# Read the audio file using soundfileaudio, sample_rate=sf.read(path_to_audio)
audio=audio.astype(np.float32)
# Set up the audio playback streamplayback_stream=sd.OutputStream(samplerate=sample_rate, channels=1, callback=print_audio_level)
# Start the audio playback streamplayback_stream.start()
# Play the audio fileplayback_stream.write(audio)
# Stop the audio stream (wait for playback to finish)playback_stream.stop()
# Close the audio streamplayback_stream.close()
The text was updated successfully, but these errors were encountered:
Davis8483
changed the title
sounddevice.PortAudioError: Can't write to a callback stream [PaErrorCode -9976]
Can't write to a callback stream [PaErrorCode -9976]
Jun 20, 2023
I'm trying to get the current audio level of the wav file thats playing using a callback function. When ran it results in,
sounddevice.PortAudioError: Can't write to a callback stream [PaErrorCode -9976]
The audio plays correctly when the callback parameter is removed.
Here's the code...
The text was updated successfully, but these errors were encountered: