Search code examples
parsinguwpspeech-recognitionsfspeechrecognizer

UWP - Speech Recognition - Can't reference an external grammar file


I am building an UWP application with speech recognition capability. I want to reference an external grammar file from within another -root- file. Here is the code for the root grammar file (named RootGrammar.xml):

<?xml version="1.0" encoding="utf-8"?>
<grammar version="1.0" xml:lang="en-us" 
         root="topLevel" 
         xmlns="http://www.w3.org/2001/06/grammar" 
         tag-format="semantics/1.0"
         mode="voice">

<rule id="topLevel">
  <item>Hello</item>
  <ruleref uri="words.xml"/>
</rule>

</grammar>

And the external grammar file (named words.xml) is:

<?xml version="1.0" encoding="utf-8"?>
<grammar version="1.0" xml:lang="en-us" root="words"
         xmlns="http://www.w3.org/2001/06/grammar" 
         tag-format="semantics/1.0" 
         mode="voice">

  <rule id="words" scope="public">
    <one-of>
      <item>world</item>
      <item>universe</item>
      <item>galaxy</item>
    </one-of>
  </rule>

</grammar>

The two files are located in the same folder (named Grammar), the folder is located on the top level of the solution.

I tried many values for the URI attribute in the root grammar file like:

  • uri= "/words.xml"
  • uri= "\words.xml"
  • uri = "../words.xml"
  • uri = "..\words.xml"
  • uri = "ms-appx:///Grammar///words.xml"

I also tried to rename the external file into words.grxml, also tried explicitly identify the rule in the uri (i.e uri = "/words.xml#words") but all of that resulted in GrammarCompilationFailure.


Solution

  • It's by design. When checking the file path references, the only supported URI schemes are file://, http://, and https://. For now, the only solution will likely be to not have external reference files. You also could submit a Feature Request on WPDev UserVoice.