locked
Voice enabled app .... Cortana integration RRS feed

  • Question

  • Hi,

    I am trying to integrate voice commands in my windows app. I have windows 8.1 with VS express for windows. I am planning to create a app which will only work with voice commands. Based on voice commands I want to call particular web service api.

    My app should have a page with a microphone icon. The user should press the button and the app should listen the command. For example the user can say "Search Customers" or "Search Products". Based on what the customer says the app asks user to say "First Name" (If Customers) or "Product Name" (If Products). The user should then say the FirstName or Product name. Based on the command the api for Customer or Product will be called and parameter would be passed (First Name or Product Name).

    I tried finding some samples but I could not find anything like that. I did try to run the sample at MSDN VOICE SAMPLE but it fails when I press the Microphone button on the first app page it asks me to accept speech privacy policy. I accept that and it fails with the error (Code exact fail line un bold italic below) :

     /// <summary>
            /// Initializes the Speech Recognizer object and its completion handler, used for subsequent reco operations.
            /// </summary>
            private async void InitializeRecognizer()
            {
                this.Recognizer = new SpeechRecognizer();
                this.Recognizer.Grammars.AddGrammarFromPredefinedType("search", SpeechPredefinedGrammar.WebSearch);
                await this.Recognizer.PreloadGrammarsAsync();
    
                recoCompletedAction = new AsyncOperationCompletedHandler<SpeechRecognitionResult>((operation, asyncStatus) =>
                {
                    Dispatcher.BeginInvoke(() =>
                    {
                        this.CurrentRecognizerOperation = null;
                        bool recognitionSuccessful = false;
    
                        switch (asyncStatus)
                        {
                            case AsyncStatus.Completed:
                                SpeechRecognitionResult result = operation.GetResults();
                                if (!String.IsNullOrEmpty(result.Text))
                                {
                                    recognitionSuccessful = true;
                                    StartSearchQueryNavigation(result.Text, true);
                                }
                                break;
                            case AsyncStatus.Error:
                                MessageBox.Show(String.Format(
                                    AppResources.SpeechRecognitionErrorTemplate,
                                    operation.ErrorCode.HResult,
                                    operation.ErrorCode.Message));
                                break;
                            default:
                                break;
                        }

    Error is :

    An exception of type 'System.NullReferenceException' occurred in MSDN Voice Search.DLL but was not handled in user code

    Additional information: Object reference not set to an instance of an object.

    If there is a handler for this exception, the program may be safely continued.

    Reason  :  The operation object is null

     Any help is appreciated.

    - Girija


    Please mark responses as answered if it helped you.. This helps others... - Girija Shankar Beuria

    Saturday, October 25, 2014 5:43 PM

Answers

  • On Emulator the "MSDN VOICE SAMPLE" doesnot work but testing on device it works.

    - Girija


    Please mark responses as answered if it helped you.. This helps others... - Girija Shankar Beuria

    • Marked as answer by Girija Beuria Thursday, November 20, 2014 9:55 AM
    Thursday, November 20, 2014 9:55 AM

All replies

  • Hi Girija,

    Could you please check links below, It used to handle all exceptions:

    http://www.markermetro.com/2013/01/technical/handling-unhandled-exceptions-with-asyncawait-on-windows-8-and-windows-phone-8/

    http://msdn.microsoft.com/en-us/library/system.windows.application.unhandledexception(v=vs.95).aspx

    Hope this helps.

    Thanks

    Monday, October 27, 2014 8:09 AM
  • On Emulator the "MSDN VOICE SAMPLE" doesnot work but testing on device it works.

    - Girija


    Please mark responses as answered if it helped you.. This helps others... - Girija Shankar Beuria

    • Marked as answer by Girija Beuria Thursday, November 20, 2014 9:55 AM
    Thursday, November 20, 2014 9:55 AM