Friday, March 09, 2007

Festival: Making Your Scripts Speak

I was just reading through some old issues of SysAdmin magazine, of which I am a subscriber, and I came accross a cool article entitled: "Making Your Monitoring Speak." The basic premise of this article is that this guy wrote a python script that had his servers make a phone call to his cell, and actually speak the problem to him. His script uses the festival text to speech converter, which is available for linux and OS X (it comes standard on Ubuntu . . . awesomely enough). If you have a mac, don't bother, the mac "say" program is vastly superior to festival, so just use that instead. I've been playing around with this . . . (notably because having your computer say dirty things to you is just one of those things that doesn't get old . . . ever . . . i'm seriously) . . . only with BASH and not python:


#!/bin/bash
########################################
## talktome.sh
##
## An example script using festival
########################################
SPEECH="Good morning Dave."

## on linux
echo $"SPEECH" | festival --tts

## on mac
#say $"SPEECH"

exit 0


The reason we use echo/pipe with festival, is that when festival is run with the --tts (text-to-speech) option, it can only take a text file or STDIN as it's input, whereas say takes a string as it's argument. If you want to make an audio file you can use texttowave utility that comes with festival . . . which will convert from text to wave, and then just use LAME or your favorite audio encoder to re-encode the audio if you so desire.

Enjoy!

No comments: