I'm doing speech recognition application. Now my application can recognize my speech command, but somehow my application still not working. Is it because i did not trigger an event like .getSource()? This is part of my program:

public void resultAccepted(javax.speech.recognition.ResultEvent e)
    {
        try{
                 Result r = (Result)(e.getSource());
                 ResultToken tokens[] = r.getBestTokens();
                 for (int i = 0; i < tokens.length; i++)
                 {
                        gst=tokens[i].getSpokenText();
                 }
                 JOptionPane.showMessageDialog(new JFrame(),gst, "word",JOptionPane.INFORMATION_MESSAGE);

                 if (gst.equals("A"))
                 {

                      try{
                               lesson_yearlist.show();
                               lesson_yearlist.toFront();
                         }
                      catch(Exception ee)
                      {
                               JOptionPane.showMessageDialog(new JFrame(),"error", "Error", JOptionPane.ERROR_MESSAGE);
                      }
                  }
                  else if (gst.equals("Exercise"))
                  {
                               JOptionPane.showMessageDialog(new JFrame(),"printing", "print",JOptionPane.INFORMATION_MESSAGE);
                               exelist.show();
                               exelist.toFront();
                  }
                  else
                  {
                               JOptionPane.showMessageDialog(new JFrame(),"error", "Not found",JOptionPane.ERROR_MESSAGE);
                   }
                   }
                   catch (Exception ec)
                   {
                               ec.printStackTrace();
                   }

                   }

When I say "exercise", the JOptionPane is showing "exercise" to show that the recognizer gets what i said exactly and the second JOptionPane shows "printing" to show that my if statement is working. But the second and third lines exelist.show() and exelist.toFront() are not working. They are working fine with button using mouse.

Please help. Thanks

Recommended Answers

All 6 Replies

"exercise" is not equal to "Exercise"
It's probably a good idea to convert everything to a single case (eg toLowerCase()) to avoid this kind of problem.

What i write in my grammar file is "Exercise". And there is a message box showing "printing" so i think the if-statement works.

I was just quoting what you posted exactly as you posted it

if (gst.equals("Exercise"))
...
the JOptionPane is showing "exercise"

yeah...my mistake sorry. I just wanna to say my speech command match with if-statement since the "printing" message box showed. Any suggestion?

without any of the code for exelist there's nothing else I can suggest, sorry. Maybe it's something to do with the current state of exelist - whatever that may be?

the exelist is one of my internal frame. Now i just realize we should use jDesktopPane to manipulate internal frames. But I put all my internal frames in JLayoutPane instead. Will it occur problem when i wanna switch frames if using JLayoutPane? Is it the reason why my internal frames is not showing and in front when the speech recognizer catch my speech input?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.