Freigeben über


MenuActivity in MSS

POSTED BY: AHMED STEWART, MSS Software Dev Engineer

Today, I’m going to talk about the MenuActivity of MSS 2007 Beta.

The Menu, like the name implies, allows easy selection of an item from a menu. Under the covers the activity creates a grammar consisting of the items supplied to it.

Menu, like the other high level activities, supports confirmation, but since I’ve already talked about in the post about the GetAndConfirm Activity, I won’t go over it again here.

Now, let’s get into using the MenuActivity:

The code below creates a string array that contains the options that the user can choose from. The Executing handler then assigns the array to the DataSource of the MenuActivity and Binds the data to the activity. The binding process just creates the required grammars from the options.

     private string[] _choicesList = new string[] { "one", "two", "three", "four", "five" };
     private void menuActivity1_Executing(object sender, ActivityExecutionStatusChangedEventArgs e)
     {
          menuActivity1.DataSource = _choicesList;
          menuActivity1.DataBind();
     }

Below is the TurnStarting handler which is pretty self explanatory.

     private void menuActivity1_TurnStarting(object sender, TurnStartingEventArgs e)
     {
          //The actual text of the prompt
          string optionText = "This is option {0}. ";

          //Clear the prompt
          menuActivity1.MainPrompt.ClearContent();

          //For each option, add a bookmark and a prompt for it.
          foreach (string option in _choicesList)
          {

menuActivity1.MainPrompt.AppendBookmark(option);

menuActivity1.MainPrompt.AppendText(String.Format(optionText, option));
          }
     }

The code above that constructs the prompt text inserts a bookmark before text that is associated with an option. When the default grammar recognizes “that one”, the last encountered bookmark is set as the selected option. For the curious, the constructed SSML looks like this:

<speak version="1.0" xmlns="https://www.w3.org/2001/10/synthesis" xml:lang="en-US"><mark name="one" />This is option one. <mark name="two" />This is option two. <mark name="three" />This is option three. <mark name="four" />This is option four. <mark name="five" />This is option five. </speak>

Custom grammars can also be used for the “that one” recognition by adding them to the Grammars collection of the activity. If you decide to go this route, you’re going to have to set the selected option yourself. The function below is a sample grammar recognized handle that calls the appropriate method:

     void customTimedRecoGrammar_Recognized(object sender, RecognizedEventArgs e)
{

menuActivity1.SetSelectedOptionToMostRecentBookmark(sender, e);
     }

After the activity completes execution, the selection is available via the SelectedOption property.

Comments

  • Anonymous
    February 09, 2007
    Earlier Marshall blogged about Speech Workflow Applications in Microsoft Speech Server 2007 Beta. Today,