This article will show you how to build a cross-platform IRC robot (an automated client) that uses the Freetts Java Speech Synthesis Library to convert IRC messages into audible speech. The Freetts library can be downloaded at freetts.sourceforge.net. To connect to an IRC server, you need to download the Pircbot Java IRC API in www.jibble.org/pircbot.php. Once you have downloaded the two libraries you need, create a Lib directory, and then copy the following. jar files to the inside. Cmu_time_awb.jar
Cmu_us_kal.jar
Cmulex.jar
Cmutimelex.jar
En_us.jar
Freetts.jar
Pircbot.jar Now, writing IRC robots has become a simple task, because these libraries will do most of the difficult work for you. Create a file named Speechbot.java:
Import org.jibble.pircbot.*;
Import com.sun.speech.freetts.*;
Import com.sun.speech.freetts.audio.*;
Import javax.sound.sampled.*;
Import Java.io.File;
public class Speechbot {
Private Voice Voice;
Public Speechbot (String say) {
SetName (name); Choose The voice for the speech synthesizer.
Select the voice of the speech synthesizer
String voicename = "Kevin16";
Voicemanager Voicemanager = Voicemanager.getinstance ();
Voice = Voicemanager.getvoice (Voicename);
if (voice = = null) {
System.out.println ("Voice not Found.");
System.exit (1);
}
Voice.allocate (); Set up the output format. Allocating resources
Set output format
Audioplayer Voiceplayer = new Javaclipaudioplayer ();
Voiceplayer.setaudioformat (New Audioformat (8000, 1, false, true));
Voice.setaudioplayer (Voiceplayer);
float WPM = 120f;//set speed
Voice.setrate (WPM);
Voice.setpitch (85f);
Voice.setpitchrange (10f);
Synthetic speech
Voice.startbatch ();
Voice.speak (say);
Voice.endbatch ();
You can get a synthetic voice file here
Releasing resources
Voice.deallocate ();
}
public void OnMessage (string channel, String sender,
string login, string hostname, string message {
Send all IRC messages to the voice
Synthesizer.
Send all IRC messages to speech synthesizer
message = Message.trim ();
String input = sender + "On" + Channel + "
Says: "+ message;
Voice.speak (input);
}
public static void Main (string[] args) throws Exception {
Speechbot bot = new Speechbot ("Speechbot");
}}