166

I have a USB microphone that I can chat on Skype, record sound etc. But how can I make it so that when my mic is on and I speak, Ι hear it in speakers live without having to record my voice first and then play it back? What apps do I need or where can I enable this option?

I'm running Ubuntu 10.10

  • 2
    One thing to consider is that depending on your soundcard you might get latency (a slight delay between your speaking and the sound coming through your headphones). This is very disconcerting and is due to the processing and converting from Analog to Digital then back to Analog. I have heard that in Ubuntu you might need to install Jack audio libraries to reduce latency. http://superuser.com/questions/87571/how-to-hear-mic-sound-over-speakers-ubuntu-karmic – Colin Matheson Apr 20 '12 at 18:29
  • 1
    ok, but how do I get the sound coming out in first place? – Martin Zeltin Apr 20 '12 at 18:30
  • You don't need jack. I use the lowlatency kernel from Ubuntustudio that is also available through apt-get with no issues. – mchid Feb 04 '16 at 07:14
  • 14
    Try this command: arecord | aplay – user619271 Jul 02 '16 at 15:28
  • You don't even need to do a single thing. You can just search for "online mic check". There are sites letting you hear your own voice. – Eray Erdin May 21 '21 at 08:10
  • Do you know about any open source alternative. This one from Mozilla MDN works just visually – Pablo Bianchi Jul 06 '21 at 07:26

11 Answers11

228

Here is a solution that I've tested with Pulse Audio on Ubuntu 12.04.

  • Install PulseAudio Volume Control (pavucontrol):

    sudo apt install pavucontrol
    
  • Now we will route your microphone to your speakers. Do this by running the following command:

    pactl load-module module-loopback latency_msec=1
    
  • On the Recording tab of pavucontrol, you can show all streams (combobox at the bottom) and then configure which microphone (if you have more than one) should loopback into the built-in analog stereo

To stop it running, run:

pactl unload-module module-loopback
Eliah Kagan
  • 117,780
Charl Botha
  • 2,826
  • 10
    The solution works fine, but how can I undo this setting? – Ionică Bizău Dec 19 '13 at 11:31
  • 5
    To undo it see this answer. – Gramic Feb 08 '14 at 09:43
  • 3
    When I do this sound comes out of the speakers, but it is only static, and no voice if I speak into the mic. Any ideas? I'm on 14.04 – andrewmh20 Jun 10 '14 at 17:07
  • 2
    delay ruins playback.. try to sing with it :\ – neu-rah Apr 04 '16 at 15:22
  • 1
    You can also logout and login to undo this. – Smile4ever Aug 01 '16 at 09:36
  • 2
    Or, instead of logging out: pactl unload-module module-loopback – Hedede Nov 22 '16 at 18:32
  • 3
    It still gives a slightly noticeable lag, which is annoying when playing instruments. Any way to avoid it? – Daniel Vartanov Nov 06 '17 at 20:50
  • 1
    This solution does not work on Ubuntu Budgie 18.04 (kernel 4.20.17) on Dell Inspiron 7720 – Marecky May 11 '19 at 22:58
  • 3
    @DanielVartanov: To reduce latency significantly, use a realtime-enabled kernel and configure pulseaudio to run with realtime priority and a lower nice value (I have nice-level = -19, realtime-scheduling = yes and realtime-priority = 97, as well as rlimit-nice = 39 and rlimit-rtprio = 98, in /etc/default/pulse.pa). For that to work you'll also need to configure limits (in /etc/systemd/system.conf.d/limits.conf). I have DefaultLimitNICE=-19 and DefaultLimitRTPRIO=98 for the realtime group (of which I'm a user). It works great. – Marc.2377 Dec 12 '19 at 00:33
  • Oh, it also makes sense to load module-loopback with latency_msec=20 so as to not result in too many dropped sources and auto-increasing the latency (it can be monitored with journalctl --user-unit pulseaudio -n 1000 -f). – Marc.2377 Dec 12 '19 at 00:34
  • here's a convenient script I wrote to wrap these. https://github.com/aalok-sathe/dotfiles/blob/master/loopback – axolotl Oct 04 '20 at 23:07
  • 1
    It gives loud noise – Jobayer Shajal Nov 04 '20 at 06:43
  • I have made a simple script to use this solution, just copy the code into a file (openmic.sh) script: `#!/bin/bash echo -e "\nusage: openmic.sh on / openmic.sh off \n"

    switch=$1

    if [ $switch = on ] then pactl load-module module-loopback latency_msec=1 fi

    if [ $switch = off ] then pactl unload-module module-loopback fifinally make the script executable:chmod +x openmic.sh` Just in case, in the script every big gap (space) is a new line.

    – Andrés Chandía Jan 29 '21 at 13:12
79

Simple solution

Just use:

arecord -f cd - | aplay -

If you wanna play while saving:

arecord -f cd - | tee output.wav | aplay -
  • 1
    Definitely, the most simple way to echo microphone into headphones. I miss a GUI interface. –  Apr 10 '17 at 15:39
  • 9
    With this solution the playback has an awful latency, unfortunately – Daniel Vartanov Nov 06 '17 at 20:50
  • 20
    This will help with the latency: arecord --buffer-time=1 - | aplay --buffer-time=1 - – Brent Bradburn Nov 09 '18 at 04:46
  • 2
    Great way to record media! You can listen to it too so it's less painfully slow! Question though, how would I handle this if I have multiple mics connected (how can I select one over the other)? – Mark Deven Feb 19 '19 at 18:30
  • 3
    a buffer time of 1ms will result in underruns. I recommend at least 20ms - make it 40ms if not using a realtime kernel. – Marc.2377 Dec 12 '19 at 00:28
  • 3
    1ms resulted in lower format, this worked for me to force specific format and sampling rate: arecord -r 192000 -f s16_le --buffer-time=1 - | aplay --buffer-time=1 - – chaz Mar 26 '20 at 19:22
  • 1
    Thanks a lot, this is really a good and simple solution :-) – Fred Feb 12 '22 at 17:58
  • Thank You for the answer and others for the comments (especially @BrentBradburn and @Marc.2377 ). I can confirm it also works with electric guitar. ;) If one would like to record it using tee still works: arecord --buffer-time=20 - | tee output.wav | aplay --buffer-time=20 -. Praise to the One! – kcpr Nov 03 '23 at 14:14
35
  1. First install PulseAudio Volume Control/pavucontrol.

Either install via Software Manager.

Or run this below command in terminal:

    sudo apt-get install pavucontrol
  1. To start Mic to Speaker working, run below command in terminal.

     pactl load-module module-loopback latency_msec=1
    
  2. To stop the same, run below command in terminal.

     pactl unload-module module-loopback
    
alter_igel
  • 103
  • 4
PraveenKolar
  • 11
  • 2
  • 3
  • 2
    This solution does not work on Ubuntu Budgie 18.04 (kernel 4.20.17) on Dell Inspiron 7720 – Marecky May 11 '19 at 22:59
  • 1
    This (module-loopback) doesn't seem to work with a Focusrite Scarlett 4i4. For some reason it randomly disconnects after a second or two. module-loopback works with the built-in mic though. And the Scarlett is not broken, I can record fine in Audacity :/. – gatoatigrado May 21 '20 at 06:29
  • In addition link to documentation https://www.freedesktop.org/wiki/Software/PulseAudio/Documentation/User/Modules/#module-loopback – JOHN_16 Jul 08 '21 at 21:42
  • Woof. That was weird. It feels like it's coming in very delayed. Can I apply a negative number to latency ; ) – Costa Michailidis Mar 23 '22 at 23:23
28

I've packaged up other people's answers into 'listen', a Bash script. Run this to listen to your mic input. It sleeps forever. Kill it (e.g. Ctrl-C) to stop listening.

#!/usr/bin/env bash

Directs audio input (e.g. mic) to audio output (e.g. speakers),

then sleeps forever. Stops audio redirection when it is killed.

So, for example, plug your phone into the PC's mic, run 'listen',

and listen to phone audio through your computer's speakers.

Requires:

sudo apt-get install pactl

set -e

module=$(pactl load-module module-loopback latency_msec=10)

function cleanup { pactl unload-module $module }

trap cleanup EXIT

sleep infinity

Pablo Bianchi
  • 15,657
24

You can do it with jackd and qjackctl.

The program jackd is an audio sound server daemon for Linux, and its counterpart qjackctl is a simple user interface that lets you handle JACK audio server. From this you can virtually connect the output of your mic to your speakers.

You can install them from you terminal with:

sudo apt-get install jackd qjackctl

After installing it and running qjackctl, the connections mentioned will look like the following screenshot:

qjackctl app in action

Note, I am a professional audio editor and use it each week recordings sessions.

  • 6
    what do I do if there's nothing under connections there.... I don't have that system - capture - playback thing.... there's nothing there.... – Martin Zeltin Apr 21 '12 at 04:13
  • 1
    I think it's not working because i have a usb mic... – Martin Zeltin Apr 21 '12 at 04:30
  • Strange... when you started qjackctl, dit it started without complaining? – Rubens Mariuzzo Apr 21 '12 at 19:29
  • 3
    @MartinZeltin: For me it was because the jack server wasn't started. Click the 'Messages' button and look for that error in the log. To fix this I opened 'Setup' and then went to the 'Misc' tab and ticked 'Start JACK audio server on application startup'. I then closed qjackctl and reopened it. After that I could see exactly what was in the picture above – Baggers May 30 '15 at 16:04
  • qjackctl does not work on Ubuntu 22.04 Desktop: fails with can't connect to server: 09:27:15.279 Statistics reset. 09:27:15.282 ALSA connection change. 09:27:15.291 JACK is starting... 09:27:15.292 /usr/bin/jackd -dalsa -dhw:0 Cannot connect to server socket err = No such file or directory Cannot connect to server request channel jack server is not running or cannot be started – John Rose Nov 03 '23 at 09:30
9

Just an update for 2018 if you use gnome. There's a gnome extension that you can use to achieve just that. Here is the link in case anyone wants to try it out https://extensions.gnome.org/extension/954/pulseaudio-loopback-device/

  • Could you elaborate a little bit how to install that and how it should work? I think I have installed the extension properly (using Firefox Gnome Shell extension plugin), but nothing happened and I have no idea how to enable/configure it. – bluenote10 Jan 12 '19 at 12:21
  • Once you install it, it should make a tray icon appear. Clicking that icon should enable the mic loop. If the tray icon isn't displaying you probably need to install something like TopIcon Plus and that will probably make it appear. I'm sorry I can't be more specific but had to switch to windows and it's been a while since I used linux as a main system. – Lucas D'Abate Jan 31 '19 at 18:02
  • Extension is incompatible with Ubuntu 22.04 Desktop and/or shell 42 – John Rose Nov 03 '23 at 09:31
4

You can use audacity to amplify your voice by "playback while recording" feature. go to edit>preferences>recording> check software playthrough.

nick
  • 51
2

Mixxx is awesome! I'm using it on Ubuntu (Budgie) 18.04. Quick setup, just turn it on, set up your hardware (I only had to set up the input device) and turn on the mic. You're up and running in no time with no latency, plus the ability to do tons more if you want. I dowloaded it from the software store.

Bus42
  • 364
1

You can also use ffplay (part of ffmpeg) e.g. to listen to ALSA device hw:1 and disabling ffplay's display feature (-nodisp) so no X11 is needed:

ffplay -nodisp  -f alsa -i hw:1

Note: You can list possible ALSA [input] sources using ffplay:

ffplay --sources alsa
Pierz
  • 3,063
  • 1
  • 25
  • 15
0

simple script:

 Simple convenience wrapper to record then play back a temporary sound file.
# Usage: arecord-mic duration
[[ $1 == *[![:digit:]]* ]] || return
typeset tmpFile
tmpFile=$(mktemp --suffix .wav) || return

typeset -a arecordOpts=( -c 1 # number of channels -D plughw:0,0 # device name -d "$1" # duration -f S32_LE # format -r 48000 # sample rate -V mono # VU meter type )

arecord "${arecordOpts[@]}" -- "$tmpFile" && aplay -- "$tmpFile" rm -f -- "$tmpFile"

usage: ./arecord-mic <duration>

e.g ./arecord-mic 10 will record about 10 seconds and then plays it back.

source https://wiki.gentoo.org/wiki/ALSA

0

You can also use OBS Studio. After you add an input source like a microphone, click on the gear icon next to it and select Advanced Audio Properties, on this menu select "Monitor and Output" for the "Audio Monitoring" option.

I use this to pass audio from my Nintendo Switch over usb capture card to my PC headphones and I did not notice any delay.

I believe it uses PulseAudio, but it's a more friendly user interface imo.