A P2P AIM Robot in Perl | 5 | WebReference

A P2P AIM Robot in Perl | 5

A P2P AIM Robot in Perl

The Speech Synthesis Plugin

Festival

Festival is a speech synthesis application developed at the The Centre for Speech Technology Research (CSTR) at the University of Endinburgh. More information on acquiring the source code is available at https://www.cstr.ed.ac.uk/projects/festival/. I'll warn you now that installing Festival is a bit tricky if you're not familiar with compiling complex applications yourself, so you may want to get some help. Once it's installed though, you'll quickly realize that it's a mature and powerful speech synthesis system.

Though we won't be using it in this example, I would like to also mention that there is a Perl library for connecting to a Festival server available on CPAN called Festival::Client.

Writing a Perl plugin for Gaim

The previous examples all utilized the Net::AIM module for connecting to the AIM network. Those examples did not require Gaim, but this one does. That's because we're going to write a Perl plugin for the Gaim client. I though it would be neat to get voice synthesized output from the Gaim client. Having used Festival in the past, it seemed like a no brainer. I used the example Perl script that came with the Gaim distribution initially to figure out how to write a Perl plugin.

While you can run Perl code in a plugin, I did have problems loading modules, so what I did was use a Perl system call to pass the text from incoming AIM messages to Festival.

AIM::register("Festival TTS", "0.0.1", "goodbye", "");
AIM::print("Perl Says", "Loaded Festival TTS");
AIM::command("idle", "60000") if ($pro ne "Offline");
AIM::add_event_handler("event_im_recv", "synthesize");
sub goodbye {
	AIM::print("You Dog!", "Unloaded Festival TTS");
}
sub synthesize {
    my $string = $_[0];
    $string =~ s/\<.*?\>//g;
    $string =~ s/\".*\"//;    
    system("echo \"$string\" | /usr/bin/festival --tts");
}

There's not too much documentation on how to do it, but once you figure it out, it's pretty easy. Like Net::AIM, you register the event you want to catch and specify the function to call. This is set with the AIM::add_event_handler function, the first argument being the name of the event and the second argument being the name of the Perl subroutine to call. I was able to get a list of events by looking at events.c in the plugins/ directory that's distributed with the Gaim source code.

Loading the plugin in Gaim

Loading Perl plugins in Gaim is easy. Select the Tools->Perl->Load Script menu item and type in the path to the Perl script above that you've hopefully by now saved to a file. You should see a popup box that tells you the plugin has been loaded. The next time you get a message, you should hear the output on your speakers if you have Festival setup properly.

Conclusion

I really had a lot of fun tinkering with Gaim plugins and the Net::AIM module. I hope you find the scripts useful too. If you run into problems, let me know and I'll try to help. I'd also love to hear about how you've adopted the examples in this tutorial to do cool things on AIM. Again, if you want to download the three examples, here they are: aim_message.pl, aim_eliza.pl, aim_fest_plugin.pl


https://www.internet.com

Produced by Jonathan Eisenzopf
All Rights Reserved. Legal Notices.
Created: September 28, 2000
Revised: September 28, 2000

URL: https://www.webreference.com/perl/tutorial/13/5.html