Skip to content

Instantly share code, notes, and snippets.

@willeccles
Last active August 13, 2016 17:09
Show Gist options
  • Save willeccles/18363bda30d016c01533d639b3898ad4 to your computer and use it in GitHub Desktop.
Save willeccles/18363bda30d016c01533d639b3898ad4 to your computer and use it in GitHub Desktop.
Bash file to speak a file out loud on OS X, with options for volume, voice, and interactive reading.
#! /bin/bash
if (( $# == 1 )) && [ "$1" == "?" ]
then
say -v ?
echo ""
echo "Voices should be specified in quotes if 2+ words."
exit 0
fi
if (( $# == 4 )) && [ "$4" == "-i" ]
then
osascript -e "set Volume $2"
cat "$1" | say -v "$3" -i
elif (( $# == 3 ))
then
osascript -e "set Volume $2"
cat "$1" | say -v "$3"
elif (( $# == 2 ))
then
osascript -e "set Volume $2"
cat "$1" | say
elif (( $# == 1 ))
then
cat "$1" | say
else
echo "Usage: speakfile [? | [filename] [volume 1-10] [voice] [-i]]"
echo " For a list of voices: speakfile ?"
fi
@willeccles
Copy link
Author

willeccles commented Jul 13, 2016

For a good time, download Moby Dick and copy it to moby.txt and run this: ./speakfile moby.txt 2.5 Daniel. Enjoy! 😄

Another fun thing is to put the files all in a user's folder on another computer in the office, then you ssh into their computer as them and then run that script. It will make the computer randomly start talking, and hilarity will surely ensue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment