Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
A quick Bash loop to play all available voices for OS X say command
#!/bin/bash
# Arguments can include a quoted string to define the test string to be repeated
# If an argument is numbers only, it changes the rate at which to speak (words per minute, default 200)
play_all_voices() {
local voice
local rate=200
local test_string="How are you?"
for arg in $@; do
if [[ $arg =~ ^[0-9]+$ ]]; then
rate=$arg
else
test_string=$arg
fi
done
echo "Rate: $rate"
echo "String: $test_string"
read -a voices <<< $(say -v \?|sed -E 's/^([[:alpha:]]+( [[:alpha:]]+)?).*$/\1/g'|sed -E 's/ /_/g')
# declare -a voices=(Agnes Albert Alex Alice Alva Amelie Anna Bad_News Bahh Bells Boing Bruce Bubbles Carmit Cellos Damayanti Daniel Deranged Diego Ellen Fiona Fred Good_News Hysterical Ioana Joana Junior Kanya Karen Kathy Kyoko Laura Lekha Luciana Mariska Mei-Jia Melina Milena Moira Monica Nora Paulina Pipe_Organ Princess Ralph Samantha Sara Satu Sin-ji Tarik Tessa Thomas Ting-Ting Trinoids Veena Vicki Victoria Whisper Xander Yelda Yuna Zarvox Zosia Zuzana)
for v in ${voices[@]}; do
voice=$(echo "$v"|tr '_' ' ')
echo "Playing \"$voice\"..."
say -v "Daniel" -r 200 "$voice"
say -r $rate -v "$voice" "$test_string"
done
}
play_all_voices $@
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.