Luke Oliff.

TIL: Generating WAV Files at a Specific Sample Rate With SoX

·TIL·1 min read·Luke Oliff

APIs expect audio at specific sample rates. SoX generates test files that match exactly.

sox -n test.wav rate 16000 channels 1 synth sine 440

Creates a 440Hz sine wave WAV at 16kHz mono. No microphone needed.

sox -n test.wav rate 8000 channels 1 synth noise

White noise at 8kHz mono. Useful for testing silence detection and voice activity detection.

sox -n test.wav rate 48000 channels 2 synth sawtooth 220 duration 5

A 5 second sawtooth wave at 48kHz stereo. Covers higher sample rate APIs.

What sample rate do most speech APIs use?

16000 Hz (16kHz) mono is the standard for speech recognition. Some support 8000 Hz for telephony quality.

Can I convert existing files?

sox input.mp3 -r 16000 -c 1 output.wav