if no proxy type is set default to none.
[Rockbox.git] / tools / genvoice.sh
blob15028e3bd174c77402ea065f46d3b457e2aa34cb
1 #!/bin/sh
2 # __________ __ ___.
3 # Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 # Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 # Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 # Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 # \/ \/ \/ \/ \/
8 # $Id$
10 # Copyright 2006 Jonas Häggqvist, some parts Copyright 2004 Daniel Gudlat
12 # All files in this archive are subject to the GNU General Public License.
13 # See the file COPYING in the source tree root for full license agreement.
15 # This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 # KIND, either express or implied.
18 # Include voicecommon.sh from the same dir as this script
19 # Any settings from voicecommon can be overridden if added below the following
20 # line.
21 source `dirname $0`'/voicecommon.sh'
23 ####################
24 # General settings #
25 ####################
27 # These settings can be overridden by passing a file with definitions as
28 # the fourth parameter to this script
30 # which TTS engine to use. Available: festival, flite, espeak
31 TTS_ENGINE=festival
32 # which encoder to use, available: lame, speex, vorbis (only lame will produce
33 # functional voice clips at this point)
34 ENCODER=lame
35 # Where to save temporary files
36 TEMPDIR=/tmp
37 # List of IDs to send to voicefont
38 VOICEFONTIDS=voicefontids
40 ###################
41 # End of settings #
42 ###################
44 TARGET_ID="$4"
45 createvoicefile() {
46 $GENLANG -e=$ENGLISH -o -t=$TARGET $LANG_FILE > $VOICEFONTIDS
47 $VOICEFONT "$VOICEFONTIDS" "$TARGET_ID" "$TEMPDIR/" "./$RLANG.voice"
50 deletefiles() {
51 # XXX: might be unsafe depending on the value of TEMPDIR
52 rm -f "${TEMPDIR}"/LANG_*
53 rm -f "${TEMPDIR}"/VOICE_*
56 generateclips() {
57 ROCKBOX_DIR="$1"
58 RLANG="$2"
59 TARGET="$3"
60 GENLANG="$ROCKBOX_DIR"/tools/genlang
61 ENGLISH="$ROCKBOX_DIR"/apps/lang/english.lang
62 LANG_FILE="$ROCKBOX_DIR"/apps/lang/$RLANG.lang
64 $GENLANG -e=$ENGLISH -o -t=$TARGET $LANG_FILE |(
65 i=0
66 while read line; do
67 case `expr $i % 3` in
69 # String ID no.
70 NUMBER=`echo $line |cut -b 2-`
73 # String ID
74 ID=`echo $line |cut -b 5-`
77 # String
78 STRING=`echo $line |cut -b 8-`
80 if [ -n "$POOL" ]; then
81 # we have a common pool of snippets, check that first
82 # for available mp3 sounds, and if it is available copy
83 # (symlink!) it over
84 if [ -f "$POOL/$STRING.mp3" ]; then
85 echo "Re-using $ID from pool"
86 if [ ! -e "$TEMPDIR/$ID".mp3 ]; then
87 # only do this if not present
88 ln -s "$POOL/$STRING.mp3" "$TEMPDIR/$ID".mp3
93 # only make an mp3 if not already present
94 if [ ! -e "$TEMPDIR/$ID".mp3 ]; then
95 # Now generate the file
96 voice "$STRING" "$TEMPDIR/$ID".wav
97 if [ -n "$POOL" ]; then
98 # create it in the pool, symlink it back
99 encode "$TEMPDIR/$ID".wav "$POOL/$STRING".mp3
100 ln -s "$POOL/$STRING.mp3" "$TEMPDIR/$ID".mp3
101 else
102 encode "$TEMPDIR/$ID".wav "$TEMPDIR/$ID".mp3
106 esac
107 i=`expr $i + 1`
108 done
112 if [ -z "$3" ]; then
113 echo "Usage: $0 rockboxdirectory language target targetid [settingsfile]";
114 exit 32
115 else
116 if [ ! -d "$1" ] || [ ! -f "$1/tools/genlang" ]; then
117 echo "Error: $1 is not a Rockbox directory"
118 exit 33
120 if [ ! -f "$1/apps/lang/$2.lang" ]; then
121 echo "Error: $2 is not a valid language"
122 exit 34
124 if [ ! -z "$5" ]; then
125 if [ -f "$5" ]; then
126 # Read settings from file
127 source "$5"
128 else
129 echo "Error: $5 does not exist"
130 exit 36
133 # XXX: check for valid $TARGET?
136 VOICEFONT=`dirname $0`/voicefont
137 if [ ! -x $VOICEFONT ]; then
138 echo "Error: $VOICEFONT does not exist or is not executable"
139 exit 35
142 init_tts
143 init_encoder
144 generateclips "$1" "$2" "$3"
145 stop_tts
146 createvoicefile
147 #deletefiles