2006-11-03 21:47:52 +00:00
|
|
|
#!/bin/sh
|
|
|
|
# __________ __ ___.
|
|
|
|
# Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
# Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
# Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
# Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
# \/ \/ \/ \/ \/
|
|
|
|
# $Id$
|
|
|
|
#
|
|
|
|
# Copyright 2006 Jonas Häggqvist, some parts Copyright 2004 Daniel Gudlat
|
|
|
|
#
|
|
|
|
# All files in this archive are subject to the GNU General Public License.
|
|
|
|
# See the file COPYING in the source tree root for full license agreement.
|
|
|
|
#
|
|
|
|
# This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
# KIND, either express or implied.
|
|
|
|
|
|
|
|
# Include voicecommon.sh from the same dir as this script
|
|
|
|
# Any settings from voicecommon can be overridden if added below the following
|
|
|
|
# line.
|
|
|
|
source `dirname $0`'/voicecommon.sh'
|
|
|
|
|
|
|
|
####################
|
|
|
|
# General settings #
|
|
|
|
####################
|
|
|
|
|
|
|
|
# These settings can be overridden by passing a file with definitions as
|
|
|
|
# the fourth parameter to this script
|
|
|
|
|
|
|
|
# which TTS engine to use. Available: festival, flite, espeak
|
|
|
|
TTS_ENGINE=festival
|
|
|
|
# which encoder to use, available: lame, speex, vorbis (only lame will produce
|
|
|
|
# functional voice clips at this point)
|
|
|
|
ENCODER=lame
|
|
|
|
# Where to save temporary files
|
|
|
|
TEMPDIR=/tmp
|
2007-08-05 19:19:39 +00:00
|
|
|
# List of IDs to send to voicefont
|
|
|
|
VOICEFONTIDS=voicefontids
|
2006-11-03 21:47:52 +00:00
|
|
|
|
|
|
|
###################
|
|
|
|
# End of settings #
|
|
|
|
###################
|
|
|
|
|
2007-08-05 19:19:39 +00:00
|
|
|
TARGET_ID="$4"
|
2006-11-03 21:47:52 +00:00
|
|
|
createvoicefile() {
|
2007-08-13 12:21:16 +00:00
|
|
|
RLANG="$1"
|
2007-08-05 19:19:39 +00:00
|
|
|
$GENLANG -e=$ENGLISH -o -t=$TARGET $LANG_FILE > $VOICEFONTIDS
|
|
|
|
$VOICEFONT "$VOICEFONTIDS" "$TARGET_ID" "$TEMPDIR/" "./$RLANG.voice"
|
2007-08-13 12:21:16 +00:00
|
|
|
rm -f $VIOCEFONTIDS
|
2006-11-03 21:47:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
deletefiles() {
|
|
|
|
# XXX: might be unsafe depending on the value of TEMPDIR
|
|
|
|
rm -f "${TEMPDIR}"/LANG_*
|
|
|
|
rm -f "${TEMPDIR}"/VOICE_*
|
2007-08-13 12:21:16 +00:00
|
|
|
rm -f "${TEMPDIR}"/NOT_USED_*
|
2006-11-03 21:47:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
generateclips() {
|
|
|
|
ROCKBOX_DIR="$1"
|
|
|
|
RLANG="$2"
|
|
|
|
TARGET="$3"
|
|
|
|
GENLANG="$ROCKBOX_DIR"/tools/genlang
|
|
|
|
ENGLISH="$ROCKBOX_DIR"/apps/lang/english.lang
|
|
|
|
LANG_FILE="$ROCKBOX_DIR"/apps/lang/$RLANG.lang
|
|
|
|
|
|
|
|
$GENLANG -e=$ENGLISH -o -t=$TARGET $LANG_FILE |(
|
|
|
|
i=0
|
|
|
|
while read line; do
|
|
|
|
case `expr $i % 3` in
|
|
|
|
0)
|
|
|
|
# String ID no.
|
|
|
|
NUMBER=`echo $line |cut -b 2-`
|
|
|
|
;;
|
|
|
|
1)
|
|
|
|
# String ID
|
|
|
|
ID=`echo $line |cut -b 5-`
|
|
|
|
;;
|
|
|
|
2)
|
|
|
|
# String
|
|
|
|
STRING=`echo $line |cut -b 8-`
|
2007-08-13 12:21:16 +00:00
|
|
|
# xxx: Should the hash include encoder/tts options?
|
|
|
|
POOL_FILE=${POOL}/`echo "$STRING" |md5sum|cut -b-32`-${RLANG}.mp3
|
2006-11-03 21:47:52 +00:00
|
|
|
|
2006-12-23 22:03:49 +00:00
|
|
|
if [ -n "$POOL" ]; then
|
|
|
|
# we have a common pool of snippets, check that first
|
|
|
|
# for available mp3 sounds, and if it is available copy
|
|
|
|
# (symlink!) it over
|
2007-08-13 12:21:16 +00:00
|
|
|
if [ -f "$POOL_FILE" ]; then
|
|
|
|
echo "Re-using $ID from pool (${POOL_FILE})"
|
2006-12-23 22:03:49 +00:00
|
|
|
if [ ! -e "$TEMPDIR/$ID".mp3 ]; then
|
|
|
|
# only do this if not present
|
2007-08-13 12:21:16 +00:00
|
|
|
ln -sf "$POOL_FILE" "$TEMPDIR/$ID".mp3
|
2006-12-23 22:03:49 +00:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
# only make an mp3 if not already present
|
|
|
|
if [ ! -e "$TEMPDIR/$ID".mp3 ]; then
|
|
|
|
# Now generate the file
|
|
|
|
voice "$STRING" "$TEMPDIR/$ID".wav
|
|
|
|
if [ -n "$POOL" ]; then
|
|
|
|
# create it in the pool, symlink it back
|
2007-08-13 12:21:16 +00:00
|
|
|
encode "$TEMPDIR/$ID".wav "$POOL_FILE"
|
|
|
|
ln -sf "$POOL_FILE" "$TEMPDIR/$ID".mp3
|
2006-12-23 22:03:49 +00:00
|
|
|
else
|
|
|
|
encode "$TEMPDIR/$ID".wav "$TEMPDIR/$ID".mp3
|
|
|
|
fi
|
|
|
|
fi
|
2006-11-03 21:47:52 +00:00
|
|
|
;;
|
|
|
|
esac
|
|
|
|
i=`expr $i + 1`
|
|
|
|
done
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2007-08-11 22:16:50 +00:00
|
|
|
if [ -z "$4" ]; then
|
2007-08-05 19:19:39 +00:00
|
|
|
echo "Usage: $0 rockboxdirectory language target targetid [settingsfile]";
|
2006-11-03 21:47:52 +00:00
|
|
|
exit 32
|
|
|
|
else
|
|
|
|
if [ ! -d "$1" ] || [ ! -f "$1/tools/genlang" ]; then
|
|
|
|
echo "Error: $1 is not a Rockbox directory"
|
|
|
|
exit 33
|
|
|
|
fi
|
2007-08-13 12:21:16 +00:00
|
|
|
# Check for valid language
|
2006-11-03 21:47:52 +00:00
|
|
|
if [ ! -f "$1/apps/lang/$2.lang" ]; then
|
|
|
|
echo "Error: $2 is not a valid language"
|
|
|
|
exit 34
|
|
|
|
fi
|
2007-08-05 19:19:39 +00:00
|
|
|
if [ ! -z "$5" ]; then
|
|
|
|
if [ -f "$5" ]; then
|
2006-11-03 21:47:52 +00:00
|
|
|
# Read settings from file
|
2007-08-13 12:21:16 +00:00
|
|
|
. "$5"
|
2006-11-03 21:47:52 +00:00
|
|
|
else
|
2007-08-05 19:19:39 +00:00
|
|
|
echo "Error: $5 does not exist"
|
2006-11-03 21:47:52 +00:00
|
|
|
exit 36
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
# XXX: check for valid $TARGET?
|
|
|
|
fi
|
|
|
|
|
|
|
|
VOICEFONT=`dirname $0`/voicefont
|
|
|
|
if [ ! -x $VOICEFONT ]; then
|
|
|
|
echo "Error: $VOICEFONT does not exist or is not executable"
|
|
|
|
exit 35
|
|
|
|
fi
|
|
|
|
|
|
|
|
init_tts
|
|
|
|
init_encoder
|
|
|
|
generateclips "$1" "$2" "$3"
|
|
|
|
stop_tts
|
2007-08-13 12:21:16 +00:00
|
|
|
createvoicefile "$2"
|
|
|
|
deletefiles
|