I am developing an application in JAVA that takes input as speech and performs actions. What I want to achieve is button click without explicitly clicking on that button.
The idea is to take the speech input, use the result which is a String object, and invoke button click just by speech result.
I have been able to use that result to start notepad or browser.
For speech processing I am using Sphinx4 and eclipse IDE.
Example:
Result result = recognizer.recognize();
if (result != null)
{
String resultText = result.getBestFinalResultNoFiller();
if((resultText.equalsIgnoreCase("Notepad"))
{
try
{
pr[0] = new ProcessBuilder("notepad.exe").start();
}
Here resultText is the String object containing the user's input. Here I tried opening notepad if speaker says notepad.
But how to use this resultText to invoke actionPerformed of a button....?
Example: How to invoke this method of a JFrame without button click
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt)
{
NewJFrame1 frame = new NewJFrame1();
frame.setVisible(true);
this.dispose();
}
If pressing the button does more than just invoking the jButton1ActionPerformed
method you showed here, use the doClick()
method on the JButton object, which I'm guessing you called jButton1
:
jButton1.doClick();
You can also cut out the middleman and just call your method directly, like any other. (This will only work if your handler method doesn't use the event argument object evt
. Since you've declared it private
, the calling method must also be in the same class.)
jButton1ActionPerformed(null);