1

I've installed and imported all the required libraries (at least I think so):

!sudo apt-get install libportaudio2
!pip install sounddevice
import numpy as np
import matplotlib.pyplot as plt
import sounddevice as sd

And I am getting the following error when running this code:

wav_wave = np.array(tone, dtype=np.int16)
sd.play(wav_wave, blocking=True)
sd.stop()

The error below is caused by the sd.play function.

PortAudioError: Error querying device -1
Diana
  • 363
  • 2
  • 8

2 Answers2

2

You are using a virtual machine from Google collab, you can´t play an audio there. Instead, you can always display an audio object in the front-end and play it from there. Like this:

from IPython.display import Audio
from IPython.display import display

wn = Audio("saxriff.wav", autoplay=True)
display(wn)

Please note that this solution only works for notebooks, like colab. It will display something like this:

output

0

Cloud servers might not have microphone. That is the reason why you are getting this error.