locked
How to add dictation in grammar with Windows.Media.SpeechRecognition.SpeechRecognizer?

    Question

  • I am using the following grammar file: https://gist.github.com/pke/090714c8cd6f3ccf556b

    But the entry to the dictation causes the call to speechRecognizer.recognizeAsync() to throw a 

    SCRIPT5385: Exception was thrown at line 34, column 9 in ms-appx://trello.windows/js/default.js
    0x80131509 - JavaScript runtime error: Unknown runtime error

    If I remove the entry at line 28, the call does not throw. But that is of course not the grammar I want. Any ideas?

    var speechRecognizer = new Windows.Media.SpeechRecognition.SpeechRecognizer();
        var uri = new Windows.Foundation.Uri("ms-appx:///speech.grxml");
        var storageFile = Windows.Storage.StorageFile.getFileFromApplicationUriAsync(uri)
        .then(function (srgs) {
          var grammarfileConstraint = new Windows.Media.SpeechRecognition.SpeechRecognitionGrammarFileConstraint(srgs, "createCommands");
          speechRecognizer.constraints.append(grammarfileConstraint);
          speechRecognizer.compileConstraintsAsync()
        }).then(function () {
          var listen = function() {
            speechRecognizer.recognizeAsync()
            .then(function (result) {
              console.info(result.text);
            }, function (error) {
              console.error("Speech: " + error.message);
            }).then(function () {
              WinJS.Promise.timeout().then(listen);
            });
          }
          listen();
        })

    Thursday, April 16, 2015 10:19 PM