Share via


Creating ColorChooser: A Custom Application Speech Control

  Microsoft Speech Technologies Homepage

This document outlines the issues that a developer must consider when developing a custom Application Speech Control. These basic considerations are illustrated using the code behind the ColorChooser Application Speech Control sample, which is included among the sample applications. ColorChooser is a custom-made Application Speech Control, inherited from the ApplicationControl class in the Microsoft.Web.UI.SpeechControls.ApplicationControls namespace. The ApplicationControl class defines common properties that are useful when building an application control.

Basic Considerations for ColorChooser

The basic considerations that are required to create the ColorChooser control are the same considerations that are required for creating any Application Speech Control. These considerations are:

  • The required semantic items. In this example, only one semantic item is required for the user to choose a color.
  • The required grammars. The ColorChooser control requires a grammar that recognizes color names. Writing grammars is possibly the most difficult task of adding speech to an application. Build grammars in the control for best results. ColorChooser uses private methods that are defined in the ColorChooser class to generate grammars at runtime. These methods use several properties defined in the ApplicationControl class that allow authors to add application-specific preamble and postamble phrases.
  • The supported modes of operation. The ColorChooser control solely supports voice-only mode.
  • The required dialogue flow: The ColorChooser control dialogue asks the user for a color, and confirms the user's choice if the recognition confidence is low. The dialogue flow in this sample is very simple.
  • The required prompts. The ColorChooser control prompts elicit and confirm a color name, and handle recognition problems (such as user silence or low recognition confidence). Generally, a control's initial instructions or question should be as specific as possible. For example, if a developer wanted to adapt the ColorChooser control to elicit a customer's preferred color for a new car, a good initial prompt would be, "What color would you like to select for your new car?" Developers may also choose to build other prompts in the ColorChooser control such as a prompt confirming the selected color, or a prompt that responds to a user's query for help. For example, when a user says help while using the ColorChooser control, the control responds, "You may choose from red, green, blue, or yellow."

ColorChooser Property Inheritance

The ColorChooser control inherits a number of properties from the ApplicationControl class.

  • QuestionPrompt contains the prompt to use when the control asks the first question in voice-only mode.
  • PromptSelectFunction contains the name of the function that the ColorChooser control calls when creating prompts in voice-only mode.
  • ConfirmThreshold defines the confidence level, below which the ColorChooser control triggers confirmation in voice-only mode.
  • OptionalPreAnswerRuleRef, OptionalPostAnswerRuleRef, OptionalPreConfirmRuleRef, and OptionalPostConfirmRuleRef define sentence preamble and postamble grammars such as, "I would like" or "please."

ColorChooser Code Structure

The code block below illustrates a collapsed outline of the code behind the ColorChooser control. The full code is contained in ColorChooser.cs, which is located in the ColorChooserControl subdirectory of the SASDK Samples directory.

using System;
using Systm.ComponentModel;
using System.Reflection;
using System.Web.UI;

using Microsoft.Speech.Web.UI;

namespace ColorChooserControl
{
    /// <summary>
    /// Allow users to specify a color. Available colors are blue, green, red and yellow.
    /// </summary>
    public class ColorChooser : ApplicationControl
    {
        #region Private Members…
        
        #region Properties…

        /// <summary>
        /// Creates a new ColorChooser control.
        /// </summary>
        public ColorChooser()
        {}
        
        protected override void CreateChildControls()…
        private void InitializeChildControls()…
        protected override void OnPreRender(eventArgs e)…
        
        public override void RenderSpeechScript(HtmlTextWriter writer, SaltModules modules)…
        
        private string QuestionGrammar()…
        private string ConfirmGrammar()…
        private string ColorRule()…
        private string GetAbsolutePath(string relativePath)…
        
    }
}            

Additional Development Steps

Control developers commonly perform two additional steps that are not demonstrated in this topic: implementing data binding, and moving language-specific strings into resources.

Implementing data binding is beneficial because it allows application authors to more easily customize and update the content of the data that the control uses by simply updating the bound object. Implementing data binding for the ColorChooser control requires the developer to create a database for color names. For an example of how data binding is implemented in Application Speech Controls, refer to the sample, Selecting an Item from a List.

Moving language-specific strings into a resource is beneficial to application authors who want to localize a control because it simplifies the task of locating these strings when translating them from one language to another. Moving language-specific strings into a resource for the ColorChooser control requires the developer to store at least the location of the grammar library and the location of the prompt file in a resource. If the developer chooses not to store the color names in a database, then the color names need to be moved into the resource as well.

These additional steps are described in detail in the common ASP.NET documentation.