Skip to content

Instantly share code, notes, and snippets.

@varqox
Last active March 7, 2024 17:59
  • Star 29 You must be signed in to star a gist
  • Fork 8 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save varqox/c1a5d93d4d685ded539598676f550be8 to your computer and use it in GitHub Desktop.
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
Copy link

bcelary commented Oct 16, 2020

Dzięki! Przydało się.

@MrJake222
Copy link

OMG Big thanks.

Dzięki!

@sektionschef
Copy link

thanks a lot! best tutorial i found

@HarleyLorenzo
Copy link

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

@jmakovecki
Copy link

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

@astrojuanlu
Copy link

It worked first time, thanks a lot!

@larvanitis
Copy link

Thanks!

@mbahmodin
Copy link

discord can not see the recording.monitor device so added this command

pacmd load-module module-remap-source master=recording.monitor source_name=recording_remap

it creates a source device recording_remap so discord can see it

@mrkeuz
Copy link

mrkeuz commented May 20, 2022

Thanks! 🚀

@mishashevelinn
Copy link

mishashevelinn commented Sep 6, 2023

Worked right away, thanks a lot! I'd like to automate step 4. Can you provide the command to implement it?
Also, I'd like to figure out programmatic way to set all the sinks to their defaults and remove virtual devices. Any help will be much appreciated.

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