I am developing a speech application. It takes input in the form of speech, and then performs the actions available in the graphical interface. I am using sphinx4-1.0beta 6 src and eclipse IDE.
I created a GUI, now what I want to do is use speech to click a button. For example, when I say “SEARCH”, the search button is pressed. Basically the idea is to access sphinx4 in my gui so that I can start the speech recognition on my button and search according to the speech input.
I also want to listen to the speech input after clicking the button to determine what to look for and perform actions accordingly. Someone please suggest what needs to be done.
The following is a modified HelloWorld file.
Here is the actionPerformed method button:
public void jButton3ActionPerformed(java.awt.event.ActionEvent evt){
try {
Class.forName("oracle.jdbc.OracleDriver");
con=DriverManager.getConnection("jdbc:oracle:thin:@127.0.0.1:1521:xe","system","manhattan");
PreparedStatement ps=con.prepareStatement("select * from records where stid=?");
ResultSet rs=ps.executeQuery();
if (rs.next()){
}
}catch(Exception e){
e.printStackTrace();
}
}
Can someone suggest how to click on this button using speech. I checked that doClick () can be used to handle listeners. But he can’t understand how to achieve the goal.
And secondly, how to make sphinx4 listen for speech input after a click? Here's how to link and use sphinx4 in a GUI ..?
For example, I say “SEARCH”, then the search button is pressed, and then I say “java”, it extracts the result for java from the database. I modified HelloWorld to enable notepad and browser so that it can open notepad, talking notepad. But how to connect it with the push of a button?
Here is a modified HelloWorld demo from sphinx4:
package edu.cmu.sphinx.demo.helloworld;
import java.io.IOException;
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.io.IOException;
public class HelloWorld {
public static void main(String[] args)
{
ConfigurationManager cm;
Process pr[]=new Process[2];
if (args.length > 0) {
cm = new ConfigurationManager(args));
} else {
cm = new ConfigurationManager(HelloWorld.class.getResource("helloworld.config.xml"));
}
Recognizer recognizer = (Recognizer) cm.lookup("recognizer");
recognizer.allocate();
Microphone microphone = (Microphone) cm.lookup("microphone");
if (!microphone.startRecording()) {
System.out.println("Cannot start microphone.");
recognizer.deallocate();
System.exit(1);
}
System.out.println("Say: (Good morning | Hello ) ( Steve | Andrew | Paul | Phili p | Rita | Will | Mark )");
System.out.print(" (Hi | Bye )* ( Tony ) \n( Search | Mail | Browser | Notepad ) \n (Open | Close) ( Search | Mail | Browser | Paint | Notepad ) \n");
while (true) {
System.out.println("Start speaking. Press Ctrl-C to quit.\n");
Result result = recognizer.recognize();
if (result != null)
{
String resultText = result.getBestFinalResultNoFiller();
if((resultText.equalsIgnoreCase("Notepad"))||(resultText.equalsIgnoreCase("Open Notepad")))
{
try
{
pr[0] = new ProcessBuilder("notepad.exe").start();
}
catch (IOException e)
{
e.printStackTrace();
}
}
if(resultText.equalsIgnoreCase("Close Notepad"))
{
try{
pr[0].destroy();
}
catch(Exception ee)
{
ee.printStackTrace();
}
}
if((resultText.equalsIgnoreCase("Browser"))||(resultText.equalsIgnoreCase("Open Browser")))
{
try
{
pr[1] = new ProcessBuilder("C:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe").start();
}
catch (IOException e)
{
e.printStackTrace();
}
}
System.out.println("You said: " + resultText + '\n');
}
else {
System.out.println("I can't hear what you said.\n");
}
}
}
}