Text to Speech conversion program in Java

By: Sulfikkar Emailed: 1728 times Printed: 2329 times    

Latest comments
By: rohit kumar - how this program is work
By: Kirti - Hi..thx for the hadoop in
By: Spijker - I have altered the code a
By: ali mohammed - why we use the java in ne
By: ali mohammed - why we use the java in ne
By: mizhelle - when I exported the data
By: raul - no output as well, i'm ge
By: Rajesh - thanx very much...
By: Suindu De - Suppose we are executing

This is a sample java program that explains how to use text to speech conversion.
You can use this program as follows
c:\> javac Speech.java
c:\> java Speech Hello Manikandan

package com.scima;
import com.sun.speech.freetts.FreeTTS;
import com.sun.speech.freetts.Voice;
import com.sun.speech.freetts.VoiceManager;
import com.sun.speech.freetts.audio.SingleFileAudioPlayer;
import java.io.FileInputStream;


/

@author vijay
/
public class Main {

/*
@param args the command line arguments
/
void call(String msg){
System.out.println("U r here");
Voice voice;
FreeTTS freetts;
System.out.println("---------************");
VoiceManager vm=VoiceManager.getInstance();
System.out.println("--------------////");
voice=vm.getVoice("kevin16");
System.setProperty("com.sun.speech.freetts.voice.defaultAudioPlayer", "com.sun.speech.freetts.audio.SingleFileAudioPlayer");
FileInputStream fis ;
SingleFileAudioPlayer sfap;
if(voice==null)
System.out.println("voice is null");
System.out.println("---0---");
if(voice!=null)
{
voice.allocate();
}
System.out.println("---1---");
freetts=new FreeTTS(voice);
String text = new String(msg);
byte b[] = text.getBytes();
if(b==null)
{
System.out.println("no byte array");
System.exit(1);
}
try
{
sfap = (SingleFileAudioPlayer)voice.getDefaultAudioPlayer();
sfap.write(b);


}
catch(Exception e)
{

}
voice.speak(msg);
voice.deallocate();

System.out.println("---------?????-----------");
try {
System.out.println("inside copy try block");
String command="copy \"C:\\Program Files\\Apache Software Foundation\\Apache Tomcat 6.0.18\\bin\\freetts.wav\" \"C:\\Program Files\\Apache Software Foundation\\Apache Tomcat 6.0.18\\webapps\"";
System.out.println("copying file from "+command);
Runtime.getRuntime().exec("cmd.exe /c"+command);
System.out.println("file copied");
} catch (Exception e) {
e.printStackTrace();
}

// freetts.setStreamingAudio(true);
// freetts.urlToSpeech("http://10.0.0.109:8084/");
System.out.println("---2---");
// freetts.setAudioFile("c:\\test.wav");
// freetts.shutdown();
System.out.println("calling wav file");
//AePlayWave aw=new AePlayWave("C:/Program Files/Apache Software Foundation/Apache Tomcat 6.0.18/bin/freetts.wav");


System.out.println("---last---");

}
Main(){

}
// static Voice voice;
// static FreeTTS freetts;
// static
// {
// voice=VoiceManager.getInstance().getVoice("kevin16");
// if(voice!=null)
// {
// voice.allocate();
// }
// freetts=new FreeTTS(voice);
// voice.speak("hello,world");
//
// freetts.startup();
// freetts.urlToSpeech("http://10.0.0.109:8080/");
// freetts.setAudioFile("c:/test.wav");
// freetts.shutdown();
// }
Main(String str){

System.out.println("Inside main");
//freetts.setAudioFile("c:/test.wav");
}
public static void main(String[] args)throws Exception {
// TODO code application logic here
}

}

Java Home | All Java Tutorials | Latest Java Tutorials

Sponsored Links

If this tutorial doesn't answer your question, or you have a specific question, just ask an expert here. Post your question to get a direct answer.



Bookmark and Share

Comments(23)


1. View Comment

Can u show how to do text to speech with servlet. I am getting error
NoClassDefFoundError: com/sun/speech/freetts/VoiceManager
I am using eclipse tomcat6


View Tutorial          By: Rotika at 2011-01-23 20:54:40
2. View Comment

hi, how do i turn it into a gui with swing allowing users to import the text file to convert and exportibg the converted file to a directory. Thank you

View Tutorial          By: psychicjava at 2011-02-06 13:18:08
3. View Comment

Hello sir pls send me
com.sun.speech.freetts.jar package on my email id
& can you any idea for speech to text conversion pls tell me
i m waiting you answerer


View Tutorial          By: nikunj at 2011-08-19 06:55:37
4. View Comment

Hello sir pls send me
com.sun.speech.freetts.jar package on my email id
& can you any idea for speech to text conversion pls tell me
i m waiting you answerer
sanasmiles123@gmail


View Tutorial          By: sana at 2011-12-23 16:16:24
5. View Comment

Sir, plz tell me how can I run the speech class in java? And where is the speech class founded?

View Tutorial          By: Nitin Govil at 2012-01-21 10:14:52
6. View Comment

hi sr.
do u have any idea have any idea how to convert from speech to text? if yes can u plz send it to me on my mail.
thx lot
waiting your answer


View Tutorial          By: mirna at 2012-03-27 05:47:34
7. View Comment

Hi Mirna,
U r talking abt speech to text conversion i.e. speech recognition.so just tell me what problem are u facing in it.I w'll surely help u as i hv worked on it as my minor project in B.Tech.


View Tutorial          By: akshat at 2012-04-02 14:38:31
8. View Comment

sir will you please tell me how i get out of all the errors i m facing in the code by running it in jcreater na is there any use of applet in this..?

View Tutorial          By: mitali at 2012-05-06 09:54:49
9. View Comment

hi sr.
do u have any idea , how to convert from speech to text? if yes can u plz send the code in j2me it to me on my mail.
thx lot
waiting your answer


View Tutorial          By: gohila at 2012-08-15 14:31:31
10. View Comment

Hi Sir...
sir i am working on Speech to Text Conversation in one of my Projects.So if you have some code plz send me to my id..
sadaquat_ruk@live.com . I would really appreciate if you do this favour.
thanx in advance SID :-)


View Tutorial          By: Sadaquat at 2012-08-19 07:51:28
11. View Comment

how do i use the jsapi classes and the freets packages i want to use them for my voice tutor ptoject

View Tutorial          By: Chileshe at 2012-08-22 14:23:38
12. View Comment

Pl send some sample program for speech to text with codes ,im struggling here.

View Tutorial          By: gokul at 2012-09-27 10:28:19
13. View Comment

I've tried this code but i am gettting error at line
getVoice("kevin16");
If anyone can help please!


View Tutorial          By: Iqra at 2012-12-13 10:43:12
14. View Comment

Hi Sir...
sir i am working on Speech to Text Conversation in one of my Projects in core java.So if you have some code plz send me to my id.. pilli.gopi001@gmail.com.
I would really appreciate if you do this.
thanks a lot


View Tutorial          By: p gopi at 2013-02-11 09:27:07
15. View Comment

Hi Sir...
sir i am a student and I am working on Text To Speech Conversation Project.
So if you can help me then plz I want to have its code plz send me to my id..
sanzu_dream123@yahoo.com ... I would really be grateful to you if you do this favour.
thank you...


View Tutorial          By: Sanzu at 2013-02-12 09:13:01
16. View Comment

Hi sir,
please send some sample code for speech to text like hello that output should be in voice


View Tutorial          By: hindu at 2013-03-21 06:00:09
17. View Comment

Hi Sir...
sir i am a student and I am working on Text To Speech Conversation Project.
So if you can help me then plz I want to have its code plz send me to my id..
shanthu45@gmail.com ... I would really be grateful to you if you do this favour.
thank you...


View Tutorial          By: shanthi at 2013-03-22 11:01:15
18. View Comment

Hello sir pls send me
com.sun.speech.freetts.and voicemanager jar package on my email id
& can you any idea for speech to text conversion pls tell me
i m waiting you answerer
shanthu45@gmail.com


View Tutorial          By: shanthi at 2013-03-22 11:18:56
19. View Comment

hello sir , i m student of mca . i am working on Speech to Text Conversation in one of my Projects in java So if you can help me then plz I want to have its code plz send me to my id..
sir i need your help plz help me


View Tutorial          By: Pallavi at 2013-04-06 13:53:54
20. View Comment

hello sir,
i am create project autosubtitlegenerator in video plz help me more error in my project ,,,,so how can make it that ??


View Tutorial          By: Dilip Gauswami at 2013-12-01 06:46:34
21. View Comment

hi sir
how can i get started if i want to do a java program to convert speech to text....pliz help me, my email is simiyujohn9@gmail.com
thnx alot.


View Tutorial          By: simiyu at 2014-03-15 09:13:04
22. View Comment

hi sir
im a student of aitm im doing speech to text conversion project plz can u mail me the code on email sinan.siddique@yahoo.com


View Tutorial          By: sinan ahmed at 2015-02-09 05:45:49
23. View Comment

Hi sir,
please send some sample code for speech to text like hello that output should be in voice


View Tutorial          By: Kruttika at 2015-07-07 05:14:14

Your name (required):


Your email(required, will not be shown to the public):


Your sites URL (optional):


Your comments:



More Tutorials by Sulfikkar
Text to Speech conversion program in Java

More Tutorials in Java
Update contents of a file within a jar file
Tomcat and httpd configured in port 8080 and 80
Java File
Java String
Count number of vowels, consonants and digits in a String in Java
Reverse a number in Java
Student marks calculation program in Java
Handling Fractions in Java
Calculate gross salary in Java
Calculate average sale of the week in Java
Vector in Java - Sample Program
MultiLevel Inheritance sample in Java
Multiple Inheritance sample in Java
Java program using Method Overriding
Java program to check if user input is an even number

More Latest News
Most Viewed Articles (in Java )
Method Overloading (function overloading) in Java
XML and Java - Parsing XML using Java Tutorial
How to Send SMS using Java Program (full code sample included)
Method Overriding in Java
FileReader and FileWriter example program in Java
Vector example in Java
What is Java?
Stack example in Java - push(), pop(), empty(), search()
Read from a COM port using Java program
The Basic Structure of a Simple Java program
arraycopy example in Java
append() in Java
Student marks calculation program in Java
for loop in java
Calendar - sample program in Java
Most Emailed Articles (in Java)
Applet Notinited : Applet xxxxxxxxxxxx notinited
Basics of Exception Handling in Java
Tomcat and httpd configured in port 8080 and 80
Calculate average sale of the week in Java
Vector in Java - Sample Program
LinkedList in Java
Taking the size of an Array at runtime & generate random numbers to populate the Array
Getting Started with Java
Configuring a DataSource in Tomcat
What is JasperReports?
java.lang.reflect package
instanceof operator example in Java
The Unary Operators example in Java
Operator Precedence in Java
toRadians() and toDegrees() Sample program in Java