Bagikan melalui


Note

Please see Azure Cognitive Services for Speech documentation for the latest supported speech solutions.

Serialization of the Root Rule Variable (Microsoft.Speech)

On recognition, the semantic interpretation mechanism of a speech recognition engine returns a semantic result to the speech application. The semantic result of a recognition is the value of the root Rule Variable (RRV) of the grammar. Like all Rule Variables, the RRV is predefined as an object.

For an input grammar that contains no markup for semantic interpretation, the SML output consists of a top-level node named SML that contains the recognized utterance. The SML opening tag contains three attributes named text, utteranceConfidence, and confidence. The following example illustrates a simple grammar that contains no markup for semantic interpretation.

<grammar version="1.0" xml:lang="en-US" mode="voice" root="destination" 
xmlns="http://www.w3.org/2001/06/grammar" tag-format="semantics/1.0">

  <rule id="destination">
    Fly me to
    <one-of>
      <item> London </item>
      <item> Paris </item>
      <item> Berlin </item>
    </one-of>
  </rule>
</grammar>

Using this grammar, the utterance "Fly me to Paris" produces the following SML output.

<SML text="Fly me to Paris" utteranceConfidence="0.874" confidence="0.874" >
    Fly me to Paris
</SML>

For more information about the structure of SML output, and the value types and ranges of these attributes in the SML element, see SML Output Overview (Microsoft.Speech).

Simple Assignment to the Root Rule Variable

If a developer directly assigns a simple scalar value to the root Rule Variable (RRV), all the properties of the RRV that the semantic interpreter normally uses for serialization are lost. The semantic interpreter produces an output in which the top-level SML element has no attributes and contains the simple scalar value. In the following grammar, each expression contained in the tag elements assigns a simple string value to the RRV.

<grammar version="1.0" xml:lang="en-US" mode="voice" root="destination" 
xmlns="http://www.w3.org/2001/06/grammar" tag-format="semantics/1.0">

  <rule id="destination">
    Fly me to
    <one-of>
      <item> London <tag> out="Heathrow"; </tag></item>
      <item> Pairs <tag> out="Orly"; </tag></item>
      <item> Berlin <tag> out="Tegel"; </tag></item>
    </one-of>
  </rule>
</grammar>

Using this grammar, the utterance "Fly me to Paris" produces SML output similar to the following.

<SML> Orly </SML>

Accessing the Root Rule Variable

Use one of the following to access the RRV to set the text content of the top-level SML element.

  • If the value for the tag-format attribute of the grammar element is semantics/1.0, the Rule Variable is named "out".

  • If the value for the tag-format attribute of the grammar element is semantics-ms/1.0 the Rule Variable is named "$".

The following grammar is identical to the previous grammar except for the addition of an expression that assigns a value to the RRV.

<grammar version="1.0" xmlns="http://www.w3.org/2001/06/grammar"
 root="destination" xml:lang="en-US" tag-format="semantics/1.0">

  <rule id="destination">
    <tag> out="Destination city"; </tag>
    Fly me to
    <one-of>
      <item> London </item>
      <item> Paris </item>
      <item> Berlin </item>
    </one-of>
  </rule>
</grammar>

Using this grammar, the utterance "Fly me to Paris" produces SML output similar to the following.

<SML text="Fly me to Paris" utteranceConfidence="0.874" confidence="0.874" >
    Destination city
</SML>

With the script expression written in the syntax of semantics-ms/1.0, the following example will also produce the preceding SML output.

<grammar version="1.0" xmlns="http://www.w3.org/2001/06/grammar"
 root="destination" xml:lang="en-US" tag-format="semantics/1.0">

  <rule id="destination">
    <tag> $="Destination city"; </tag>
    Fly me to
    <one-of>
      <item> London </item>
      <item> Paris </item>
      <item> Berlin </item>
    </one-of>
  </rule>
</grammar>

All valid utterances for this grammar produce an SML result that has the same text content in the top-level SML element. This result occurs because the script expression assigning the value of the text content follows the start tag of the rule element. For grammars that contain lists in one-of elements, change the value of the text content of the SML element according to the item selected from a list. Follow each item element with a tag element containing a script expression that assigns a different string value to the RRV. The following grammar is identical to the previous grammar except for the addition of script expressions that create SML element text content that is specific to each item.

<grammar version="1.0" xml:lang="en-US" mode="voice" root="destination" 
xmlns="http://www.w3.org/2001/06/grammar" tag-format="semantics/1.0">
  <rule id="destination">
    Fly me to
    <one-of>
      <item> London <tag> out="Arriving at Heathrow"; </tag></item>
      <item> Paris <tag> out="Arriving at Orly"; </tag></item>
      <item> Berlin <tag> out="Arriving at Tegel"; </tag></item>
    </one-of>
  </rule>
</grammar>

Using this grammar, the utterance "Fly me to Paris" produces the following SML output.

<SML text="Fly me to Paris" utteranceConfidence="0.886" confidence="0.886" >
    Arriving at Orly
</SML>

Accessing Properties of the Root Rule Variable

Use the _attributes property of the RRV to produce additional XML attributes in the top-level SML element start tag. As can be seen in the first line in the body of the rule, the _attributes property is created as a new object (out._attributes=new Object();). This is necessary because the _attributes property has two child properties, code and time. The following grammar is identical to the previous grammar, except for the addition of expressions that assign values to two child properties of the _attributes property of the RRV. The code has also been reformatted to make it easier to read.

<rule id="destination">
  <tag>out._attributes=new Object();</tag>
  Fly me to
  <one-of>
    <item>London
      <tag>
        out._value="Arriving at Heathrow";
        out._attributes.code="EGLL";
        out._attributes.time="UTC";
      </tag>
    </item>
    <item>Paris
      <tag>
        out._value="Arriving at Orly";
        out._attributes.code="LFPO";
        out._attributes.time="UTC+1";
      </tag>
    </item>
    <item>Berlin
      <tag>
        out._value="Arriving at Tegel";
        out._attributes.code="EDDT";
        out._attributes.time="UTC+1";
      </tag>
    </item>
  </one-of>
</rule>

Using this grammar, the utterance "Fly me to Paris" produces the following SML output.

<SML text="Fly me to Paris" utteranceConfidence="0.840"confidence="0.840" code="LFPO" time="UTC+1" >
    Arriving at Orly
</SML>

See Also

Concepts

Semantic Interpretation Markup (Microsoft.Speech)

Using the tag Element (Microsoft.Speech)

tag Element (Microsoft.Speech)

ruleref Element (Microsoft.Speech)