I am running a Python code to record audio playing on a browser in a Google Compute Engine VM (Ubuntu 18.04).
Here's the basic code I am running:
import sounddevice as sd
samplerate = 44100 # Hertz
duration = 30 # seconds
mydata = sd.rec(0, samplerate=samplerate,channels=2)
When I ssh into it as a user, sounddevice works perfectly, but when I change to root, PortAudio returns this error:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/gowthamsathyan/v/lib/python3.6/site-packages/sounddevice.py", line 280, in rec
ctx.input_dtype, callback, blocking, **kwargs)
File "/home/gowthamsathyan/v/lib/python3.6/site-packages/sounddevice.py", line 2498, in start_stream
**kwargs)
File "/home/gowthamsathyan/v/lib/python3.6/site-packages/sounddevice.py", line 1382, in __init__
**_remove_self(locals()))
File "/home/gowthamsathyan/v/lib/python3.6/site-packages/sounddevice.py", line 778, in __init__
extra_settings, samplerate)
File "/home/gowthamsathyan/v/lib/python3.6/site-packages/sounddevice.py", line 2571, in _get_stream_parameters
info = query_devices(device)
File "/home/gowthamsathyan/v/lib/python3.6/site-packages/sounddevice.py", line 569, in query_devices
raise PortAudioError('Error querying device {0}'.format(device))
sounddevice.PortAudioError: Error querying device -1
Both are happening on the same VM. I even started Pulseaudio as root before running the code.
Please let me know if I did anything wrong and if there's a fix.
Thank you