#!/bin/sh #Rockbox voice creation with Mbrola and Freephone for English # and with Ru_tts for Russian. # # Put this script onto the PATH and use as TTS backend # for the Rockbox voice creation. # Used data locations. # Edit these paths according to your environment. mbrola_voice="/usr/share/mbrola/en1/en1" lexicon_en="/usr/share/freespeech/enlex.db" lexicon_ru="/usr/share/freespeech/rulex.db" # Russian text must be in unicode LANG=ru_RU.utf8 export LANG # Be quiet exec >/dev/null 2>&1 # Accept voice parameter if any case $1 in --bass) shift pitch_en=0.6 pitch_ru=0 ;; --baritone) shift pitch_en=0.8 pitch_ru=0.15 ;; --tenor) shift pitch_en=1.2 pitch_ru=0.45 ;; --alto) shift pitch_en=1.4 pitch_ru=0.6 ;; *) # Default voice pitch_en=1.0 pitch_ru=0.3 ;; esac # Old and new ru_tts versions treat speech parameters differently. if ru_tts -v 2>/dev/null; then rate_ru=1.25 pitch_ru=$pitch_en else rate_ru=0.25 fi # Read and clean text string read string string=`echo "$string" | sed 's/LCD/ L C D /g'` string=`echo "$string" | sed 's/WPS/ W P S /g'` string=`echo "$string" | sed 's/VBR/ V B R /g'` string=`echo "$string" | sed 's/FM/ F M /g'` string=`echo "$string" | sed 's/PCM/ P C M /g'` string=`echo "$string" | sed 's/Last.fm/ Last dot F M /g'` string=`echo "$string" | sed 's/Spindown/Spin down/g'` string=`echo "$string" | sed 's/Makeup/Make up/g'` string=`echo "$string" | sed 's/^bmp$/b m p/g'` string=`echo "$string" | sed 's/^mpegplayer$/mpeg player/g'` string=`echo "$string" | sed 's/^png$/p n g/g'` string=`echo "$string" | sed 's/^ppmviewer$/p p m viewer/g'` string=`echo "$string" | sed 's/^vbrfix$/v b r fix/g'` string=`echo "$string" | sed 's/^zxbox$/z x box/g'` string=`echo "$string" | sed 's/^flipit$/flip it/g'` string=`echo "$string" | sed 's/^spacerocks$/space rocks/g'` string=`echo "$string" | sed 's/^rocklife$/rock life/g'` string=`echo "$string" | sed 's/^fft$/f f t/g'` string=`echo "$string" | sed 's/^starfield$/star field/g'` string=`echo "$string" | sed 's/^alarmclock$/alarm clock/g'` string=`echo "$string" | sed 's/^boomshine$/boom shine/g'` string=`echo "$string" | sed 's/^lrcplayer$/l r c player/g'` string=`echo "$string" | sed 's/^pictureflow$/picture flow/g'` string=`echo "$string" | sed 's/^robotfindskitten$/robot find skitten/g'` string=`echo "$string" | sed 's/^md5sum$/m d 5 sum/g'` string=`echo "$string" | sed "s/[(\"_')]/ /g" | sed 's/\(\.\)\([^ 0-9]\)/\1 \2/g'` # Detect language and use an appropriate TTS engine Russian=no if echo "$string" | grep -iq '[а-я]'; then Russian=yes elif [ "$RB_PREFER_RU" = "yes" ]; then if echo "$string" | grep -q '^[^a-zA-Z]*$'; then Russian=yes fi fi if [ "$Russian" = "yes" ]; then uppercase=`echo "АБВГДЕЁЖЗИЙКЛМНОПРСТУФХЦЧШЩЪЫЬЭЮЯ" | recode utf8..koi8-r` lowercase=`echo "абвгдеёжзийклмнопрстуфхцчшщъыьэюя" | recode utf8..koi8-r` echo "$string" | sed 's/FM/эфэ+м/g' | sed 's/\(^\| \)С\./\1ЭС /g' | sed 's/\(^\| \)\([БВ]\)\./\1\2Э /g' | sed 's/\(^\| \)К\./\1КА /g' | sed 's/\(^\| \)\([а-яА-Я]\)\./\1\2 /g' | sed 's/&/ и /g' | sed 's/\([0-9]\) *\([0-9]\)/\1, \2/g' | sed 's/\([0-9]\.\) *\([0-9]\)/\1, \2/g' | recode utf8..koi8-r | tr "$uppercase" "$lowercase" | ru_tts -r $rate_ru -p $pitch_ru -s "$lexicon_ru" | sox -G -D -t raw -s -1 -r 10000 -c 1 -v 0.75 - -t wav -r 16000 -2 "$1" rate else echo "$string" | sed 's/&/ and /g' | sed 's|/| slash |g' | sed 's/\([aeiouyAEIOUY][a-zA-Z]*\)\([0-9]\)/\1 \2/g' | freephone -h "$lexicon_en" -i - -o - | mbrola -e -v 1.5 -f $pitch_en -t 0.75 "$mbrola_voice" - "$1" fi