Luke Oliff.

TIL: What afinfo Reveals About Your Audio Files

·TIL·3 min read·Luke Oliff

Every audio file carries its specs in the header. Sample rate, channels, bit depth, codec. Before you send anything to a speech-to-text API, one command tells you if the audio and the endpoint agree.

afinfo speech.wav

Output:

File:           speech.wav
File type ID:   WAVE
Num Tracks:     1
----
Data format:     1 ch,  48000 Hz, lpcm (0x0000000E)
                 24-bit big-endian signed integer
estimated duration: 93.250 sec
audio bytes: 13419000

48 kHz, 24-bit, stereo. The STT endpoint expected 16 kHz, 16-bit, mono. There was your problem.

afinfo is built into macOS. It reads the file headers and dumps every property the system knows about. Sample rate, channel count, bit depth, codec, duration, byte count. Everything you need to check before you send audio to a speech-to-text API.

What afinfo reveals about your audio files

The first thing is the data format line. You want:

  • 1 ch (mono) for most STT endpoints. Two channels means the API either mixes them down or processes one and discards the other.
  • 16000 Hz or whatever sample rate your provider expects. A mismatch here produces garbage transcripts with no error message.
  • 16-bit signed integer. The most common format for speech-to-text pipelines. 24-bit works but wastes bandwidth.

The second is the duration and byte count. If the estimated duration is way off or the byte count looks small, the file might be truncated or have trailing metadata that inflates the header size.

# Quick check: is it even the right format?
afinfo speech.wav | grep "Data format"

# Brief mode for scripting
afinfo -b speech.wav

The -b (brief) flag prints everything on one line. Good for scripts or when you want the answer in under a second.

afinfo -b speech.wav
# /path/to/speech.wav: WAVE, 1 ch, 16000 Hz, lpcm (0x0000000E) 16-bit big-endian signed integer

Why afinfo matters for STT debugging

Most STT issues are not model problems. They are format mismatches that the API does not tell you about. The audio plays fine in a media player. QuickTime shows a waveform. But the sample rate is wrong, or the bit depth is unexpected, or the file is stereo when the pipeline assumes mono. The API returns a transcript that reads like a fax machine falling down stairs, with no error and no hint about why.

afinfo catches all of these in one command. No SDK needed. No API call wasted.

Can I use afinfo on compressed audio like MP3 or AAC?

Yes. afinfo reads any format QuickTime handles. For MP3 files it prints the codec info and bitrate instead of raw PCM properties. The output looks different but the key fields (sample rate, channels, duration) are the same.

Is there a way to fix audio format issues from the terminal?

Use afconvert for that. It converts between audio formats using macOS Core Audio. afconvert speech.wav -o speech-16kHz.wav -f WAVE -d LEI16@16000 is the pattern for creating a 16-bit, 16 kHz mono WAV file.

Does afinfo work on Linux?

No, it’s macOS-only. On Linux use ffprobe (from ffmpeg) or mediainfo for the same functionality. The output format differs but the fields are the same.