i need speech to text conversion in java with source code
Posts: 8,059
Threads: 1
Joined: Mar 2014
free download speech to text conversion in java open source code
package speechtotext;
import edu.cmu.sphinx.frontend.util.Microphone;
import edu.cmu.sphinx.recognizer.Recognizer;
import edu.cmu.sphinx.result.Result;
import edu.cmu.sphinx.util.props.ConfigurationManager;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
public class HelloWorld extends JApplet implements ActionListener{
private JButton b1 = new JButton("SPEAK"), b2 = new JButton("STOP");
JTextArea textArea = new JTextArea(7,30);
Result result;
ConfigurationManager cm;
Recognizer recognizer;
Microphone microphone;
String resultText ;
public void init() {
Container cp = getContentPane();
cp.setLayout(new FlowLayout());
Image image = Toolkit.getDefaultToolkit().createImage("C:\\Users\\arsa\\Desktop\\1.png");
Image scaled = image.getScaledInstance(300, 550, Image.SCALE_SMOOTH);
JLabel label = new JLabel(new ImageIcon(scaled));
cp.add(label,BorderLayout.CENTER);
textArea.setText("");
textArea.setLineWrap(true);
textArea.setEditable(false);
add(textArea,"Center");
cp.add(b2,FlowLayout.LEFT);
cp.add(b1,FlowLayout.LEFT);
cp.add(textArea);
b1.addActionListener(this);
b2.addActionListener(this);
cm = new ConfigurationManager(HelloWorld.class.getResource("helloworld.config.xml"));
recognizer = (Recognizer) cm.lookup("recognizer");
System.out.println("Successful1 allocation");
recognizer.allocate();
System.out.println("Successful1 allocation1");
microphone = (Microphone) cm.lookup("microphone");
if (!microphone.startRecording()) {
System.out.println("Cannot start microphone.");
recognizer.deallocate();
System.exit(1);
}
}
@Override
public void actionPerformed(ActionEvent e) {
String str=e.getActionCommand();
if (e.getSource() == b1)
{
result = recognizer.recognize();
}
else if (e.getSource() == b2)
{
if (result != null) {
resultText = result.getBestPronunciationResult();
if(resultText!=null)
textArea.setText("You said: " + resultText + '\n');
else if(resultText==null)
textArea.setText("I couldn't hear what you said.\n");
}
else if(result==null)
textArea.setText("Cheater!! Cheater!! you didn't say anything....\n");
}
}