JAVA: HOW TO CONVERT TEXT TO SPEECH USING FreeTTS API - 3 SIMPLE STEPS
PREREQUISITE:
1) ECLIPSE IDE
2) FreeTTS API - CLICK HERE TO DOWNLOAD
3) SWING.JAR - CLICK HERE TO DOWNLOAD
STEP 1:
Download the FreeTTS API. CLICK here to download FreeTTS API. Unzip the downloaded file. Now copy the 'lib' folder present in 'freetts-1.2' to your project
STEP 2:
Download the swing.jar file. Click here to download swing.jar. Now add the swing.jar file in the 'lib' folder of java. Simply right click 'JRE System Library', then click 'Add JAR's' and then find the 'swing.jar' file. Click OK.
STEP 3:
Now write the code. To download Source Code Click here
SOURCE CODE:
package pa;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JFrame;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import com.sun.speech.freetts.Voice;
import com.sun.speech.freetts.VoiceManager;
public class texttospeech extends JFrame
{
/**
*
*/
private static final long serialVersionUID = 1L;
public JTextField txtenter=new JTextField();
public JTextArea txtchat=new JTextArea();
public void texttospeech1()
{
this.setVisible(true);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setSize(600,600);
this.add(txtenter);
this.add(txtchat);
this.setResizable(false);
this.setLayout(null);
this.setTitle("TEXT TO SPEECH");
txtenter.setLocation(2,540);
txtenter.setSize(590,30);
txtenter.addActionListener(new ActionListener()
{public void actionPerformed(ActionEvent arg0){
String utext=txtenter.getText();
txtchat.append("You: "+utext+"\n");
Voice voice;
VoiceManager voicemanager=VoiceManager.getInstance();
voice=voicemanager.getVoice("kevin16");
voice.allocate();
voice.speak(utext);
}
});
txtchat.setLocation(15,5);
txtchat.setLocation(15,5);
txtchat.setSize(560,510);
txtchat.setEditable(false);
}
public static void main(String[] args)
{
texttospeech ss=new texttospeech();
ss.texttospeech1();
}
}
FINALLY COMPILE AND RUN THE PROGRAM.
COMMENT YOUR QUERIES AND SHARE IT WITH YOUR FRIENDS!



Comments
Post a Comment