This article will show 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 voice. Freetts Library can be downloaded in freetts.sourceforge.net. In order to connect to the IRC server, you need to download the Pircbot Java IRC API in www.jibble.org/pircbot.php. Once you have downloaded the required two libraries, create a Lib directory and copy the following. jar files into it. Cmu_time_awb.jar
Cmu_us_kal.jar
Cmulex.jar
Cmutimelex.jar
En_us.jar
Freetts.jar
Pircbot.jar Now, writing IRC bots has become a simple task because these libraries will do most of the hard work for you. To 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 voice for 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. assigning Resources
Setting the 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 ();
Synthesized voice files can be obtained here
Freeing 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 the 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");
}}