How do I capture audio from the system bus in a node app (or from sox) on a raspberry pi?

12 Views Asked by At

I have loaded a loopback module using pulseaudio:

pactl load-module module-loopback

and I can see in pavucontrol that the loopback is capturing the sound I want it to.

I have the following code in a node app that calls sox to capture an audio stream from alsa:

const soxCommand = 'sox'
const args = ['-t', 'alsa', 'default', '-t', 'mp3', '-C', '128', 'output.mp3']
const audioRecorder = spawn(soxCommand, args)

The code runs for the duration I would expect when playing sound, but the output file is empty and contains no actual sound data.

My goal is to capture all sound from a source programmatically. In my case, I have a hifiberry dac + adc pro hooked up, and I can record sound in audacity, but not through the node app.

0

There are 0 best solutions below