I am unable to record audio using sounddevice
in python. This code worked before on an older version of Mac OS.
The python3 code is as follows:
import sounddevice as sd
import numpy as np
fs = 48000
duration=5
rec = sd.rec(int(duration * fs), samplerate=fs, channels=1, blocking=True)
print(rec)
The output is
array([[0.],
[0.],
[0.],
...,
[0.],
[0.],
[0.]], dtype=float32)
Although not all values are shown here, I have confirmed that they are all zero. When the sound records correctly, most of the these values are non-zero.
I have confirmed that the devices are set correctly:
sd.default.device # Output is [2, 3]
python3 -m sounddevice
0 DisplayPort, Core Audio (0 in, 2 out)
1 DisplayPort, Core Audio (0 in, 2 out)
> 2 MacBook Pro Microphone, Core Audio (1 in, 0 out)
< 3 MacBook Pro Speakers, Core Audio (0 in, 2 out)
Is this something to do with permissions in Mac OS? I'm using Mojave.
Thank you.