Share via


Implementing the Dialogue Flow

  Microsoft Speech Technologies Homepage

The dialogue flow of the ColorChooser control uses two QA controls. One QA control prompts the user to choose a color name, and the other confirms the color name. Include confirmational QA controls in an application in case the application is unable to recognize user responses with high confidence.

Creating the ColorChooser QA Controls

The CreateChildControls method creates these child QA controls, establishing their basic structure. The code for establishing the basic structure of both QA controls is similar. A new Answer object and a new Grammar object are created and added to the Answers and Grammars collections of the controls. The code for both controls also sets the XPathTrigger property and assigns the value of this property to the location of the color grammar that the QA controls use to recognize a color name.

The code for the confirm QA control also creates additional XPath properties and assigns the value of these properties to paths for SML accept and reject.

The member modifier of the CreateChildControls method is set to override to ensure that the QA controls are added to the ColorChooser control. The last few lines of the code add the new question QA and confirm QA controls, and set the value of the ChildControlsCreated property of the ColorChooser control to true.

protected override void CreateChildControls()
{
    // question
    _question = new QA();
    
    Answer QuestionAnswer = new Answer();
    questionAnswer.XPathTrigger     = "//color";
    _question.Answers.Add(questionAnswer);

    Grammar grammar = new Grammar();
    _question.Reco.Grammars.Add(grammar);
    
    // confirm
    _confirm = new QA();
    _confirm.XPathAcceptConfirms    = "/SML/accept";
    _confirm.XPathDenyConfirms      = "/SML/deny";

    Answer confirmAnswer = new Answer();
    confirmAnswer.XPathTrigger     = "//color";
    _confirm.Confirms.Add(confirmAnswer);
    
    grammar = new Grammar();
    _confirm.Reco.Grammars.Add(grammar);

    Controls.Add(_question);
    Controls.Add(_confirm);

    ChildControlsCreated = true;
}

Initializing QA Control Values

The InitializeChildControls method initializes the values of various properties. For both QA controls, the code:

  • Sets the value of the ClientActivationFunction property to the location of a function in an external file (ColorChooser-code.js) that generates a client object.
  • Sets the value of the PromptSelectFunction property to the location of a function in an external file (ColorChooser-prompt.js) that generates a prompt (the initial question prompt for the question QA and the confirmation prompt for the confirm QA).
  • Copies the prompt database for each of the QA controls.
  • Sets values for BargeIn, time-outs, and recognition thresholds.
  • Sets the value of the InlineGrammar property of the Grammar object belonging to the QA control to call a function that creates a grammar. The function associated with the question QA creates the QuestionGrammar grammar, and the function associated with the confirm QA creates the ConfirmGrammar grammar.
private void InitializeChildControls()
{                    
    _question.ClientActivationFunction    = ClientObjectID + "." + _clientActivationFunctionName;      
    _question.Prompt.PromptSelectFunction = ClientPromptObjectID + "." + _questionPromptSelectFunctionName;

    foreach(PromptDatabase database in PromptDatabases)
    {
        PromptDatabase tempDatabase = new PromptDatabase();
        tempDatabase.Source = database.Source;
        _question.Prompt.PromptDatabases.Add(tempDatabase);
    }
    _question.Prompt.BargeIn        = BargeIn;
    _question.Reco.EndSilence       = EndSilence;
    _question.Reco.InitialTimeout   = InitialTimeout;
    _question.Reco.BabbleTimeout    = BabbleTimeout;
    _question.Reco.MaxTimeout       = MaxTimeout;

    _question.Reco.Grammars[0].InlineGrammar = System.Web.HttpUtility.HtmlEncode(QuestionGrammar());

    _question.Answers[0].SemanticItem     = SemanticItem;
    _question.Answers[0].ConfirmThreshold = ConfirmThreshold;
    _question.Answers[0].Reject           = RejectThreshold;

    _confirm.ClientActivationFunction    = ClientObjectID + "." + _clientActivationFunctionName;                  
    _confirm.Prompt.PromptSelectFunction = ClientPromptObjectID + "." + _confirmPromptSelectFunctionName;            

    foreach(PromptDatabase database in PromptDatabases)
    {
        PromptDatabase tempDatabase = new PromptDatabase();
        tempDatabase.Source = database.Source;
        _confirm.Prompt.PromptDatabases.Add(tempDatabase);
    }
    _confirm.Prompt.BargeIn         = BargeIn;
    _confirm.Reco.InitialTimeout    = EndSilence;
    _confirm.Reco.InitialTimeout    = InitialTimeout;
    _confirm.Reco.BabbleTimeout     = BabbleTimeout;
    _confirm.Reco.MaxTimeout        = MaxTimeout;
    _confirm.AcceptRejectThreshold  = ConfirmRejectThreshold;

    _confirm.Reco.Grammars[0].InlineGrammar = System.Web.HttpUtility.HtmlEncode(ConfirmGrammar());

    _confirm.Confirms[0].SemanticItem     = SemanticItem;
    _confirm.Confirms[0].ConfirmThreshold = ConfirmThreshold;
    _confirm.Confirms[0].Reject           = RejectThreshold;
}

See Also

Creating ColorChooser: A Custom Application Speech Control | Creating the Class and SemanticItem Property | Creating the Grammars | Generating Prompts | Creating a Client-Side Object and SALT