-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsayit.sh
More file actions
66 lines (53 loc) · 1.42 KB
/
sayit.sh
File metadata and controls
66 lines (53 loc) · 1.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/bin/bash
# sayit--Uses the "say" command to read whatever's specified (OS X only)
dosay="$(which say) --quality=127"
format="$(which fmt) -w 70"
voice="" # Default systems
rate="" # Default to the standard speaking rate
demovoices()
{
# Offer up a sample of each available voice.
voicelist=$( say -v \? | grep "en_" | cut -c1-12 \
| sed 's/ /_/;s/ //g;s/_$//')
if [ "$1" = "list" ] ; then
echo "Available voices: $(echo $voicelist | sed 's/ /, /g;s/_/ /g') \
| $format"
echo "HANDY TIP: use \"$(basename $0) demo\" to hear all the voices"
exit 0
fi
for name in $voicelist ; do
myname=$(echo $name | sed 's/_/ /')
echo "Voice: $myname"
$dosay -v "$myname" "Hello I'm $myname. This is what I sound like."
done
exit 0
}
usage()
{
echo "Usage: sayit [-v voice] [-r rate] [-f file] phrase"
echo " or: sayit demo"
exit 0
}
while getopts "df:r:v:" opt; do
case $opt in
d ) demovoices list ;;
f ) input="$OPTARG" ;;
r ) rate="-r $OPTARG" ;;
v ) voice="$OPTARG" ;;
esac
done
shift $(($OPTIND - 1))
if [ $# -eq 0 -a -z "$input" ] ; then
$dosay "Hey! You haven't given me any parameters to work with."
echo "Error: no parameters specified. Specify a file or phrase."
exit 0
fi
if [ "$1" = "demo" ] ; then
demovoices
fi
if [ ! -z "$input" ] ; then
$dosay $rate -v "$voice" -f $input
else
$dosay $rate -v "$voice" "$*"
fi
exit 0