afplay is a command-line audio player built into macOS. You give it a file and it plays it, with no window and no controls. It stops when the file ends or when you kill it.
afplay -h
# -v, --volume VOLUME volume. 1 is normal, 0.5 is quieter
# -t, --time TIME only play the first TIME seconds
# -r, --rate RATE playback speed. 1.5 is 50% faster
# -q, --rQuality 0|1 quality of rate-scaled playback. 0 is low (default), 1 is high
# -d, --debug debug output
# --leaks run leaks analysis# Listen to a podcast or audiobook at 1.5x.
# -q 1 uses the higher-quality time stretching, which is worth it for voices.
afplay -r 1.5 -q 1 episode.mp3# Get a ding when a long command finishes, and a honk when it fails.
npm test && afplay /System/Library/Sounds/Glass.aiff || afplay /System/Library/Sounds/Basso.aiff# A 25-minute pomodoro timer.
sleep 1500 && afplay /System/Library/Sounds/Hero.aiff# Skim a folder of clips by playing the first 3 seconds of each one.
for f in *.mp3; do echo "$f"; afplay -t 3 "$f"; done# Loop a sound until Ctrl-C.
while true; do afplay /System/Library/Sounds/Submarine.aiff; done# Pair it with `say`, the Mac's built-in text-to-speech command.
say "Deploy finished" && afplay /System/Library/Sounds/Ping.aiff# A quiet pop every time you commit.
echo 'afplay -v 0.3 /System/Library/Sounds/Pop.aiff &' >> .git/hooks/post-commit
chmod +x .git/hooks/post-commit# Play something in the background, then stop it later.
afplay article.mp3 &
killall afplay# The built-in sounds you can use for all of the above.
ls /System/Library/Sounds/
# Basso Blow Bottle Frog Funk Glass Hero Morse Ping Pop Purr Sosumi Submarine TinkIt can't pause, seek, or stream from a URL. For that, use ffplay (it comes with ffmpeg) or mpv.