Chapter 1. Text to speech

Table of Contents

Base System
Program integration
Opera
KMouth
emerge

I use a basic Text-to-Speech system (TTS) for the purpose that the computer can tell me pieces of information instead of that I have to look on the screen.

This is helpful if I e.g. emerge (download & compile) a program in a console the background and work on something different in the foreground. Normally I don't know when the compile process is done; but if the computer tells you that all is done, you don't have always to look onto the console.

Base System

I use the txt2pho program to convert the text into phonemes, and mbrola for transforming the phonemes into spoken audio. I do some extra preprocessing of the text to fit my needs:

Example 1.1. /home/cweiske/scripts/say

#!/bin/sh
if [ x"$#" = x"0" ]; then
  file=/dev/stdin
  else
        file=${1}
fi
cat $file \
| sed 's/\.com/ dot comm /g' \
| sed -r 's/00:([0-9]+)/0 Uhr \1/g' \
| sed -r 's/([0-9]+):00/genau \1 Uhr/g' \
| /usr/share/txt2pho/preproc/preproc /usr/share/txt2pho/preproc/Rules.lst /usr/local/txt2pho/preproc/Hadifix.abk \
| sed 's/cweiske/ c weiske /g' \
| /usr/bin/txt2pho -m \
| /home/cweiske/scripts/say-de5 \
| aplay -

You can pipe your text into the program, e.g. via echo "hello you there" | say or just give a filename which is read. Then there are some conversions to my liking; adresses ending with ".com" are pronounced "dot com" while german addresses ".de" are pronounced "Punkt de", which is the german speak. Then some time conversion is done as the normal is suboptimal. And of course "cweiske" is spoken "c weiske".

The say-de5 is the script for converting the phonemes into audio with the german voice number 5. For fast changing I put this in an extra script so that the pitch and loudness can be specific for every voice.

Example 1.2. /home/cweiske/scripts/say-de5

#!/bin/sh
#german female voice
cat /dev/stdin \
| /usr/bin/mbrola -v3 -f2 -t1 /usr/share/txt2pho/voices/german/de5 - -.au

Now I made another script which just passes all the parameters to the say script, as some programs just can call one program with the text as the parameter (like Opera)

Example 1.3. /home/cweiske/scripts/sayparam

#!/bin/sh
echo $* | say

Last but not least there is a script which tells the time. I put it in a cron job which is called every ten minutes.

Example 1.4. /home/cweiske/scripts/saytime

#!/bin/sh
echo Es ist jetzt `date '+%H:%M'` | say