One good solution is to use Gstreamer directly !
It does not need GUI libraries.

Please start audio-recorder and go into the [Additional settings] dialog. Choose the [Recording commands] tab. There you can see the actual Gstreamer commands that do the recording work. There are Gstreamer pipelines for various codex and formats (.mp3, .ogg, flac, etc.) . Use the [Show Cmd] button to see and test the pipelines in a terminal window.

You will need to install gstreamer1.0-tools package.
It contains the gst-launch-1.0 command.

Become also familiar with the pactl command that is explained in the dialog.

Can you help with this problem?

Provide an answer of your own, or ask
Andrey
for more information if necessary.