Made myself a text to speech server today: Festival

Every day solutions to every day challenges. + Brilliant stuff

Moderators: b1o, jkerr82508

Forum rules
Please feel free to post your tip it does not have to be advanced. Also ask questions directly related to the tip here. But do not start new threads with questions or ask for help here. That is what the help section is for. forum rules: http://bjoernvold.com/forum/viewtopic.php?f=8&t=568
User avatar
viking60
Über-Berserk
Posts: 9351
Joined: 14 Mar 2010, 16:34

Made myself a text to speech server today: Festival

Postby viking60 » 02 May 2015, 19:44

ImageWell I like the occasional prank...So it has been a dream of mine to SSH into my homebox when I am away and make the computer speak...


So I installed festival from the repos and happily danced away to my terminal.
Then I wrote my first message to be spoken:

Code: Select all

echo "Hello!  Is anyone home? May the force be with you" | festival --tts

and...
Nothing ;)

Ok so I needed a language file too - I found and installed festival-english
Now it should be OK
:drummer
...and got

Code: Select all

Linux: can't open /dev/dsp

Ah back to the drawing board then.

It turns out that only people with a working text to speech server get it to work right out of the box so here is what I had to do:
    Find
    /usr/share/festival/festival.scm and edit it and put these lines at the very bottom:

    Code: Select all

    (Parameter.set 'Audio_Required_Format 'aiff)
    (Parameter.set 'Audio_Method 'Audio_Command)
    (Parameter.set 'Audio_Command "paplay $FILE --client-name=Festival --stream-name=Speech")

    This is for people with pulseaudio - like me.
    ALSA people can have a look here:
    :A
    If you use ALSA you need to add these lines instead:

    Code: Select all

    (Parameter.set 'Audio_Method 'Audio_Command)
    (Parameter.set 'Audio_Command "aplay -q -c 1 -t raw -f s16 -r $SR $FILE")
So I happily type

Code: Select all

echo "Hello!  Is anyone home? Did you know that bjoernvold.com rocks?" | festival --tts   

...and
:drummer
:drummer
SUCCESS!

My speakers announced the message :jackpot

PS: on some distros the file to edit might be ~/.festivalrc

The syntax is easy
echo "whatever you want to say" | festival --tts


PS on Mageia a simple

Code: Select all

sudo urpmi festival
will take care of everything for you.
Install it at you are good to go with this:

Code: Select all

echo hello $USER you are super awesome i am your processor | festival --tts 


In Centos it is even simpler:

Code: Select all

sudo yum install festival

No questions asked, and it comes with a sexy female voice :s

In Debian 8 everything works right out of the box after a:

Code: Select all

sudo apt-get install festival

It looks like my trouble shooting above is mostly for Arch based distros.
Manjaro 64bit on the main box -Intel(R) Core(TM) i7 CPU 920 @ 2.67GHz and nVidia Corporation GT200b [GeForce GTX 275] (rev a1. + Centos on the server - Arch on the laptop.
"There are no stupid questions - Only stupid answers!"

User avatar
viking60
Über-Berserk
Posts: 9351
Joined: 14 Mar 2010, 16:34

Re: Made myself a sound server today: Festival

Postby viking60 » 03 May 2015, 09:52

One word of warning,

Be careful with these pranks! I tested it and it scared the living daylights out of her. She was convinced she was hacked and pulled the plug which naturally broke off my ssh connection.
And was in general paranoid after that.

Me laughing, did not help much either so I am only alive due to my robust Berserk nature - trying to spare my fellow Berserks the same suffering.... :dance1

Podcast


It sounds much better than this on the computer but I guess I lost some quality in converting it to mp3
Manjaro 64bit on the main box -Intel(R) Core(TM) i7 CPU 920 @ 2.67GHz and nVidia Corporation GT200b [GeForce GTX 275] (rev a1. + Centos on the server - Arch on the laptop.
"There are no stupid questions - Only stupid answers!"

User avatar
viking60
Über-Berserk
Posts: 9351
Joined: 14 Mar 2010, 16:34

Re: Made myself a text to speach server today: Festival

Postby viking60 » 04 May 2015, 00:22

Not practical you say?
Well here is one example why you absolutely need this:

Since you are loaded and need to keep track of currencies worldwide you can get the currency in a terminal.
To get the daily course add this at the end of your ~/.bashrc or ~/.zshrc

Code: Select all

currency() {
curl -s "http://www.google.com/finance/converter?a=$1&from=$2&to=$3" | sed '/res/!d;s/<[^>]*>//g';
}

Reload bash with

Code: Select all

source ~/.bashrc

Now you can go to a terminal and type

Code: Select all

currency 1 usd eur

This will convert 1 usd to eur
You can convert mostly any currency from the first to the second like this. And that is great but naturally you need your computer to read the values to you too so replace the code above with this one:

Code: Select all

##Setting up currency conversion in the terminal
currency() {
curl -s "http://www.google.com/finance/converter?a=$1&from=$2&to=$3" | sed '/res/!d;s/<[^>]*>//g' | festival --tts;
curl -s "http://www.google.com/finance/converter?a=$1&from=$2&to=$3" | sed '/res/!d;s/<[^>]*>//g';
}

Type
currency 1 usd eur
And the computer will read the values to you before they are printed in the terminal. You can take any currency like currency 1 usd nok which will convert one USD to NOK or currency 1 nok eur and so on...
The currencies are updated in real time (I suspect there might be a small delay in comparison to the paid services - depending on how fast Google get the data, which I suspect is pretty fast) and based on non free services that Google do provide for us. The sources for these are mainly Reuters and EBS.
It will look like this in the terminal

Code: Select all

~/ curreny 1 eur nok
1 EUR = 8.5158 NOK

And you will hear it too.
Time to admit it: You will never be able to live without that :snooty:
Manjaro 64bit on the main box -Intel(R) Core(TM) i7 CPU 920 @ 2.67GHz and nVidia Corporation GT200b [GeForce GTX 275] (rev a1. + Centos on the server - Arch on the laptop.
"There are no stupid questions - Only stupid answers!"


Return to “Tips & Tricks”