Using the Command 'speaker-test' (with examples)
- Linux
- December 17, 2024
The ‘speaker-test’ command is a utility that comes with ALSA (Advanced Linux Sound Architecture), providing a simple means to test speakers on a Linux system. It is particularly useful when configuring audio devices or diagnosing sound-related issues. The tool generates audio signals that can be used to verify the functionality and setup of speaker hardware. It supports different types of test sounds, such as pink noise, sine waves, and WAV files. This article illustrates several practical examples of how to use the ‘speaker-test’ command to test your speakers.
Use case 1: Test the default speakers with pink noise
Code:
speaker-test
Motivation:
The default use of ‘speaker-test’ is to generate pink noise—a sound signal that is often used for testing audio systems. Pink noise has equal energy per octave, making it advantageous for assessing the consistent performance of audio systems across all frequencies. This type of test can be very useful for ensuring speakers are not distorting sound or missing specific frequencies.
Explanation:
speaker-test
: This is the basic command term, which, when run without additional parameters, defaults to generating pink noise for speaker testing. Pink noise is preferred for preliminary checks of audio setups because it provides a comprehensive frequency range, allowing users to evaluate the quality and performance of their speaker output.
Example output:
Playback device is default
Stream parameters are 48000Hz, S16_LE, 2 channels
Using 16 octaves of pink noise
Rate set to 48000Hz (requested 48000Hz)
Buffer size range from 2048 to 16384
Period size range from 1024 to 1024
Using max buffer size 16384
Periods = 4
was set period_size = 1024
was set buffer_size = 16384
0 - Front Left
1 - Front Right
Time per period = 2.726754
Use case 2: Test the default speakers with a sine wave
Code:
speaker-test -t sine -f 440
Motivation:
Using a sine wave to test speakers may be desirable for more precise calibration, as it emits a pure tone at a specified frequency. A sine wave is beneficial when checking for harmonic distortions or specific issues at certain frequencies. This focused testing can help isolate auditory issues that might not be apparent when using broader spectrum noises like pink noise.
Explanation:
-t|--test sine
: This option specifies that the test tone should be a sine wave instead of the default pink noise.-f|--frequency frequency
: Allows the user to set the frequency of the sine wave in Hertz. In this example, the frequency is set to 440Hz, which corresponds to the musical note A, commonly used as a tuning standard (the A above middle C).
Example output:
Playback device is default
Stream parameters are 48000Hz, S16_LE, 1 channels
Sine wave with frequency 440Hz
Rate set to 48000Hz (requested 48000Hz)
Buffer size range from 2048 to 16384
Period size range from 1024 to 1024
Using max buffer size 16384
Periods = 4
was set period_size = 1024
was set buffer_size = 16384
0 - Front Left
Time per period = 2.726754
Use case 3: Test the default speakers with a predefined WAV file
Code:
speaker-test -t wav
Motivation:
Testing with a predefined WAV file lets users assess speaker performance using actual audio content stored within the speaker-test utility. This can be particularly helpful for quick checks without needing to obtain additional audio files. It demonstrates how speakers handle real sound waves compared to synthesized test tones.
Explanation:
-t|--test wav
: This argument tells ‘speaker-test’ to use a predefined WAV file for the test. It converts the typical test environment into a scenario more like real-world audio playback, allowing for a practical evaluation of audio playback quality.
Example output:
Playing WAVE '/usr/share/sounds/alsa/Front_Left.wav' : Signed 16 bit Little Endian, Rate 48000 Hz, Mono
Sample rate set to 48000Hz (requested 48000Hz)
Front Left Channel
Playing WAVE '/usr/share/sounds/alsa/Front_Right.wav' : Signed 16 bit Little Endian, Rate 48000 Hz, Mono
Front Right Channel
Use case 4: Test the default speakers with a WAV file
Code:
speaker-test -t wav -w path/to/file
Motivation:
This use case is crucial for instances when a user needs to test speakers with specific audio content beyond what is predefined. By using a custom WAV file, it’s possible to simulate diverse audio scenarios and verify audio output under specific formats or complex soundscapes as required by unique testing environments or personal preferences.
Explanation:
-t|--test wav
: This argument sets the test type to play a WAV file, unlike default synthesized sounds.-w|--wavfile path/to/file
: Specifies the path to a user-selected WAV file. This flexibility supports testing across various audio content types defined by the user’s specific requirements.
Example output:
Playing WAVE 'path/to/customfile.wav' : Unsigned 16 bit Little Endian, Rate 44100 Hz, Stereo
Stream parameters are 44100Hz, S16_LE, 2 channels
Sample rate set to 44100Hz (requested 44100Hz)
0 - Front Left
1 - Front Right
Time per period = 4.532875
Conclusion:
The ‘speaker-test’ command is a versatile tool for testing speaker configurations and diagnosing audio issues on Linux systems. By offering various test modes—pink noise, sine waves, predefined WAV files, and custom WAV files—it allows users to thoroughly evaluate speaker performance across different scenarios. Whether for routine checks or deeper diagnostic assessments, ‘speaker-test’ provides the flexibility and functionality necessary for effective audio testing.