none
How does one set RecognizeCompletedEventArgs.UserState property? RRS feed

  • Question

  • I have not been able to find a way to set the UserState when calling the SpeechRecognitionEngine.RecognizeAsync(...) method.  Is it possible?  It would be a real benefit to my application if it could be set.
    Regards, JayAchTee
    Wednesday, January 26, 2011 2:10 PM

Answers

  • I took a different approach and created a Grammar superclass and added the necessay properties for user state, my own engine and a callback/event handler.  I then subscribed to the SpeechRecognized event on the Grammar and using the e.Result construct a new event argument object with my user state set properly.  I can also bubble the event up to the engine's RecognizeCompleted event using the same event agrument class.

    This might be a flaw in the implementation of the SpeechRecognitionEngine class or the documentation should reflect the unusability of the UserState property.

    Thanks for your input however!


    Regards, JayAchTee
    • Marked as answer by JayAchTee Thursday, January 27, 2011 6:27 PM
    Thursday, January 27, 2011 6:27 PM

All replies

  •  

    Hi JayAchTee,

     

    My test result shows that the UserState field is always NULL, the callback method (e.g. _recognizer_RecognizeCompleted(System.Object, System.Speech.Recognition.RecognizeCompletedEventArgs)) is invoked by System.Speech.Internal.AsyncSerializedWorker.WorkerProc method, the latter method only accepted an object as parameter, I cannot see how the method is implemented, but seems that the UserState is out of our control.

     

    As an alternative, you may create an object of Dictionary<Guid, object>, each time you invoke the SpeechRecognitionEngine.RecognizeAsync method, create a new guid, store information in the value object, and insert an element to the Dictionary<Guid, object> object; in the callback method, retrieve the value object according the guid in your hand.


    Eric Yang [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Thursday, January 27, 2011 7:04 AM
  • I took a different approach and created a Grammar superclass and added the necessay properties for user state, my own engine and a callback/event handler.  I then subscribed to the SpeechRecognized event on the Grammar and using the e.Result construct a new event argument object with my user state set properly.  I can also bubble the event up to the engine's RecognizeCompleted event using the same event agrument class.

    This might be a flaw in the implementation of the SpeechRecognitionEngine class or the documentation should reflect the unusability of the UserState property.

    Thanks for your input however!


    Regards, JayAchTee
    • Marked as answer by JayAchTee Thursday, January 27, 2011 6:27 PM
    Thursday, January 27, 2011 6:27 PM