Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
How to record multiple applications and microphone into one audio file on Linux using PulseAudio

How to record multiple applications and microphone into one audio file on Linux

Step 0. Terminology

Sinks are for output, sources are for input. To stream source to sink a loopback must be created. More shall you find there.

Step 1. Create output sink that will be recorded

Our output sink will be named recording.

pacmd load-module module-null-sink sink_name=recording sink_properties=device.description=recording

Step 2. Create output sink that will forward data to recording and the default sink -- your headphones (using speakers is not a good idea because they will be recorded by microphone for the second time)

First we have to locate our output sink:

pacmd list-sinks | egrep '^\s+name: .*'

For me it prints:

	name: <alsa_output.pci-0000_00_1f.3.analog-stereo>
	name: <bluez_sink.4C_87_5D_07_5B_C4.a2dp_sink>

So I choose bluez_sink.4C_87_5D_07_5B_C4.a2dp_sink as my output sink because its my headphones (the other represents my speakers). Now we can combine it with our new recording sink into combined sink:

pacmd load-module module-combine-sink sink_name=combined sink_properties=device.description=combined slaves=recording,bluez_sink.4C_87_5D_07_5B_C4.a2dp_sink

Step 3. Attach microphone to recording sink

Protip: If you ommit this step you may record multiple apps without microphone.

First we have to locate our microphone as a source:

pacmd list-sources | egrep '^\s+name: .*' | grep input

For me it produced:

	name: <alsa_input.pci-0000_00_1f.3.analog-stereo>

So alsa_input.pci-0000_00_1f.3.analog-stereo represents my microphone. Now we attach it to redording sink:

pacmd load-module module-loopback source=alsa_input.pci-0000_00_1f.3.analog-stereo sink=recording latency_msec=1

Step 4. Channel applications through the combined sink to record them (this step can be done after step 5. -- you can change what apps you record without stopping recording)

Open pavucontrol, go to Playback tab and change sink to combined. Hint: the application won't appear there unless it is producing sound.

image

Step 5. Record audio

With the above setup, you can start and stop recording at any time. To record recording sink, use:

parecord --channels=2 -d recording.monitor output.wav

It will save recording to output.wav file. To stop recording press Crtl-C (kill the parecord with SIGINT). Protip: You can change recorded applications while recording by controlling which ones output to combined sink as was shown in step 4.

@bcelary

This comment has been minimized.

Copy link

@bcelary bcelary commented Oct 16, 2020

Dzięki! Przydało się.

@MrJake222

This comment has been minimized.

Copy link

@MrJake222 MrJake222 commented Nov 5, 2020

OMG Big thanks.

Dzięki!

@sektionschef

This comment has been minimized.

Copy link

@sektionschef sektionschef commented Jan 28, 2021

thanks a lot! best tutorial i found

@HarleyLorenzo

This comment has been minimized.

Copy link

@HarleyLorenzo HarleyLorenzo commented Mar 4, 2021

Awesome thanks! I modified this to my purposes quite easily, great tutorial!

@jmakovecki

This comment has been minimized.

Copy link

@jmakovecki jmakovecki commented Apr 5, 2021

Used this tutorial to forward sound from specific applications to a conference call running in browser. Worked like a charm, many thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment