Fix serious bug in FAT filename check, preventing most files from being created ...
[kugel-rb.git] / tools / genvoice.sh
blobf32ab9476a9f4cf184edde63c78e42b45e379b2b
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
38 ###################
39 # End of settings #
40 ###################
42 createvoicefile() {
43 $VOICEFONT "$LANG_FILE" "$TEMPDIR/" "./$RLANG.voice"
46 deletefiles() {
47 # XXX: might be unsafe depending on the value of TEMPDIR
48 rm -f "${TEMPDIR}"/LANG_*
49 rm -f "${TEMPDIR}"/VOICE_*
52 generateclips() {
53 ROCKBOX_DIR="$1"
54 RLANG="$2"
55 TARGET="$3"
56 GENLANG="$ROCKBOX_DIR"/tools/genlang
57 ENGLISH="$ROCKBOX_DIR"/apps/lang/english.lang
58 LANG_FILE="$ROCKBOX_DIR"/apps/lang/$RLANG.lang
60 $GENLANG -e=$ENGLISH -o -t=$TARGET $LANG_FILE |(
61 i=0
62 while read line; do
63 case `expr $i % 3` in
65 # String ID no.
66 NUMBER=`echo $line |cut -b 2-`
69 # String ID
70 ID=`echo $line |cut -b 5-`
73 # String
74 STRING=`echo $line |cut -b 8-`
76 if [ -n "$POOL" ]; then
77 # we have a common pool of snippets, check that first
78 # for available mp3 sounds, and if it is available copy
79 # (symlink!) it over
80 if [ -f "$POOL/$STRING.mp3" ]; then
81 echo "Re-using $ID from pool"
82 if [ ! -e "$TEMPDIR/$ID".mp3 ]; then
83 # only do this if not present
84 ln -s "$POOL/$STRING.mp3" "$TEMPDIR/$ID".mp3
89 # only make an mp3 if not already present
90 if [ ! -e "$TEMPDIR/$ID".mp3 ]; then
91 # Now generate the file
92 voice "$STRING" "$TEMPDIR/$ID".wav
93 if [ -n "$POOL" ]; then
94 # create it in the pool, symlink it back
95 encode "$TEMPDIR/$ID".wav "$POOL/$STRING".mp3
96 ln -s "$POOL/$STRING.mp3" "$TEMPDIR/$ID".mp3
97 else
98 encode "$TEMPDIR/$ID".wav "$TEMPDIR/$ID".mp3
102 esac
103 i=`expr $i + 1`
104 done
108 if [ -z "$3" ]; then
109 echo "Usage: $0 rockboxdirectory language target [settingsfile]";
110 exit 32
111 else
112 if [ ! -d "$1" ] || [ ! -f "$1/tools/genlang" ]; then
113 echo "Error: $1 is not a Rockbox directory"
114 exit 33
116 if [ ! -f "$1/apps/lang/$2.lang" ]; then
117 echo "Error: $2 is not a valid language"
118 exit 34
120 if [ ! -z "$4" ]; then
121 if [ -f "$4" ]; then
122 # Read settings from file
123 source "$4"
124 else
125 echo "Error: $4 does not exist"
126 exit 36
129 # XXX: check for valid $TARGET?
132 VOICEFONT=`dirname $0`/voicefont
133 if [ ! -x $VOICEFONT ]; then
134 echo "Error: $VOICEFONT does not exist or is not executable"
135 exit 35
138 init_tts
139 init_encoder
140 generateclips "$1" "$2" "$3"
141 stop_tts
142 createvoicefile
143 #deletefiles