sound – How to record audio with ffmpeg with Python on Ubuntu?

I encountered the problem of recording output audio on Ubuntu with Python. I want to record the output sound from the browser. I used USB Headphone as the output device, then record sounded with ffmpeg.

pactl list short sources output:

0. alsa_output.usb-0c76_USB_PnP_Audio_Device-00.analog-stereo.monitor  module-alsa-card.c      s16le 2ch 48000Hz       SUSPENDED
1. alsa_input.usb-0c76_USB_PnP_Audio_Device-00.mono-fallback  module-alsa-card.c      s16le 1ch 48000Hz       SUSPENDED 
2. alsa_output.pci-0000_00_1f.3.iec958-stereo.monitor     module-alsa-card.c      s16le 2ch 44100Hz       SUSPENDED

When I run the following command on Ubuntu, it records audio successfully:

ffmpeg -f pulse -i alsa_output.usb-0c76_USB_PnP_Audio_Device-00.analog-stereo.monitor -t 10 output.wav

successful command in the terminal

However, when I executed the command in the Python project, this error is reported:

alsa_output.usb-0c76_USB_PnP_Audio_Device-00.analog-stereo.monitor: Operation not permitted

or if using another output:

alsa_output.pci-0000_00_1f.3.iec958-stereo.monitor: Operation not permitted

error when running in Python project

Read more here: Source link