Freetts to enable speech synthesis-----convert IRC messages into audible voice

Source: Internet
Author: User

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");
 
}}

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.