summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
Diffstat (limited to 'tools')
-rwxr-xr-xtools/gentalkclips.sh152
-rwxr-xr-xtools/genvoice.sh153
-rw-r--r--tools/voicecommon.sh301
3 files changed, 0 insertions, 606 deletions
diff --git a/tools/gentalkclips.sh b/tools/gentalkclips.sh
deleted file mode 100755
index 8da3b37704..0000000000
--- a/tools/gentalkclips.sh
+++ /dev/null
@@ -1,152 +0,0 @@
1#!/bin/sh
2# __________ __ ___.
3# Open \______ \ ____ ____ | | _\_ |__ _______ ___
4# Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5# Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6# Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7# \/ \/ \/ \/ \/
8# $Id$
9#
10# Copyright (c) 2004 Daniel Gudlat
11# - http://www.rockbox.org/tracker/task/2131
12# Copyright (c) 2006 Jonas Häggqvist
13# - This version, only dirwalk and the following comments remains
14#
15# All files in this archive are subject to the GNU General Public License.
16# See the file COPYING in the source tree root for full license agreement.
17#
18# This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19# KIND, either express or implied.
20#
21# Note: You may wish to change some of the settings below.
22#
23# A script to automatically generate audio clips containing the names of all
24# folders in a directory tree for use with the "Talkbox" feature available to
25# users of the Rockbox open source firmware for Archos MP3 players and
26# recorders as well as several other devices. Talkbox permits the device to
27# speak the names of the folders as one navigates the directory structure on
28# the device, thus permitting "eyes-free" use for those for whom the usual
29# visual navigation is difficult or simply inadvisable.
30#
31# Audio clips are captured and stored in wave format, then converted into MP3
32# format by a third party application (lame). If you execute the script,
33# passing it the top level of your music file hierarchy as an argument while
34# your device is connected to your PC, then the resulting audio clips will be
35# generated and stored in the correct location for use with the Talkbox
36# feature. Alternatively, if you mirror your music folder structure from your
37# PC to your Archos device, you can just run the script on the PC and then
38# update the files on your Archos with your usual synchronization routine.
39#
40# NOTE: If you don't already have them installed, you may obtain the Festival
41# text to speech system and several voices at:
42#
43# http://www.cstr.ed.ac.uk/projects/festival.html
44# http://festvox.org/festival/
45#
46# The most pleasant freely available Festival voice I know of is the slt_arctic
47# voice from HST at http://hts.ics.nitech.ac.jp/
48#
49# Known bugs
50# - This script generates talk clips for all files, Rockbox only uses talk clips
51# for music files it seems.
52
53# Include voicecommon.sh from the same dir as this script
54# Any settings from voicecommon can be overridden if added below the following
55# line.
56source `dirname $0`'/voicecommon.sh'
57
58####################
59# General settings #
60####################
61
62# which TTS engine to use. Available: festival, flite, espeak
63TTS_ENGINE=festival
64# which encoder to use, available: lame, speex, vorbis (only lame will produce
65# functional voice clips)
66ENCODER=lame
67# whether to overwrite existing mp3 files or only create missing ones (Y/N)
68OVERWRITE_TALK=N
69# whether, when overwriting mp3 files, also to regenerate all the wav files
70OVERWRITE_WAV=N
71# whether to remove the intermediary wav files after creating the mp3 files
72REMOVE_WAV=Y
73# whether to recurse into subdirectories
74RECURSIVE=Y
75# whether to strip extensions from filenames
76STRIP_EXTENSIONS=Y
77
78###################
79# End of settings #
80###################
81
82strip_extension() {
83 TO_SPEAK=$1
84 # XXX: add any that needs adding
85 for ext in mp3 ogg flac mpc sid; do
86 TO_SPEAK=`echo "$TO_SPEAK" |sed "s/\.$ext//i"`
87 done
88}
89
90# Walk directory $1, creating talk files if necessary, descend into
91# subdirecotries if specified
92dirwalk() {
93 if [ -d "$1" ]; then
94 for i in "$1"/*; do
95 # Do not generate talk clip for talk(.wav) files
96 if [ `echo "$i" | grep -c "\.talk$"` -ne 0 ] || \
97 [ `echo "$i" | grep -c "\.talk\.wav$"` -ne 0 ]; then
98 echo "Notice: Skipping file \"$i\""
99 continue
100 fi
101
102 TO_SPEAK=`basename "$i"`
103 if [ X$STRIP_EXTENSIONS = XY ]; then
104 strip_extension "$TO_SPEAK"
105 fi
106
107 if [ -d "$i" ]; then
108 # $i is a dir:
109 SAVE_AS="$i"/_dirname.talk
110 WAV_FILE="$SAVE_AS".wav
111
112 # If a talk clip already exists, only generate a new one if
113 # specified
114 if [ ! -f "$SAVE_AS" ] || [ X$OVERWRITE_TALK = XY ]; then
115 voice "$TO_SPEAK" "$WAV_FILE"
116 encode "$WAV_FILE" "$SAVE_AS"
117 fi
118
119 # Need to be done lastly, or all variables will be dirty
120 if [ X$RECURSIVE = XY ]; then
121 dirwalk "$i"
122 fi
123 else
124 # $i is a file:
125 SAVE_AS="$i".talk
126 WAV_FILE="$SAVE_AS".wav
127
128 # If a talk clip already exists, only generate a new one if
129 # specified
130 if [ ! -f "$i.talk" ] || [ X$OVERWRITE_TALK != XY ]; then
131 voice "$TO_SPEAK" "$WAV_FILE"
132 encode "$WAV_FILE" "$SAVE_AS"
133 fi
134 fi
135 # Remove wav file if specified
136 if [ X$REMOVEWAV = XY ]; then
137 rm -f "$WAV_FILE"
138 fi
139 done
140 else
141 echo "Warning: $1 is not a directory"
142 fi
143}
144
145init_tts
146init_encoder
147if [ $# -gt 0 ]; then
148 dirwalk "$*"
149else
150 dirwalk .
151fi
152stop_tts
diff --git a/tools/genvoice.sh b/tools/genvoice.sh
deleted file mode 100755
index 4e58801205..0000000000
--- a/tools/genvoice.sh
+++ /dev/null
@@ -1,153 +0,0 @@
1#!/bin/sh
2# __________ __ ___.
3# Open \______ \ ____ ____ | | _\_ |__ _______ ___
4# Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5# Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6# Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7# \/ \/ \/ \/ \/
8# $Id$
9#
10# Copyright 2006 Jonas Häggqvist, some parts Copyright 2004 Daniel Gudlat
11#
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.
14#
15# This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16# KIND, either express or implied.
17
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.
21source `dirname $0`'/voicecommon.sh'
22
23####################
24# General settings #
25####################
26
27# These settings can be overridden by passing a file with definitions as
28# the fourth parameter to this script
29
30# which TTS engine to use. Available: festival, flite, espeak
31TTS_ENGINE=festival
32# which encoder to use, available: lame, speex, vorbis (only lame will produce
33# functional voice clips at this point)
34ENCODER=lame
35# Where to save temporary files
36TEMPDIR=/tmp
37# List of IDs to send to voicefont
38VOICEFONTIDS=voicefontids
39
40###################
41# End of settings #
42###################
43
44TARGET_ID="$4"
45createvoicefile() {
46 RLANG="$1"
47 $GENLANG -e=$ENGLISH -o -t=$TARGET $LANG_FILE > $VOICEFONTIDS
48 $VOICEFONT "$VOICEFONTIDS" "$TARGET_ID" "$TEMPDIR/" "./$RLANG.voice"
49 rm -f $VIOCEFONTIDS
50}
51
52deletefiles() {
53 # XXX: might be unsafe depending on the value of TEMPDIR
54 rm -f "${TEMPDIR}"/LANG_*
55 rm -f "${TEMPDIR}"/VOICE_*
56 rm -f "${TEMPDIR}"/NOT_USED_*
57}
58
59generateclips() {
60 ROCKBOX_DIR="$1"
61 RLANG="$2"
62 TARGET="$3"
63 GENLANG="$ROCKBOX_DIR"/tools/genlang
64 ENGLISH="$ROCKBOX_DIR"/apps/lang/english.lang
65 LANG_FILE="$ROCKBOX_DIR"/apps/lang/$RLANG.lang
66
67 $GENLANG -e=$ENGLISH -o -t=$TARGET $LANG_FILE |(
68 i=0
69 while read line; do
70 case `expr $i % 3` in
71 0)
72 # String ID no.
73 NUMBER=`echo $line |cut -b 2-`
74 ;;
75 1)
76 # String ID
77 ID=`echo $line |cut -b 5-`
78 ;;
79 2)
80 # String
81 STRING=`echo $line |cut -b 8-`
82 # xxx: Should the hash include encoder/tts options?
83 POOL_FILE=${POOL}/`echo "$STRING" |md5sum|cut -b-32`-${RLANG}.mp3
84
85 if [ -n "$POOL" ]; then
86 # we have a common pool of snippets, check that first
87 # for available mp3 sounds, and if it is available copy
88 # (symlink!) it over
89 if [ -f "$POOL_FILE" ]; then
90 echo "Re-using $ID from pool (${POOL_FILE})"
91 if [ ! -e "$TEMPDIR/$ID".mp3 ]; then
92 # only do this if not present
93 cp -f "$POOL_FILE" "$TEMPDIR/$ID".mp3
94 fi
95 fi
96 fi
97
98 # only make an mp3 if not already present
99 if [ ! -e "$TEMPDIR/$ID".mp3 ]; then
100 # Now generate the file
101 voice "$STRING" "$TEMPDIR/$ID".wav
102 if [ -n "$POOL" ]; then
103 # create it in the pool, symlink it back
104 encode "$TEMPDIR/$ID".wav "$POOL_FILE"
105 cp -f "$POOL_FILE" "$TEMPDIR/$ID".mp3
106 else
107 encode "$TEMPDIR/$ID".wav "$TEMPDIR/$ID".mp3
108 fi
109 fi
110 ;;
111 esac
112 i=`expr $i + 1`
113 done
114 )
115}
116
117if [ -z "$4" ]; then
118 echo "Usage: $0 rockboxdirectory language target targetid [settingsfile]";
119 exit 32
120else
121 if [ ! -d "$1" ] || [ ! -f "$1/tools/genlang" ]; then
122 echo "Error: $1 is not a Rockbox directory"
123 exit 33
124 fi
125 # Check for valid language
126 if [ ! -f "$1/apps/lang/$2.lang" ]; then
127 echo "Error: $2 is not a valid language"
128 exit 34
129 fi
130 if [ ! -z "$5" ]; then
131 if [ -f "$5" ]; then
132 # Read settings from file
133 . "$5"
134 else
135 echo "Error: $5 does not exist"
136 exit 36
137 fi
138 fi
139 # XXX: check for valid $TARGET?
140fi
141
142VOICEFONT=`dirname $0`/voicefont
143if [ ! -x $VOICEFONT ]; then
144 echo "Error: $VOICEFONT does not exist or is not executable"
145 exit 35
146fi
147
148init_tts
149init_encoder
150generateclips "$1" "$2" "$3"
151stop_tts
152createvoicefile "$2"
153deletefiles
diff --git a/tools/voicecommon.sh b/tools/voicecommon.sh
deleted file mode 100644
index 458a7b2ec6..0000000000
--- a/tools/voicecommon.sh
+++ /dev/null
@@ -1,301 +0,0 @@
1#!/bin/sh
2# __________ __ ___.
3# Open \______ \ ____ ____ | | _\_ |__ _______ ___
4# Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5# Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6# Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7# \/ \/ \/ \/ \/
8# $Id$
9#
10# Copyright (c) 2006 Jonas Häggqvist
11#
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.
14#
15# This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16# KIND, either express or implied.
17#
18# A selection of functions common to creating voicefiles for Rockbox.
19#
20# You may wish to change some of the settings below.
21
22#####################
23# Program locations #
24#####################
25
26# Leave any you're not using untouched, enter full path if the program is
27# not found
28
29# the festival main executable
30FESTIVAL_BIN=festival
31# the festival_client binary
32FESTIVAL_CLIENT=festival_client
33
34# The flite executable
35FLITE_BIN=flite
36
37# The eSpeak executable
38ESPEAK_BIN=espeak
39
40# The lame executable
41LAME_BIN=lame
42
43# The speexenc executable
44SPEEX_BIN=speexenc
45
46# The oggenc executable
47VORBIS_BIN=oggenc
48
49# Tools directory
50TOOLSDIR=`dirname $0`
51
52# The wavtrim executable
53WAVTRIM=$TOOLSDIR/wavtrim
54
55# The SAPI5 script directory
56if [ -f "`which cygpath`" ]; then
57 SAPI5DIR=`cygpath $TOOLSDIR -a -w`
58fi
59
60#####################
61# Festival settings #
62#####################
63
64# If you're not using festival, leave untouched
65
66# whether to start the Festival server locally (Y/N)
67FESTIVAL_START=Y
68# the host of the Festival server
69# this is set to localhost automatically when FESTIVAL_START is Y
70FESTIVAL_HOST=localhost
71# the port of the Festival server
72FESTIVAL_PORT=1314
73# where to log the Festival client output
74FESTIVAL_LOG=/dev/null
75# other options to the festival server
76FESTIVAL_OPTS=""
77
78##################
79# Flite settings #
80##################
81
82# If you're not using flite, leave untouched
83FLITE_OPTS=""
84
85###################
86# eSpeak settings #
87###################
88
89# If you're not using eSpeak, leave untouched
90ESPEAK_OPTS=""
91
92####################
93# Wavtrim settings #
94####################
95
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
98# 32767).
99#
100# 500 is a good guess - at least for Festival
101
102NOISEFLOOR='500'
103
104#####################
105# Encoding settings #
106#####################
107# where to log the encoder output
108ENC_LOG=/dev/null
109
110# Suggested: --vbr-new -t --nores -S
111# VBR, independent frames, silent mode
112LAME_OPTS="--vbr-new -t --nores -S"
113
114# Suggested:
115# XXX: suggest a default
116SPEEX_OPTS=""
117
118# Suggested: -q0 --downmix
119# Low quality, mono
120VORBIS_OPTS="-q0 --downmix"
121
122###################
123# End of settings #
124###################
125
126# Check if executables exist and perform any necessary initialisation
127init_tts() {
128 case $TTS_ENGINE in
129 festival)
130 # Check for festival_client
131 if [ ! -f "`which $FESTIVAL_CLIENT`" ]; then
132 echo "Error: $FESTIVAL_CLIENT not found"
133 exit 4
134 fi
135
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"
140 exit 3
141 fi
142 FESTIVAL_HOST='localhost'
143 $FESTIVAL_BIN $FESTIVAL_OPTS --server 2>&1 > /dev/null &
144 FESTIVAL_SERVER_PID=$!
145 sleep 3
146 if [ `ps | grep -c "^\ *$FESTIVAL_SERVER_PID"` -ne 1 ]; then
147 echo "Error: Festival not started"
148 exit 9
149 fi
150 fi
151 # Test connection to festival server
152 output=`echo -E "Rockbox" | $FESTIVAL_CLIENT --server \
153 $FESTIVAL_HOST --otype riff --ttw --output \
154 /dev/null 2>&1`
155 if [ $? -ne 0 ]; then
156 echo "Error: Couldn't connect to festival server at" \
157 "$FESTIVAL_HOST ($output)"
158 exit 8
159 fi
160 ;;
161 flite)
162 # Check for flite
163 if [ ! -f "`which $FLITE_BIN`" ]; then
164 echo "Error: $FLITE_BIN not found"
165 exit 5
166 fi
167 ;;
168 espeak)
169 # Check for espeak
170 if [ ! -f "`which $ESPEAK_BIN`" ]; then
171 echo "Error: $ESPEAK_BIN not found"
172 exit 5
173 fi
174 ;;
175 sapi5)
176 # Check for SAPI5
177 cscript /B $SAPI5DIR/sapi5_init_tts.vbs
178 if [ $? -ne 0 ]; then
179 echo "Error: SAPI 5 not available"
180 exit 5
181 fi
182 ;;
183 *)
184 echo "Error: no valid TTS engine selected: $TTS_ENGINE"
185 exit 2
186 ;;
187 esac
188 if [ ! -x $WAVTRIM ]; then
189 echo "Error: $WAVTRIM is not available"
190 exit 11
191 fi
192}
193
194# Perform any necessary shutdown for TTS engine
195stop_tts() {
196 case $TTS_ENGINE in
197 festival)
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
201 fi
202 ;;
203 esac
204}
205
206# Check if executables exist and perform any necessary initialisation
207init_encoder() {
208 case $ENCODER in
209 lame)
210 # Check for lame binary
211 if [ ! -f "`which $LAME_BIN`" ]; then
212 echo "Error: $LAME_BIN not found"
213 exit 6
214 fi
215 ;;
216 speex)
217 # Check for speexenc binary
218 if [ ! -f "`which $SPEEX_BIN`" ]; then
219 echo "Error: $SPEEX_BIN not found"
220 exit 7
221 fi
222 ;;
223 vorbis)
224 # Check for vorbis encoder binary
225 if [ ! -f "`which $VORBIS_BIN`" ]; then
226 echo "Error: $VORBIS_BIN not found"
227 exit 10
228 fi
229 ;;
230 *)
231 echo "Error: no valid encoder selected: $ENCODER"
232 exit 1
233 ;;
234 esac
235
236}
237
238# Encode file $1 with ENCODER and save the result in $2, delete $1 if specified
239encode() {
240 INPUT=$1
241 OUTPUT=$2
242
243 if [ ! -f "$INPUT" ]; then
244 echo "Warning: missing input file: \"$INPUT\""
245 else
246 echo "Action: Encode $OUTPUT with $ENCODER"
247 case $ENCODER in
248 lame)
249 $LAME_BIN $LAME_OPTS "$WAV_FILE" "$OUTPUT" >>$ENC_LOG 2>&1
250 ;;
251 speex)
252 $SPEEX_BIN $SPEEX_OPTS "$WAV_FILE" "$OUTPUT" >>$ENC_LOG 2>&1
253 ;;
254 vorbis)
255 $VORBIS_BIN $VORBIS_OPTS "$WAV_FILE" -o "$OUTPUT" >>$ENC_LOG 2>&1
256 esac
257 if [ ! -f "$OUTPUT" ]; then
258 echo "Warning: missing output file \"$OUTPUT\""
259 fi
260 fi
261}
262
263# Generate file $2 containing $1 spoken by TTS_ENGINE, trim silence
264voice() {
265 TO_SPEAK=$1
266 WAV_FILE=$2
267 if [ ! -f "$WAV_FILE" ] || [ X$OVERWRITE_WAV = XY ]; then
268 if [ "${TO_SPEAK}" = "" ]; then
269 touch "$WAV_FILE"
270 else
271 case $TTS_ENGINE in
272 festival)
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"
277 ;;
278 espeak)
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"
282 ;;
283 flite)
284 echo "Action: Generate $WAV_FILE with flite"
285 echo -E "$TO_SPEAK" | $FLITE_BIN $FLITE_OPTS -o "$WAV_FILE"
286 ;;
287 sapi5)
288 cscript /B "$SAPI5DIR\sapi5_voice.vbs" ""$TO_SPEAK"" "$WAV_FILE"
289 ;;
290 esac
291 fi
292 fi
293 trim "$WAV_FILE"
294}
295
296# Trim wavefile $1
297trim() {
298 WAVEFILE="$1"
299 echo "Action: Trim $WAV_FILE"
300 $WAVTRIM "$WAVEFILE" $NOISEFLOOR
301}