1 Reply Latest reply: Dec 30, 2008 8:57 AM by 800370 RSS

    how I can catch the word that was spoken in a string??

    843802
      Hi
      i'm doing a java aplication with speech recognition jsapi and i want know how  i can convert tag form FinalRuleResult  to string??

      i want  catch the word that was spoken in a string to  evaluate the string in the sentences if                               

      this is the code that i have developed:


      public static void main(String[] args)
           {prueba inst = new prueba();
                     inst.setVisible(true);
                try {
                     RecognizerModeDesc descripcion = new RecognizerModeDesc(null, Boolean.TRUE);
                     SpeechEngineChooser chooser = SpeechEngineChooser.getRecognizerDialog(descripcion);
                     chooser.show();
                     descripcion = chooser.getRecognizerModeDesc();
                     reconocedor = Central.createRecognizer(descripcion);
                     reconocedor.addEngineListener(new TestEngineListener());
                     
                     RecognizerAudioAdapter raud = new TestAudioListener();
                     reconocedor.getAudioManager().addAudioListener(raud);
                     reconocedor.allocate();
                     reconocedor.waitEngineState(Recognizer.ALLOCATED);
                     RuleSequence secuencia = new RuleSequence();
                     RuleTag comando1 = new RuleTag(new RuleToken("vol"),"VOL");
                     RuleTag comando2 = new RuleTag(new RuleToken("channel"),"CHANNEL");
                     RuleTag comando3 = new RuleTag(new RuleToken("end"),"END");
                     RuleTag comando4 = new RuleTag(new RuleToken("up"),"UP");
                     RuleTag comando5 = new RuleTag(new RuleToken("down"),"DOWN");
                     RuleAlternatives comandos = new RuleAlternatives();
                     comandos.append(comando1);
                     comandos.append(comando2);
                     comandos.append(comando3);
                     secuencia.append(comandos);
                     RuleGrammar gramatica = reconocedor.newRuleGrammar("basepatrones");
                     gramatica.setRule("testRule",secuencia,true);
                     gramatica.setEnabled(true);
                     reconocedor.suspend();
                     reconocedor.commitChanges();
                     reconocedor.waitEngineState(Recognizer.LISTENING);
                     reconocedor.requestFocus();
                     reconocedor.resume();
                     
                     reconocedor.addResultListener(new ResultAdapter() {
                          public void resultAccepted(final ResultEvent e)
                          {
                               try {
                                    FinalRuleResult r = (FinalRuleResult)(e.getSource());
                                    System.out.println("Obtenido el resultado "+r);
                                    String tags[] = r.getTags();
      if(tags == null) return;
                          //comparacion de :::     
      // in this point i want catch the word that was spoken in a string to evaluate the string in the sentences if                               
           
                                    if(tags[0].equals("VOL"))
                                         {
                                         
                                         JOptionPane.showMessageDialog(null,"has selecciuonado el volumen");
                                         jLabel1.setIcon(new ImageIcon(getClass().getClassLoader().getResource("control/controltv+.gif")));
                                         enviar("s");     
                                         }
                                    
                                    if(tags[0].equals("CHANNEL"))
                                              {
                                              JOptionPane.showMessageDialog(null,"QUIERES CAMBIAR CANAL???");
                                              jLabel1.setIcon(new ImageIcon(getClass().getClassLoader().getResource("control/controlt0.gif")));
                                              enviar("c");
                                              }
                                    if(tags[0].equals("END"))
                                    {
                               
                                    JOptionPane.showMessageDialog(null,"SESION DE RECONOCIMIENTO TERMINADA");
                                    jLabel1.setIcon(new ImageIcon(getClass().getClassLoader().getResource("control/controlt1.gif")));
                                    System.exit(-1);
                                    
                                    
                                    }
                                         
                                    else return;
                               } catch(Exception e1) {}
                          }
                     }
                );
                     
                     
                } catch (Exception e) {
                     e.printStackTrace();
                     System.exit(-1); }
           }