Skip to content

Instantly share code, notes, and snippets.

@ericbolo
Last active February 28, 2023 12:08
Show Gist options
  • Save ericbolo/1261438048147b97316ff65f1ee105c6 to your computer and use it in GitHub Desktop.
Save ericbolo/1261438048147b97316ff65f1ee105c6 to your computer and use it in GitHub Desktop.
Routing mic to audio output for monitoring (ALSA + PulseAudio)

Credits

https://mikebeach.org/2011/07/26/how-to-monitor-your-microphone-through-headphones-in-ubuntu/

Introduction

This walks you through routing the microphone's audio to your headphones. I've tested it on a Raspberry PI (Raspbian Jessie).

Steps

start PulseAudio daemon

pulseaudio -D

Get name of source and sink devices

pactl list sources short

Then copy the appropriate source device to your clipboard. In my case: alsa_input.usb-0d8c_C-Media_USB_Headphone_Set-00-Set.analog-mono

pactl list sinks short

In my case: alsa_output.usb-0d8c_C-Media_USB_Headphone_Set-00-Set.analog-stereo

Route the signal

Edit the names of input and output to the appropriate source and sink and run the command:

pacat -r --latency-msec=1 -d alsa_input.usb-0d8c_C-Media_USB_Headphone_Set-00-Set.analog-mono | pacat -p --latency-msec=1 -d alsa_output.usb-0d8c_C-Media_USB_Headphone_Set-00-Set.analog-stereo

Whatever you say or record through your mic jack will now be output to your headphones. Enjoy!

@RobertoHernandezjr
Copy link

I am trying to use this to route my mic always to my output for karaoke, and it works but theirs a lot of static and noticeable delay. Any alternatives to fix this? I have been trying to use JACK but its a bit over my head.

@ericbolo
Copy link
Author

ericbolo commented Jan 7, 2021 via email

@RobertoHernandezjr
Copy link

NP, thank you for the quick response !

@FascinatedBox
Copy link

It's been a while since the last comment, but I just now stumbled on this while trying to figure something out. Going to post what I've done in case that helps.

I was originally using a pipeline like above to get audio from my capture card routed to my headphones. I was able to tune different options to get rid of the static, but was occasionally having lag issues.

I'm now using a gstreamer pipeline that looks like this:

    gst-launch-1.0 \
        pulsesrc \
            device=alsa_input.blah_blah_blah \
        ! \
        pulsesink \
            device=alsa_output.blah_blah_blah

@bhuvankrishna
Copy link

@ericbolo Thanks for the oneliner it worked out really well without any setup or tweaking. I used it to play electric guitar plugged in as input and used headphones to hear what I am playing on my electric guitar. Thanks a ton again. I tried it on archlinux with pipewire.

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