Programster's Blog

Tutorials focusing on Linux, programming, and open-source

Linux CLI Audio Cheatsheet

Related Posts

Manage Volume

Increase Volume

amixer -D pulse sset Master 2%+

Decrease Volume

amixer -D pulse sset Master 2%-

Set Specific Volume

Set volume to a specific amount:

amixer -D pulse sset Master 50%

Manage Microphone

Listen To Microphone

If you want to hear what your microphone sounds like, then do the following:

arecord -f cd - | aplay -

Record To File

arecord -f cd -t wav recording.wav

Listen To Microphone And Record

If you wish to record the microphone whilst listening to it, do the following:

arecord -f cd - | tee output.wav | aplay -

List Microphones

arecord -l

List Audio Sources

pactl list sources

Create Virtual Microphone

SOURCE_NAME="virtmic"
FILE_PATH="$HOME/virtmic"

pactl load-module module-pipe-source \
  source_name=$SOURCE_NAME \
  file=$FILE_PATH \
  format=s16le \
  rate=16000 \
  channels=1

If you need to find a source name, be sure to list audio sources.

Set Default Microphone

pactl set-default-source $SOURCE_NAME

Play Sound Down Virtual Microphone

SOUND_FILEPATH="/path/to/example.mp3"
VIRTUAL_MIC_FILEPATH="$HOME/virtualmic"

ffmpeg -re \
  -i $SOUND_FILEPATH \
  -f s16le \
  -ar 16000 \
  -ac 1 - \
  > $VIRTUAL_MIC_FILEPATH

References

Last updated: 28th January 2024
First published: 21st February 2022

This blog is created by Stuart Page

I'm a freelance web developer and technology consultant based in Surrey, UK, with over 10 years experience in web development, DevOps, Linux Administration, and IT solutions.

Need support with your infrastructure or web services?

Get in touch