Slight improvement of the 'Rockboxed' WPS for the H300 by better placing the progressbar.
[Rockbox.git] / tools / gentalkclips.sh
blob8da3b377043bbf69391b944f1ab5475fe4ee2723
1 #!/bin/sh
2 # __________ __ ___.
3 # Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 # Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 # Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 # Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 # \/ \/ \/ \/ \/
8 # $Id$
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
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.
18 # This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19 # KIND, either express or implied.
21 # Note: You may wish to change some of the settings below.
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.
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.
40 # NOTE: If you don't already have them installed, you may obtain the Festival
41 # text to speech system and several voices at:
43 # http://www.cstr.ed.ac.uk/projects/festival.html
44 # http://festvox.org/festival/
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/
49 # Known bugs
50 # - This script generates talk clips for all files, Rockbox only uses talk clips
51 # for music files it seems.
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.
56 source `dirname $0`'/voicecommon.sh'
58 ####################
59 # General settings #
60 ####################
62 # which TTS engine to use. Available: festival, flite, espeak
63 TTS_ENGINE=festival
64 # which encoder to use, available: lame, speex, vorbis (only lame will produce
65 # functional voice clips)
66 ENCODER=lame
67 # whether to overwrite existing mp3 files or only create missing ones (Y/N)
68 OVERWRITE_TALK=N
69 # whether, when overwriting mp3 files, also to regenerate all the wav files
70 OVERWRITE_WAV=N
71 # whether to remove the intermediary wav files after creating the mp3 files
72 REMOVE_WAV=Y
73 # whether to recurse into subdirectories
74 RECURSIVE=Y
75 # whether to strip extensions from filenames
76 STRIP_EXTENSIONS=Y
78 ###################
79 # End of settings #
80 ###################
82 strip_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
90 # Walk directory $1, creating talk files if necessary, descend into
91 # subdirecotries if specified
92 dirwalk() {
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
102 TO_SPEAK=`basename "$i"`
103 if [ X$STRIP_EXTENSIONS = XY ]; then
104 strip_extension "$TO_SPEAK"
107 if [ -d "$i" ]; then
108 # $i is a dir:
109 SAVE_AS="$i"/_dirname.talk
110 WAV_FILE="$SAVE_AS".wav
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"
119 # Need to be done lastly, or all variables will be dirty
120 if [ X$RECURSIVE = XY ]; then
121 dirwalk "$i"
123 else
124 # $i is a file:
125 SAVE_AS="$i".talk
126 WAV_FILE="$SAVE_AS".wav
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"
135 # Remove wav file if specified
136 if [ X$REMOVEWAV = XY ]; then
137 rm -f "$WAV_FILE"
139 done
140 else
141 echo "Warning: $1 is not a directory"
145 init_tts
146 init_encoder
147 if [ $# -gt 0 ]; then
148 dirwalk "$*"
149 else
150 dirwalk .
152 stop_tts