How to record both input and output audio simultaneously?

By creating a virtual sound card and looping back both the real sound card's input and output into it, it's possible to record both, without hearing yourself speak.

The following is adapted from this solution to a more complex problem.

First create a sink to be used as a virtual sound card, and add two loopbacks into it, which will be used to route the real sound card's input and output.

pacmd load-module module-null-sink sink_name=Virtual1 sink_properties=device.description=Virtual-Sound-Card
pactl load-module module-loopback sink=Virtual1
pactl load-module module-loopback sink=Virtual1

Next, open pavucontrol, navigate to the "Recording" tab and set the real sound card's input and output as the sources for each loopback, which in the OP's case would be "Built-in Audio Analog Stereo" and "Monitor of Built-in Audio Analog Stereo".

Example of Recording tab configuration

Finally, navigate pavucontrol's "Input Devices" tab and set the monitor of the virtual sound card as the fallback device (by clicking the button with a check mark in a green circle to the right of "Monitor of Virtual-Sound-Card").

Example of virtual sound card set as fallback

If you're using the ALSA plug-in, as depicted in the OP's screenshot, set "ALSA Capture from" to "Monitor of Virtual-Sound-Card" in the "Recording" tab.

Now, audacity should pick up the virtual sound card's input, which contains both the real sound card's input and output, while your speakers/headphones will still be reproducing the real sound card's output only, so you won't be hearing your microphone.


You can try to enable "the stereo mixer" using pactl to load module-loopback

The idea is to mix the source stream from your microphone to the speakers. With a correct set for volume and reciprocal position of microphone and speakers you should be able to avoid the Larson effect. :-)

Load the module-loopback

 pactl load-module module-loopback

and after change the recording device (Alsa capture from) from the built-in to the monitor one.
[You find in Volume control->Recording->Alsa plug in / Alsa capture from].

There's a short video for Ubuntu system on youtube

Notes:

module-loopback
allows one to route audio from a source directly back to a sink.