Saturday, December 29, 2007

Transform Linux into a Talking Companion

TTSText-to-speech is really convenient, especially when you are lazy like me. Festival enables us to achieve a TTS system with limitless possibilities thanks to our Linux bash shell. I will show you some ways that we can use Festival as an enabler to our laziness and also produce some really cool and useful effects when coupling this technology with common things like PHP, cron, dnotify, or login scripts.


Remember the movie 2001: A Space Odyssey? I’d like to think that I am Dave, I just hope that my PC doesn’t turn on me (Although, I think it has in the past).


Credit were credit is due - some ideas from xenocafe.com and linuxgazette.net.


image via link

 


Installation


You need to install Festival. su root if need be.


Ubuntu:


sudo apt-get install festival festvox-kallpc16k

festvox-kallpc16k is the male american voice. Ubuntu doesn’t install a voice unless you specify which will cause the program to crash. Look in synaptic for other voices and language support.


Fedora - CentOS - Redhat:


yum install festival

openSUSE:


yast -i festival


The Basics


Now that we have Festival installed, lets start with the basics.


Make Festival say something:


echo “My talking Linux PC efin rocks” | festival --tts

Make Festival read a text file:


cat -A file.txt | festival --tts

Make Festival say the time:


date ‘+%I, %M %p’ | festival --tts



Festival and PHP Programming


Combining the Power of PHP and Festival we can do some cool things. You need to have a PHP CLI installed.


Make Festival say a random quote:


Contents of rquote.php (minus the PHP tags):




$quotes[] = 'Nothing is faster than the speed of light...To prove this to yourself, try opening the refrigerator door before the light comes on.';
$quotes[] = 'The FBI is watching YOU.';
$quotes[] = 'Vote anarchist.';

srand ((double) microtime() * 1000000);
$random_number = rand(0,count($quotes)-1);

echo ($quotes[$random_number]);







  1. $quotes[] = ‘Nothing is faster than the speed of light…To prove this to yourself, try opening the refrigerator door before the light comes on.’;



  2. $quotes[] = ‘The FBI is watching YOU.’;



  3. $quotes[] = ‘Vote anarchist.’;



  4.  



  5. srand ((double) microtime() * 1000000);



  6. $random_number = rand(0,count($quotes)-1);



  7.  



  8. echo ($quotes[$random_number]);





php rquote.php | festival --tts


Back to the Real World


You might be thinking,”Well that is great and dandy, I can make my PC talk. Woopty friggin doo.”.


We can do any number of other things that could be useful with desktop shortcuts, cron, dnotify, reading man pages, and more.


Create a desktop shortcut. You can then drag files on top of it to have Festival read the file (Yah! No more command line):


Create a file with the following contents named readit.desktop:


[Desktop Entry]
Encoding=UTF-8
Version=1.0
Type=Application
Terminal=false
Name[en_US]=festival
Exec=festival --tts
Name=festival

Remind yourself of the time on the hour with cron:


crontab -e

Enter the following into the file:


0 * * * * username ~/time.sh

Contents of time.sh:


#!/bin/bash
date '+%I, %M %p' | festival --tts

Make it executable chmod u+x ~/time.sh.


Make Festival talk when a file has been accessed or changed using dnotify (HINT: You might have to install dnotify):


dnotify -CD /home/shane/Desktop -e echo "A file has changed on the desktop" | festival --tts

Make Festival read man pages to you:


Lets face it, no one likes to read man pages:


man lsof | festival --tts

The possibilities are endless


I hope you see all the possible things that you can have your computer talking to you about. I am acually going to have Festival (It would have been cool if they would have named it HAL 9000) read this article to me to check for grammar and spelling. The voice isn’t the greatest, it just takes a little getting used to. Check your repos for more voices. Let me know if you come up with something interesting in the comments and I will add it to the list. Now you should feel a little bit more like Dave Bowman!

0 comments: