Files
David Ibia 66d1d21011 feat(omo): play omo's own synthesised notification sounds
omo-notify and omo-remote played Apple's Glass and Ping through afplay, which exist only on macOS and are not ours to ship. They now play omo-done (task finished), omo-input (needs your input) and omo-error (stopped with an error), rendered by sfx from .config/omo/sounds/recipes.toml at the same loudness as Glass. The new omo-sound plays a sound by name or any audio file, with afplay on macOS and pw-play, paplay, aplay or ffplay on Linux, and finds the sounds through the dotfiles checkout it is linked from.
2026-10-18 13:12:34 +01:00

34 lines
1.1 KiB
Bash
Executable File

#!/usr/bin/env bash
# Play one of omo's notification sounds (omo-done, omo-input, omo-error) or any
# audio file with whatever player this machine has: afplay on macOS, else
# PipeWire, PulseAudio, ALSA or ffplay on Linux. It blocks until playback ends,
# so hooks that must not wait run it in the background.
#
# The sounds are rendered by sfx from .config/omo/sounds/recipes.toml in the
# dotfiles checkout this script is linked from.
#
# Usage: omo-sound NAME|FILE
sound=${1:?usage: omo-sound NAME|FILE}
if [[ ! -f $sound ]]; then
sound="$(dirname "$(readlink -f "${BASH_SOURCE[0]}")")/../../.config/omo/sounds/$sound.wav"
fi
if [[ ! -f $sound ]]; then
echo "omo-sound: no such sound or file: $1" >&2
exit 1
fi
if command -v afplay >/dev/null; then
exec afplay "$sound"
elif command -v pw-play >/dev/null; then
exec pw-play "$sound"
elif command -v paplay >/dev/null; then
exec paplay "$sound"
elif command -v aplay >/dev/null; then
exec aplay -q "$sound"
elif command -v ffplay >/dev/null; then
exec ffplay -nodisp -autoexit -loglevel quiet "$sound"
fi
echo "omo-sound: no audio player found (afplay, pw-play, paplay, aplay or ffplay)" >&2
exit 1