Text to Speech conversion program in Java
By: Sulfikkar
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
}
}
Comment on this tutorial
- Data Science
- Android
- AJAX
- ASP.net
- C
- C++
- C#
- Cocoa
- Cloud Computing
- HTML5
- Java
- Javascript
- JSF
- JSP
- J2ME
- Java Beans
- EJB
- JDBC
- Linux
- Mac OS X
- iPhone
- MySQL
- Office 365
- Perl
- PHP
- Python
- Ruby
- VB.net
- Hibernate
- Struts
- SAP
- Trends
- Tech Reviews
- WebServices
- XML
- Certification
- Interview
categories
Subscribe to Tutorials
Related Tutorials
Program using concept of byte long short and int in java
Update contents of a file within a jar file
Tomcat and httpd configured in port 8080 and 80
Count number of vowels, consonants and digits in a String in Java
Student marks calculation program 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
Archived Comments
1. This code required some packages that need to run
View Tutorial By: Suresh Kumar Thakur (m tech) at 2010-10-07 02:09:08
2. Can u show how to do text to speech with servlet.
View Tutorial By: Rotika at 2011-01-23 20:54:40
3. http://half-wit4u.blogspot.com/2011/01/text-to-spe
View Tutorial By: Armu at 2011-02-01 23:08:28
4. hi, how do i turn it into a gui with swing allowin
View Tutorial By: psychicjava at 2011-02-06 13:18:08
5. Hello sir pls send me
com.sun.speech.freet
View Tutorial By: nikunj at 2011-08-19 06:55:37
6. Hello sir,
how to convert speech to text i
View Tutorial By: Tejas at 2011-09-21 09:05:14
7. Hello sir pls send me
com.sun.speech.freett
View Tutorial By: sana at 2011-12-23 16:16:24
8. Sir, plz tell me how can I run the speech class in
View Tutorial By: Nitin Govil at 2012-01-21 10:14:52
9. Hello sir,
I am doing a project on developi
View Tutorial By: rohan at 2012-02-01 10:59:16
10. hi sr.
do u have any idea have any idea how
View Tutorial By: mirna at 2012-03-27 05:47:34
11. Hi Mirna,
U r talking abt speech to text co
View Tutorial By: akshat at 2012-04-02 14:38:31
12. guys , do have any idea how to convert note that u
View Tutorial By: sha at 2012-04-04 06:58:30
13. sir will you please tell me how i get out of all t
View Tutorial By: mitali at 2012-05-06 09:54:49
14. sir plz help me with source code to convert speech
View Tutorial By: amelia at 2012-05-29 06:30:50
15. please help
can u send me com.sun.speech.fr
View Tutorial By: noura at 2012-07-01 17:31:45
16. hi sr.
do u have any idea , how to convert
View Tutorial By: gohila at 2012-08-15 14:31:31
17. Hi Sir...
sir i am working on Speech to Tex
View Tutorial By: Sadaquat at 2012-08-19 07:51:28
18. how do i use the jsapi classes and the freets pack
View Tutorial By: Chileshe at 2012-08-22 14:23:38
19. Pl send some sample program for speech to text wit
View Tutorial By: gokul at 2012-09-27 10:28:19
20. I've tried this code but i am gettting error at li
View Tutorial By: Iqra at 2012-12-13 10:43:12
21. Hi Sir...
sir i am working on Speech to Tex
View Tutorial By: p gopi at 2013-02-11 09:27:07
22. Hi Sir...
sir i am a student and I am work
View Tutorial By: Sanzu at 2013-02-12 09:13:01
23. Hi sir,
please send some sample code for sp
View Tutorial By: hindu at 2013-03-21 06:00:09
24. Hi Sir...
sir i am a student and I am worki
View Tutorial By: shanthi at 2013-03-22 11:01:15
25. Hello sir pls send me
com.sun.speech.freett
View Tutorial By: shanthi at 2013-03-22 11:18:56
26. hello sir , i m student of mca . i am working on S
View Tutorial By: Pallavi at 2013-04-06 13:53:54
27. hello sir,
i am create project autosubtitle
View Tutorial By: Dilip Gauswami at 2013-12-01 06:46:34
28. hi sir
how can i get started if i want to
View Tutorial By: simiyu at 2014-03-15 09:13:04
29. hi sir
im a student of aitm im doing speec
View Tutorial By: sinan ahmed at 2015-02-09 05:45:49
30. Hi sir,
please send some sample code for sp
View Tutorial By: Kruttika at 2015-07-07 05:14:14
31. hello sir,
I am student working on text to
View Tutorial By: shravani at 2016-01-18 08:01:53
32. Hi Sir...
sir i am working on Speech to Tex
View Tutorial By: Varalakshmi P at 2016-01-28 03:10:37
33. without giving jar files code how can we execute p
View Tutorial By: akhil at 2016-03-17 12:23:42
34. Sir,
I am a student and I am doing a mini
View Tutorial By: Melbin Mathai at 2016-03-28 16:45:02
35. Dear, Would you give me a java code that convert t
View Tutorial By: asma at 2016-04-16 13:35:19
36. Sir, it would be greatful if u help me. I'm a stud
View Tutorial By: Harsimran at 2016-05-08 16:34:22
37. sir please send me the complete code in my mail pl
View Tutorial By: Animesh at 2016-07-26 08:18:16
38. Thanks for sharing, Keep up the good work
View Tutorial By: Dinesh Krishnan at 2016-12-29 12:50:33
39. Sir, I am a diploma student of third year, I am do
View Tutorial By: Christinajoice at 2017-01-04 10:01:37
40. wuwakexutu
View Tutorial By: wuwakexutu at 2017-03-26 16:41:40
41. edogozox
View Tutorial By: edogozox at 2017-03-26 16:41:56
42. upahenula
View Tutorial By: upahenula at 2017-03-26 16:42:45
43. unazusa
View Tutorial By: unazusa at 2017-03-26 16:54:07
44. efeyayeju
View Tutorial By: efeyayeju at 2017-03-26 17:02:21
45. owoahoqexucul
View Tutorial By: owoahoqexucul at 2017-03-26 18:16:47
46. Hi sir,
Please i want to design a text to s
View Tutorial By: Dammie Shewar at 2017-05-16 15:21:02