skip to main | skip to sidebar

Java Programs and Examples with Output

Pages

▼
 
  • RSS
  • Twitter
Thursday, October 18, 2012

Text to Speech in java

Posted by Raju Gupta at 10:00 PM – 0 comments
 
This java application converts given text(It can be number of lines) to speech. Need to import freetts.jar.

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import com.sun.speech.freetts.Voice; 
import com.sun.speech.freetts.VoiceManager; 

public class Demofreetts {
 // Default voice is Kevin16
 private static final String VOICENAME = "kevin16";

 public static void main(String[] args) {
  Voice voice;
  // Taking instance of voice from VoiceManager factory.
  VoiceManager voiceManager = VoiceManager.getInstance();
  voice = voiceManager.getVoice(VOICENAME);
  // Allocating voice
  voice.allocate();
  // word per minute
  voice.setRate(120);
  voice.setPitch(100);
  System.out.print("Enter your text: ");
  // open up standard input
  BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
  try {
   // Ready to speak
   voice.speak(br.readLine());
  } catch (IOException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  }
 }
}


Labels: Java Voice Example

Leave a Reply

Newer Post Older Post
Subscribe to: Post Comments ( Atom )
  • Popular
  • Recent
  • Archives
Powered by Blogger.
 
 
 
© 2011 Java Programs and Examples with Output | Designs by Web2feel & Fab Themes

Bloggerized by DheTemplate.com - Main Blogger