Handling Recognition Events

Top  Previous  Next

When there are active recognition results or warnings/errors, the voice recognition module sends events via callbacks. You can subscribe the following events in your application:

OnRecognition: The module sends this event when there are active recognition results. The RecognitionData structure describes the recognition details.
OnAlert: The module sends this event when there are warnings or errors such as volume too high or too low. See the AlertData structure for the event definitions.

Example 80 shows a typical voice recognition handler implementation.

The application must maintain the life cycle of the event handler until after the StopRec function.

C++ Example 80: Voice Recognition Handler Implementation

class MyHandler: public PXCSpeechRecognition::Handler {

public:

   virtual void PXCAPI OnRecognition(const PXCSpeechRecognition::RecognitionData *data) {

       // Process Recognition Data

   }

};

 

// sr is a PXCSpeechRecognition instance

MyHandler handler;

sr->StartRec(NULL, &handler);

 

...

 

sr->StopRec();

C# Example 80: Voice Recognition Handler Implementation

public void OnRecognition(PXCMSpeechRecognition.RecognitionData data) {

   // Process Recognition Data

};

 

// Set handler

PXCMSpeechRecognition.Handler handler=new PXCMSpeechRecognition.Handler();

handler.onRecognition=OnRecognition;

 

// sr is a PXCMSpeechRecognition instance

sr.StartRec(null, handler);

 

...

 

sr.StopRec();

Java Example 80: Voice Recognition Handler Implementation

class MyHandler implements PXCMSpeechRecognition::Handler {

   public void OnRecognition(PXCMSpeechRecognition.RecognitionData data) {

       // Process Recognition Data

   }

};

 

// Set handler

MyHandler handler=new MyHandler();

 

// sr is a PXCMSpeechRecognition instance

sr.StartRec(null, handler);

 

...

 

sr.StopRec();