Play Audio Files from Terminal with afplay
macOS ships a built-in Core Audio player that plays MP3, M4A, WAV and more — with variable rate and timed playback.
Run `afplay ~/Music/track.mp3` to play an audio file through the default output; add -v 2 to double the playback rate.
01Command
Command
$ afplay -v 2 ~/Music/track.mp302What it does
afplay uses Core Audio, so it plays every format macOS itself supports without extra software. The -v flag takes a playback rate between 0.5 and 32 (e.g. -v 0.5 for half speed), and -t limits playback to a number of seconds. Because it blocks until the file finishes, it's a natural fit for script sound cues — pair it with & for background audio.
03Risk
!Warning: afplay blocks until playback ends, so a long file will hang your script unless you background it with &.
04Undo
✓No undo needed — this command does not change persistent state.
05Sources
- afplay — audio file play command (macOS)Evidence: Documents afplay options: -v rate (playback rate 0.5–32), -q quality, and -t time in seconds, played via the default output device.
- afplay(1) — play audio filesEvidence: Man page documents the -v playback-rate option along with -t/-q flags for time and quality.
Last verified: 2026-09-17 · Category: Media