How to record audio with ffmpeg on ubuntu with python?

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

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 command on Ubuntu, It recorded audio successfully.

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

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

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

or if using orther ouput:

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

Details can see more attached photos:
enter image description here
Record error:
enter image description here

Read more here: Source link