3 # Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 # Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 # Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 # Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 # Copyright (c) 2006 Jonas Häggqvist
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 # A selection of functions common to creating voicefiles for Rockbox.
20 # You may wish to change some of the settings below.
26 # Leave any you're not using untouched, enter full path if the program is
29 # the festival main executable
31 # the festival_client binary
32 FESTIVAL_CLIENT
=festival_client
34 # The flite executable
37 # The eSpeak executable
43 # The speexenc executable
46 # The oggenc executable
49 # The wavtrim executable
50 WAVTRIM
=`dirname $0`/wavtrim
56 # If you're not using festival, leave untouched
58 # whether to start the Festival server locally (Y/N)
60 # the host of the Festival server
61 # this is set to localhost automatically when FESTIVAL_START is Y
62 FESTIVAL_HOST
=localhost
63 # the port of the Festival server
65 # where to log the Festival client output
66 FESTIVAL_LOG
=/dev
/null
67 # other options to the festival client
74 # If you're not using flite, leave untouched
81 # If you're not using eSpeak, leave untouched
88 # The maximum sample value that will be treated as silence by the wavtrim tool.
89 # The value is expressed as an absolute 16 bit integer sample value (0 dB equals
92 # 500 is a good guess - at least for Festival
99 # where to log the encoder output
102 # Suggested: --vbr-new -t --nores -S
103 # VBR, independent frames, silent mode
104 LAME_OPTS
="--vbr-new -t --nores -S"
107 # XXX: suggest a default
110 # Suggested: -q0 --downmix
112 VORBIS_OPTS
="-q0 --downmix"
118 # Check if executables exist and perform any necessary initialisation
122 # Check for festival_client
123 if [ ! `which $FESTIVAL_CLIENT` ]; then
124 echo "Error: $FESTIVAL_CLIENT not found"
128 # Check for, and start festival server if specified
129 if [ X
$FESTIVAL_START = XY
]; then
130 if [ ! `which $FESTIVAL_BIN` ]; then
131 echo "Error: $FESTIVAL_BIN not found"
134 FESTIVAL_HOST
='localhost'
135 $FESTIVAL_BIN --server 2>&1 > /dev
/null
&
136 FESTIVAL_SERVER_PID
=$
!
138 if [ `ps | grep -c "^\ *$FESTIVAL_SERVER_PID"` -ne 1 ]; then
139 echo "Error: Festival not started"
143 # Test connection to festival server
144 output
=`echo -E "Rockbox" | $FESTIVAL_CLIENT --server \
145 $FESTIVAL_HOST --otype riff --ttw --output \
147 if [ $?
-ne 0 ]; then
148 echo "Error: Couldn't connect to festival server at" \
149 "$FESTIVAL_HOST ($output)"
155 if [ ! `which $FLITE_BIN` ]; then
156 echo "Error: $FLITE_BIN not found"
162 if [ ! `which $ESPEAK_BIN` ]; then
163 echo "Error: $ESPEAK_BIN not found"
168 echo "Error: no valid TTS engine selected: $TTS_ENGINE"
172 if [ ! -x $WAVTRIM ]; then
173 echo "Error: $WAVTRIM is not available"
178 # Perform any necessary shutdown for TTS engine
182 if [ X
$FESTIVAL_START = XY
]; then
183 # XXX: This is probably possible to do using festival_client
184 kill $FESTIVAL_SERVER_PID > /dev
/null
2>&1
190 # Check if executables exist and perform any necessary initialisation
194 # Check for lame binary
195 if [ ! `which $LAME_BIN` ]; then
196 echo "Error: $LAME_BIN not found"
201 # Check for speexenc binary
202 if [ ! `which $SPEEX_BIN` ]; then
203 echo "Error: $SPEEX_BIN not found"
208 # Check for vorbis encoder binary
209 if [ ! `which $VORBIS_BIN` ]; then
210 echo "Error: $VORBIS_BIN not found"
215 echo "Error: no valid encoder selected: $ENCODER"
222 # Encode file $1 with ENCODER and save the result in $2, delete $1 if specified
227 if [ ! -f "$INPUT" ]; then
228 echo "Warning: missing input file: \"$INPUT\""
230 echo "Action: Encode $OUTPUT with $ENCODER"
233 $LAME_BIN $LAME_OPTS "$WAV_FILE" "$OUTPUT" >>$ENC_LOG 2>&1
236 $SPEEX_BIN $SPEEX_OPTS "$WAV_FILE" "$OUTPUT" >>$ENC_LOG 2>&1
239 $VORBIS_BIN $VORBIS_OPTS "$WAV_FILE" -o "$OUTPUT" >>$ENC_LOG 2>&1
241 if [ ! -f "$OUTPUT" ]; then
242 echo "Warning: missing output file \"$OUTPUT\""
247 # Generate file $2 containing $1 spoken by TTS_ENGINE, trim silence
251 if [ ! -f "$WAV_FILE" ] ||
[ X
$OVERWRITE_WAV = XY
]; then
252 if [ "${TO_SPEAK}" = "" ]; then
257 echo "Action: Generate $WAV_FILE with festival"
258 echo -E "$TO_SPEAK" |
$FESTIVAL_CLIENT $FESTIVAL_OPTS \
259 --server $FESTIVAL_HOST \
260 --otype riff
--ttw --output "$WAV_FILE" 2>"$WAV_FILE"
263 echo "Action: Generate $WAV_FILE with eSpeak"
264 echo $ESPEAK_BIN $ESPEAK_OPTS -w "$WAV_FILE"
265 echo -E "$TO_SPEAK" |
$ESPEAK_BIN $ESPEAK_OPTS -w "$WAV_FILE"
268 echo "Action: Generate $WAV_FILE with flite"
269 echo -E "$TO_SPEAK" |
$FLITE_BIN $FLITE_OPTS -o "$WAV_FILE"
280 echo "Action: Trim $WAV_FILE"
281 $WAVTRIM "$WAVEFILE" $NOISEFLOOR