Hackosis is an Open Blog. You Can Participate.

  • 24
  • Nov

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):

  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!

[Slashdot] [Digg] [Reddit] [del.icio.us] [Facebook] [Technorati] [Google] [StumbleUpon]

Related Posts


Tags: , , , , ,

Like this post? Subscibe to the RSS feed.


32 Comments

  1. Teach Linux to talk « 0ddn1x: tricks with *nix Says:

    [...] Teach Linux to talk Filed under: Linux — 0ddn1x @ 2007-11-25 16:18:42 +0000 http://www.hackosis.com/index.php/2007/11/24/transform-linux-into-a-talking-companion/ [...]

  2. femtolicious » links for 2007-11-26 Says:

    [...] Transform Linux into a Talking Companion (tags: linux free-software howto) [...]

  3. egron Says:

    and if you install http://cmusphinx.sourceforge.net/html/cmusphinx.php
    it might understand you too :), have not tried it though.

  4. Shane Says:

    Thanx for the heads up egron. I will definetely check it out. ;)

  5. spedoinkle Says:

    aaaaahhhhhhh, i took your advice and made myself a readit.desktop, but now how do i get it to shut the hell up!!! i closed festival using the system monitor but it just keeps talking!!

  6. links for 2007-11-27 | Funny Stuff is all around Says:

    [...] Transform Linux into a Talking Companion | Hackosis (tags: linux interesting howto toread free-software text-to-speech) [...]

  7. Alp Says:

    I get an error when executing this:
    echo “My talking Linux PC efin rocks” | festival –tts
    Linux: can’t open /dev/dsp

    Any ideas?

  8. Shane Says:

    Sorry, this is not a technical support blog. Please understand.

    Look here for more tips:
    http://ubuntuforums.org/showthread.php?t=171182

  9. Shane Says:

    I was trying to figure out how to disable reading of special characters..haven’t come up with anything yet. Let me know if you have any tips.

  10. fachex Says:

    To spedoinkle
    $ pkill readit.desktop

    It happened the same thing to me hahah. It was funny

  11. Open Source Depot Says:

    Do you know of any ubuntu/linux or even free/open source windows software to do the opposite. i.e. You talk into the microphone and text comes out the other end?

  12. Shane Says:

    Like egron stated above, Sphinx will for Linux, not sure of the complexity level, I have not tried it out yet.

    http://cmusphinx.sourceforge.net/html/cmusphinx.php

  13. ps Says:

    Shane:
    about the disabling of special characters, you can always run the input through sumthing like “sed” before sending it to festival like
    $ cat file|sed ’s/[^a-zA-Z .,!?]//g’|festival -tts
    would remove everything except a-z,A-Z, space, “,”,”.”,”!”,”?”.

    cheers ps

  14. Cheater Says:

    @Alp,
    You forgot a second “-”. The command would be:
    echo “My talking Linux PC efin rocks” | festival –tts

  15. Shane Says:

    @Cheater, as you can see the HTML automatically renders “- -” (without the space) as –
    @ps, That acually produces some really weird results, it acually says all of the spaces and dots. I will look into sed, I didn’t know about that. Thanks for the tip.

  16. Moran Atias Says:

    Hi…Thanks for the nice read, keep up the interesting posts about charles moran..what a nice Friday .

  17. heywood Says:

    No, no, no. What you do is install this on a machine in the middle of the office, then ssh into it and freak everybody out.

  18. Chris Says:

    This is awesome, thanks for the ideas. :) I’ve got some ideas to try out tomorrow. With festival and PulseAudio, I’m going to broadcast important announcements from my router to the rest of my network. mdadm alerts, internet connection going down, reboots, whatever. It’s hard to miss an alert when the TV, the laptop, and the office computer all say “/dev/md0 is running in a degraded state!”

  19. Timmy Says:

    Well, it seems text-to-speech hasn’t got any better sounding since my BBC micro in 1984.

  20. Software-based matrix switcher? Says:

    [...] Festival (text-to-speech engine) [...]

  21. umut Says:

    yeah, isn’t there any other nice voices out there? i am kinda bored with this guy…

  22. Eric Says:

    Thanks for the post. I took your idea about the cron saying what time it is and also added a feature to say what the outside temperature is. Yeah I know that’s useless! All the details on my blog.
    http://eric.legallais.ca/blog/?p=48

  23. Shane Says:

    doesn’t sound useless to me, nice work Eric. ;)

  24. Life: Hack Yourself | Hackosis Says:

    [...] have prepared the document in Mp3 audio format via festival — download it [...]

  25. Linux: Easily Convert Text To Wav With Festival | Hackosis Says:

    [...] you haven’t already, check out the Transform Linux into a Talking Companion post to learn how to install and use [...]

  26. jasmine Says:

    thanks for sharing it
    you will also get in mine just search
    jasmine
    tech-chek.blogspot.com

  27. navaburo Says:

    @Alp,
    To avoid the /dev/dsp issue (and infact, to use this system at all while music is playing), add the following to your ~/.festivalrc file:

    ;make festival use ALSA output:
    (Parameter.set ‘Audio_Method ‘Audio_Command)
    (Parameter.set ‘Audio_Command “aplay -q -c 1 -t raw -f s16 -r $SR $FILE”)

    Thanks to the guys at the Gentoo doc wiki:
    http://gentoo-wiki.com/HOWTO_speechd

  28. Shane Says:

    Hey Navaburo.

    Thanks for the tip and welcome to Hackosis.

  29. contrast Says:

    Nice tip. I had played with this briefly a while back. I think I’m ready to actually start putting it to use. I normally do something like “sleep 10m && mplayer -loop 0 /usr/share/sounds/KDE_Event_2.ogg” to remind myself the pizza will be done in 10 minutes. I look forward to seeing the reaction from my friends when, instead of a friendly little chime, they here, “The pizza is ready” in a monotone voice.

  30. Chris Says:

    @contrast

    If you order your pizza from Dominos, you could get real time status updates as it is being made, like in this python script.

  31. Shane Says:

    Chris. Thanks for the heads up! Neat script.

  32. Track Your Dominos Pizza With A Python Script | Hackosis Says:

    [...] to Chris for the heads up! And pizza thumbnail via jetalone. Tags: Linux, Monitoring, Pizza, [...]

Leave a Comment