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
52 # The wavtrim executable
53 WAVTRIM
=$TOOLSDIR/wavtrim
55 # The SAPI5 script directory
56 if [ -f "`which cygpath`" ]; then
57 SAPI5DIR
=`cygpath $TOOLSDIR -a -w`
64 # If you're not using festival, leave untouched
66 # whether to start the Festival server locally (Y/N)
68 # the host of the Festival server
69 # this is set to localhost automatically when FESTIVAL_START is Y
70 FESTIVAL_HOST
=localhost
71 # the port of the Festival server
73 # where to log the Festival client output
74 FESTIVAL_LOG
=/dev
/null
75 # other options to the festival server
82 # If you're not using flite, leave untouched
89 # If you're not using eSpeak, leave untouched
96 # The maximum sample value that will be treated as silence by the wavtrim tool.
97 # The value is expressed as an absolute 16 bit integer sample value (0 dB equals
100 # 500 is a good guess - at least for Festival
104 #####################
105 # Encoding settings #
106 #####################
107 # where to log the encoder output
110 # Suggested: --vbr-new -t --nores -S
111 # VBR, independent frames, silent mode
112 LAME_OPTS
="--vbr-new -t --nores -S"
115 # XXX: suggest a default
118 # Suggested: -q0 --downmix
120 VORBIS_OPTS
="-q0 --downmix"
126 # Check if executables exist and perform any necessary initialisation
130 # Check for festival_client
131 if [ ! -f "`which $FESTIVAL_CLIENT`" ]; then
132 echo "Error: $FESTIVAL_CLIENT not found"
136 # Check for, and start festival server if specified
137 if [ X
$FESTIVAL_START = XY
]; then
138 if [ ! -f "`which $FESTIVAL_BIN`" ]; then
139 echo "Error: $FESTIVAL_BIN not found"
142 FESTIVAL_HOST
='localhost'
143 $FESTIVAL_BIN $FESTIVAL_OPTS --server 2>&1 > /dev
/null
&
144 FESTIVAL_SERVER_PID
=$
!
146 if [ `ps | grep -c "^\ *$FESTIVAL_SERVER_PID"` -ne 1 ]; then
147 echo "Error: Festival not started"
151 # Test connection to festival server
152 output
=`echo -E "Rockbox" | $FESTIVAL_CLIENT --server \
153 $FESTIVAL_HOST --otype riff --ttw --output \
155 if [ $?
-ne 0 ]; then
156 echo "Error: Couldn't connect to festival server at" \
157 "$FESTIVAL_HOST ($output)"
163 if [ ! -f "`which $FLITE_BIN`" ]; then
164 echo "Error: $FLITE_BIN not found"
170 if [ ! -f "`which $ESPEAK_BIN`" ]; then
171 echo "Error: $ESPEAK_BIN not found"
177 cscript
/B
$SAPI5DIR/sapi5_init_tts.vbs
178 if [ $?
-ne 0 ]; then
179 echo "Error: SAPI 5 not available"
184 echo "Error: no valid TTS engine selected: $TTS_ENGINE"
188 if [ ! -x $WAVTRIM ]; then
189 echo "Error: $WAVTRIM is not available"
194 # Perform any necessary shutdown for TTS engine
198 if [ X
$FESTIVAL_START = XY
]; then
199 # XXX: This is probably possible to do using festival_client
200 kill $FESTIVAL_SERVER_PID > /dev
/null
2>&1
206 # Check if executables exist and perform any necessary initialisation
210 # Check for lame binary
211 if [ ! -f "`which $LAME_BIN`" ]; then
212 echo "Error: $LAME_BIN not found"
217 # Check for speexenc binary
218 if [ ! -f "`which $SPEEX_BIN`" ]; then
219 echo "Error: $SPEEX_BIN not found"
224 # Check for vorbis encoder binary
225 if [ ! -f "`which $VORBIS_BIN`" ]; then
226 echo "Error: $VORBIS_BIN not found"
231 echo "Error: no valid encoder selected: $ENCODER"
238 # Encode file $1 with ENCODER and save the result in $2, delete $1 if specified
243 if [ ! -f "$INPUT" ]; then
244 echo "Warning: missing input file: \"$INPUT\""
246 echo "Action: Encode $OUTPUT with $ENCODER"
249 $LAME_BIN $LAME_OPTS "$WAV_FILE" "$OUTPUT" >>$ENC_LOG 2>&1
252 $SPEEX_BIN $SPEEX_OPTS "$WAV_FILE" "$OUTPUT" >>$ENC_LOG 2>&1
255 $VORBIS_BIN $VORBIS_OPTS "$WAV_FILE" -o "$OUTPUT" >>$ENC_LOG 2>&1
257 if [ ! -f "$OUTPUT" ]; then
258 echo "Warning: missing output file \"$OUTPUT\""
263 # Generate file $2 containing $1 spoken by TTS_ENGINE, trim silence
267 if [ ! -f "$WAV_FILE" ] ||
[ X
$OVERWRITE_WAV = XY
]; then
268 if [ "${TO_SPEAK}" = "" ]; then
273 echo "Action: Generate $WAV_FILE with festival"
274 echo -E "$TO_SPEAK" |
$FESTIVAL_CLIENT \
275 --server $FESTIVAL_HOST \
276 --otype riff
--ttw --output "$WAV_FILE" 2>"$WAV_FILE"
279 echo "Action: Generate $WAV_FILE with eSpeak"
280 echo $ESPEAK_BIN $ESPEAK_OPTS -w "$WAV_FILE"
281 echo -E "$TO_SPEAK" |
$ESPEAK_BIN $ESPEAK_OPTS -w "$WAV_FILE"
284 echo "Action: Generate $WAV_FILE with flite"
285 echo -E "$TO_SPEAK" |
$FLITE_BIN $FLITE_OPTS -o "$WAV_FILE"
288 cscript
/B
"$SAPI5DIR\sapi5_voice.vbs" ""$TO_SPEAK"" "$WAV_FILE"
299 echo "Action: Trim $WAV_FILE"
300 $WAVTRIM "$WAVEFILE" $NOISEFLOOR