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
}

}



Archived Comments

1. Hi sir,
Please i want to design a text to speech and speech to text plugin module for chrome

View Tutorial          By: Dammie Shewar at 2017-05-16 15:21:02

2. owoahoqexucul
View Tutorial          By: owoahoqexucul at 2017-03-26 18:16:47

3. efeyayeju
View Tutorial          By: efeyayeju at 2017-03-26 17:02:21

4. unazusa
View Tutorial          By: unazusa at 2017-03-26 16:54:07

5. upahenula
View Tutorial          By: upahenula at 2017-03-26 16:42:45

6. edogozox
View Tutorial          By: edogozox at 2017-03-26 16:41:56

7. wuwakexutu
View Tutorial          By: wuwakexutu at 2017-03-26 16:41:40

8. Sir, I am a diploma student of third year, I am doing a project on voice based email for blind, I d
View Tutorial          By: Christinajoice at 2017-01-04 10:01:37

9. Thanks for sharing, Keep up the good work
View Tutorial          By: Dinesh Krishnan at 2016-12-29 12:50:33

10. sir please send me the complete code in my mail please .... i have been allotted Text to speech conv
View Tutorial          By: Animesh at 2016-07-26 08:18:16

11. Sir, it would be greatful if u help me. I'm a student and for my major project I'm making speech to
View Tutorial          By: Harsimran at 2016-05-08 16:34:22

12. Dear, Would you give me a java code that convert text to mp3, ogg, wave audio files please.

View Tutorial          By: asma at 2016-04-16 13:35:19

13. Sir,
I am a student and I am doing a mini project that is auto subtitle generator. Will you

View Tutorial          By: Melbin Mathai at 2016-03-28 16:45:02

14. without giving jar files code how can we execute program its not working showing errors
View Tutorial          By: akhil at 2016-03-17 12:23:42

15. Hi Sir...
sir i am working on Speech to Text Conversation in one of my Projects.So if you hav

View Tutorial          By: Varalakshmi P at 2016-01-28 03:10:37

16. hello sir,
I am student working on text to speech conversion project.
please tell me

View Tutorial          By: shravani at 2016-01-18 08:01:53

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

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

18. hi sir
im a student of aitm im doing speech to text conversion project plz can u mail me th

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

19. hi sir
how can i get started if i want to do a java program to convert speech to text....pli

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

20. hello sir,
i am create project autosubtitlegenerator in video plz help me more error in my pr

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

21. hello sir , i m student of mca . i am working on Speech to Text Conversation in one of my Projects i
View Tutorial          By: Pallavi at 2013-04-06 13:53:54

22. Hello sir pls send me
com.sun.speech.freetts.and voicemanager jar package on my email id

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

23. Hi Sir...
sir i am a student and I am working on Text To Speech Conversation Project.

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

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

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

25. Hi Sir...
sir i am a student and I am working on Text To Speech Conversation Project.

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

26. Hi Sir...
sir i am working on Speech to Text Conversation in one of my Projects in core java.

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

27. I've tried this code but i am gettting error at line
getVoice("kevin16");
I

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

28. 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

29. 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

30. Hi Sir...
sir i am working on Speech to Text Conversation in one of my Projects.So if you hav

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

31. hi sr.
do u have any idea , how to convert from speech to text? if yes can u plz send the cod

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

32. please help
can u send me com.sun.speech.freetts package
so fast pleeeeeeeease

View Tutorial          By: noura at 2012-07-01 17:31:45

33. sir plz help me with source code to convert speech to text...
View Tutorial          By: amelia at 2012-05-29 06:30:50

34. sir will you please tell me how i get out of all the errors i m facing in the code by running it in
View Tutorial          By: mitali at 2012-05-06 09:54:49

35. guys , do have any idea how to convert note that usually in paper size to handphone by using java co
View Tutorial          By: sha at 2012-04-04 06:58:30

36. Hi Mirna,
U r talking abt speech to text conversion i.e. speech recognition.so just tell me w

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

37. hi sr.
do u have any idea have any idea how to convert from speech to text? if yes can u plz

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

38. Hello sir,
I am doing a project on developing an application for dictating java programs thro

View Tutorial          By: rohan at 2012-02-01 10:59:16

39. 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

40. Hello sir pls send me
com.sun.speech.freetts.jar package on my email id
& can you

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

41. Hello sir,
how to convert speech to text in java programing.
i have no guide for this

View Tutorial          By: Tejas at 2011-09-21 09:05:14

42. Hello sir pls send me
com.sun.speech.freetts.jar package on my email id
& can you

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

43. hi, how do i turn it into a gui with swing allowing users to import the text file to convert and exp
View Tutorial          By: psychicjava at 2011-02-06 13:18:08

44. http://half-wit4u.blogspot.com/2011/01/text-to-speech-using-java-api.html
View Tutorial          By: Armu at 2011-02-01 23:08:28

45. Can u show how to do text to speech with servlet. I am getting error
NoClassDefFoundError: c

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

46. This code required some packages that need to run this program i will try to run this program and op
View Tutorial          By: Suresh Kumar Thakur (m tech) at 2010-10-07 02:09:08


Most Viewed Articles (in Java )

Latest Articles (in Java)

Comment on this tutorial