Created
April 19, 2013 12:43
-
-
Save nickrw/5420085 to your computer and use it in GitHub Desktop.
volsay: Wrapper around OSX's `say' command, which sets the system volume to the requested level, then restores volume / mute state once speech is complete.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
function usage() { | |
echo "usage: $0 <volume (0-100)> <say args...>" | |
echo | |
echo "Unmutes and sets the system volume to volume%, passing the remaining" | |
echo "arguments to the OSX \`say' command, restoring volume / mute setting" | |
echo "to previous values after the speech has completed." | |
exit 1 | |
} | |
# Set volume level (echos current volume level before changing) | |
function volume() { | |
osascript -e 'output volume of (get volume settings)' | |
osascript -e "set volume output volume $1" | |
} | |
# Set system mute status (echos current mute state before changing) | |
function mute() { | |
mstate=$(osascript -e 'output muted of (get volume settings)') | |
echo $mstate | |
if [[ $mstate != $1 ]]; then | |
osascript -e "set volume output muted $1" | |
fi | |
} | |
if [[ -z $1 || ! $1 =~ ^[0-9]+$ ]]; then | |
usage | |
exit 1 | |
fi | |
oldmute=$(mute false) | |
oldvol=$(volume $1) | |
shift | |
say $* | |
volume $oldvol > /dev/null | |
mute $oldmute > /dev/null |
fwiw, the man page should include [[volm <%>]] somewhere
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This file came up in a search.. It's worth noting that you can pass volume arguments directly to say:
I realize you are going for a bit more here.