10

What are some CLI tools that I can use to output a constant sound from all my speakers?

I'm trying to test my speakers (headphones) to make sure they're functional. It seems that if the wire is kinked in just the wrong way, it stops playing. But I'm not sure. It's really annoying to test this with a random media file because the I'm never sure if the silence is caused by the file having audio output gaps or the speaker failing.

I just need a simple command that will output a constant stream of sound. Bonus points if I can choose the channel.

What command line utilities can I use in Ubuntu to output a constant sound from the speakers for testing audio?

2
  • an acceptable answer would be a tool to generate a track of pink noise and another tool to play it on loop. Commented Aug 28, 2023 at 15:26
  • You can use audacity to create a 1 hour constant sine wave or noise.
    – qwr
    Commented Aug 29, 2023 at 0:53

2 Answers 2

10

The package alsa-utils includes a command called speaker-test.

Install

You can install with

sudo apt install alsa-utils

Run

You can now run this to produce a constant sound

speaker-test -t sine -p 1

Note You'll want to add -p 1 else you'll be blasted with a very loud & very annoying sound that you cannot stop with ctrl+c. We also change the test from the default "pink noise" to "sine" as it's not such a jarring sound.

5
  • 4
    speaker-test oh my god why does ctrl+c not exit this Commented Aug 28, 2023 at 15:37
  • 1
    @MichaelAltfield LOL Ctrl+c will exit it when it's like this speaker-test -t sine -f 100 -c 2 -p 1 for example.
    – Raffa
    Commented Aug 28, 2023 at 15:39
  • good lord thank you. Looks like it's the -p that's needed. I can't really hear anything on my speakers with -f 100, but this worked great for me speaker-test -t sine -p 1 Commented Aug 28, 2023 at 15:43
  • @MichaelAltfield speaker-test -t sine -f 450 1> /dev/null & sleep 0.3 && kill -9 "$!". 😘 Commented Nov 1, 2023 at 14:32
  • Is it possible to choose the channel with speaker-test? So one command to just play the "left" speaker and then another command to just play the "right" speaker? Commented Apr 8 at 20:00
2

SoX (The Sound eXchange) can do this.

Install:

sudo apt install sox

At its simplest, to just play a continuous 440Hz sine tone, you can do

play -n synth sine 440

play expects an input file, -n is just used to indicate that there is none.

The synth command is quite flexible and can generate wide variety of sounds, including different wave shapes, noise colours, chords and sweeps.

For example, to play a 10 second sine sweep from 20Hz to 20kHz and repeat it five times:

play -n synth 10 sine 20-20000 repeat 5
1
  • Is it possible to choose the channel with play? So one command to just play the "left" speaker and then another command to just play the "right" speaker? Commented Apr 8 at 20:00

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .