Skip to content

Instantly share code, notes, and snippets.

@MateusBMP
Created June 20, 2024 17:07
Show Gist options
  • Select an option

  • Save MateusBMP/e41362c38a500067dfea935d3e3234b3 to your computer and use it in GitHub Desktop.

Select an option

Save MateusBMP/e41362c38a500067dfea935d3e3234b3 to your computer and use it in GitHub Desktop.
Play a sound using the speaker
#!/bin/bash
#
# Play a sound using the speaker
#
# Usage: ./play_sound.sh [time]
# time: time in seconds to play the sound (default: 0.1)
if ! command -v speaker-test &> /dev/null
then
echo "speaker-test could not be found"
exit 1
fi
if [ $# -gt 1 ]
then
echo "Usage: $0 [time]"
echo " time: time in seconds to play the sound (default: 0.1)"
exit 1
fi
TIME=.1
if [ $# -eq 1 ]
then
TIME=$1
fi
speaker-test -t sine -f 1000 -l 1 > /dev/null 2>&1 & sleep "$TIME" && kill -9 $!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment