Closed fengwang closed 3 days ago
The error comes from the sounddevice
library and is likely due to your audio hardware or ALSA driver setup not supporting a 24000 sample rate. The simplest workaround is to remove output.play(), as this function only plays the audio if you don’t want to save the audio to a file. You can still use output.save("output.wav") and try to play the saved file. Alternatively, you could resample the audio to a supported sample rate, likely 44100. You may also want to check for related issues in the sounddevice
library here: sounddevice GitHub issues.
If you'd like to try resampling and know your supported sample rate, here’s an example:
import torchaudio
new_sr = 44100 # Set your supported sample rate here
resampler = torchaudio.transforms.Resample(orig_freq=output.sr, new_freq=new_sr).to(output.audio.device)
resampled_audio = resampler(output.audio)
output.sr = new_sr
output.audio = resampled_audio
# Now you can play the resampled audio
output.play()
Many thanks for the kind support. The problem solved after removing the play function.
Hi, I tried the code below:
And received unexpected error message like this:
sounddevice.PortAudioError: Error opening OutputStream: Invalid sample rate [PaErrorCode -9997]
The whole output from the console is