Robot KaraokeWho says people get to have all the fun? With
this hack, you can let your computer do a little singing, by scraping
the LyricsFreak.com web site and sending the results to a
text-to-speech translatorThe Code[Discuss (1) | Link to this hack]

There are things that are text-only and
things that are multimedia. Then there's this hack,
which turns boring old text into multimedia—specifically, a
.wav file.

This hack, as it stands, is actually pretty silly. It searches the
lyric collections at
LyricsFreak.com
for the keywords you specify, then sends the matching lyrics to yet
another site (http://naturalvoices.com)
that turns them into a .wav file. If
you're running a Win32 system, the code will then
automatically play the .wav file
("sing" the lyrics, for some narrow
definition of sing) via the
Win32::Sound module (http://search.cpan.org/author/ACALPINI/Win32-Sound/).

WARNING

Listening to your computer's rendition of the
Spider-Man theme song can be detrimental to
your health.

As you're playing with this code, you might want to
think of more sublime and less ridiculous implementations. Do you
have a site read by low-vision people? Are
there short bits of text, such as a local weather forecast, that
would be useful for them to have read aloud? Would it be helpful to
have a button that would convert a story summary to a
.wav file for later download?

Running the Hack

Invoke the script on the command line, passing it the phrase
you're interested in; the script will search for
that phrase in the titles of pages on LyrisFreak.com. If it
doesn't find the phase, it'll just
stop:

% perl robotkaroake.pl "fish heads"
No LyricsFreak matches were found for 'fish heads'.

If it does find the phrase, it'll download the
lyrics and generate the .wav file:

The previous example shows the output of a rather short entry. Longer
songs will result in more .wav files saved to
the current directory, each representing a small chunk (a single
chunk representing one request to the TTS server):

The Code

One of the modules used with this code,
Win32::Sound, is for Win32 machines only. Since
it's used to play back the generated
.wav file, you will not get a
"singing" robot if
you're on a non-Win32 machine;
you'll just get a .wav file,
suitable for playing through your preferred music player.