This topic describes a simple application that demonstrates debugging a dynamic grammar. Running this application requires
<form id=Form1 method=post runat="server">
<speech:answercall id=AnswerCall1 runat="server">
</speech:answercall>
<speech:semanticmap id=SemanticMap runat="server">
<speech:SemanticItem id="siState" runat="server"
TargetAttribute="value" TargetElement="TextBox1">
</speech:SemanticItem>
</speech:semanticmap>
<asp:TextBox id=TextBox1 runat="server"></asp:TextBox>
<speech:QA ID="QA1" runat="server" >
<Prompt ID="p1" InlinePrompt="Please say the name of a nation." >
</Prompt>
<Reco >
<Grammars>
<speech:Grammar ID="G1" runat="server" Src="CreateNationGrammar.aspx">
</speech:Grammar>
</Grammars>
</Reco>
<Answers>
<speech:Answer SemanticItem="siState" XpathTrigger="/SML/NationRule" >
</speech:Answer>
</Answers>
</speech:QA>
</form>
The Grammar tag references the dynamic grammar CreateNationGrammar.aspx. When the QA control that contains this tag is activated, ASP.NET will load CreateNationGrammar.aspx and its code-behind module, CreateNationGrammar.aspx.cs. When the name of a nation has been recognized, the QA control will place the name in TextBox1.
<?xml version="1.0"?>
<%@ Page language="c#" Codebehind="CreateNationGrammar.aspx.cs" AutoEventWireup="false" Inherits="DebugDynamicGrammar.CreateNationGrammar" %>
<grammar root="NationRule" xml:lang="en-US" version="1.0" xmlns="http://www.w3.org/2001/06/grammar" tag-format="semantics-ms/1.0">
<rule id="NationRule" scope="public">
<one-of>
<%= CreateGrammar() %>
</one-of>
</rule>
</grammar>
//
// <item> <tag> $.value="albania" </tag> albania </item>
//
private string OneItem(string whatever)
{
return("<item><tag> $.value=\"" + whatever + "\" </tag> " + whatever + " </item>\r\n");
}
protected string CreateGrammar()
{
// As if records in a recordset
string grm = "\r\n";
grm += OneItem("Albania");
grm += OneItem("Algeria");
grm += OneItem("Argentina");
grm += OneItem("Australia");
// . . .
grm += OneItem("Zimbabwe");
return grm;
}
<SML confidence="1.000" text="australia" utteranceConfidence="1.000"> <value>Australia</value> </SML>But the application will hang, and the nation name will not appear in TextBox1. This suggests that there may be a problem with the dynamic grammar.
//localhost/DebugDynamicGrammar/CreateNationGrammar.aspxThis will display the content of the dynamic grammar. To view and validate the grammar in the
In the case of this application, the problem is easy to determine: The dynamic grammar returns names in a mode with an XPath of /SML/value, but the QA control is searching for data with an XPath of /SML/NationRule. To fix the application, change the QA control's XPathTrigger property to /SML/value.
To summarize the technique for debugging dynamic grammars:
|
|
| Last Updated: April 28, 2004 |
|
|
|