Share via


Creating Prompt Functions

  Microsoft Speech Technologies Homepage

Use Prompt Function Editor to write functions that generate prompts. Prompt functions dynamically generate one or more prompts based on the application's dialogue flow. For example, a flight booking system might generate a prompt "Please confirm that you want a flight from Chicago O'Hare to Newark tomorrow," in which the origin, destination, and date are all variables.

Prompt functions are written in JScript code. Prompt Function Editor stores prompt functions in a .pf file instead of a .js file. The .pf files generated by Prompt Function Editor are UTF-8 encoded, and contain an XML header that allows Prompt Function Editor to maintain the file. Although prompt functions could reside in a .js file, the .pf format allows the Prompt Validation tool to validate dynamically-generated prompts at design time. The Prompt Validation tool cannot validate dynamically-generated prompts created by prompt functions that reside in a .js file.

Using Prompt Function Editor

Prompt Function Editor consists of three panes.

  • The top pane contains buttons for selecting, creating, deleting, and renaming prompt functions.
  • The middle pane is the Parameter window. Enter names, validation values, and run-time values of prompt function parameters in the Parameter window.
  • The bottom pane is the Script Editor window. Define custom behavior for the prompt function by entering script code in the Script Editor window.

To open Prompt Function Editor

  1. In Solution Explorer, double-click a prompt function file (.pf extension).

- or -

In Solution Explorer, select the Web application.

  1. On the File menu, select Add New Item.
  2. In the Add New Item dialog box, in the Templates pane, double-click the Prompt Function file icon.

- or -

Right-click a Microsoft ASP.NET Application Speech Control.

  1. On the shortcut menu, select Property Builder.
  2. In the Properties dialog box, in the tree view pane on the left, expand the Voice-Only item and click Prompt.
  3. Click Manage this page's Prompt Function script files.
  4. Click Add Existing. Use the Prompt Function URL browser dialog box to locate an existing prompt function file, then click OK.

- or -

Click New. Enter the name of a new prompt function file, then click Save.

  1. Click OK to close the Properties dialog box.
  2. In Solution Explorer, double-click the prompt function file that was added to the project in step 5.

To select a prompt function

Choose a prompt function from the Prompt function drop-down list.

To add a new prompt function

  1. In Prompt Function Editor, click the New Function button.

  2. In the New Function Name dialog box, enter the function name and click OK.

  3. In the Parameter window, select a row.

  4. In the Parameter Name column in the selected row, enter the name of the parameter.

  5. In the Validation Value column in the selected row, click the cell to open the Validation Values dialog box.

  6. In the Validation Values dialog box, enter values for the parameter. Entering parameter values is optional. The Web application does not use parameter values at run time. Instead, the Prompt Validation Tool uses parameter values to help verify that the prompt database has the expected coverage. Enter one value, or a range of values, per line.

    • Indicate ranges by entering low and high values separated by a dash (for example, 1-7).
    • Enter string values enclosed in quotes (for example, "Seattle").
  7. In the Runtime Value column in the selected row, enter the property or variable in the application that provides the parameter's input value.

    To create a prompt which contains text from the results of a recognition, use the client-side SemanticItem object's value property. Create a parameter which uses SemanticItem.value as its runtime value, where SemanticItem is the unique ID entered in the New Semantic Item dialog box.

  8. In the Script Editor window, add additional lines of script as needed.

To delete a prompt function

  1. In Prompt Function Editor, select a function name on the Prompt function drop-down list.
  2. Click Delete Function, then click Yes to confirm.

To rename a prompt function

  1. In Prompt Function Editor, select a function name on the Prompt function drop-down list.
  2. Click Rename Function.
  3. In the New Function Name dialog box, enter the new function name, and then click OK.

To search in a prompt function

Find and replace functionality is not supported by Prompt Function Editor. To find and/or replace code within the function, it is necessary to use a different editor using the following steps:

  1. Right-click on the prompt function file (.pf) in Solution Explorer and choose Open With....

  2. Choose Yes to save any changes when prompted.

  3. Select HTML/XML Editor from the list of editors and click Open.

  4. If the file was being edited in Prompt Function Editor, choose Yes to close the .pf file when prompted.

  5. In making the necessary changes to the file, ignore the warning not to hand-edit the file as long as there are edits only to the script in the body of prompt functions.

    Notes  

    • Modify only the function bodies contained in the commented-out block of XML markup at the top of the file. Do not edit any of the XML markup.
    • Do not change the function prototype of any prompt functions.
  6. Save and close the file.

  7. Re-open the file in Prompt Function Editor by double clicking on the .pf file in Solution Explorer, and then save the .pf file. This ensures that the actual script and the XML are synchronized.

Referencing Library Functions During Validation

A speech application can reference script files that contain library functions. References for use by the Web application at run time reside in script on the .aspx page, but during prompt coverage validation, references on the .aspx page are unavailable. Enter references for validating prompt coverage in the Includes for Validation text box.

To create a script reference for use during validation

Enter the file names of scripts in the Includes for Validation text box. Use semicolons as separators when adding more than one file name (for example, MyFunctions.js;MyOtherFunctions.js).

Writing Prompt Functions

Prompt Function Editor creates a wrapper function and an inner function for each function created in its interface. The application calls the wrapper function, and the inner function contains prompt selection logic added by the developer. The code displayed in Prompt Function Editor represents the inner function.

Wrapper functions on QA controls have one default parameter. The default parameter cannot be renamed or deleted.

Parameter Description
History Holds an array of strings representing the last user response (Command or exception—like Silence) for the currently active control. Possible values are a command or the exceptions Silence and NoReco. The number of elements in the array represents the number of user responses.

Inner functions have one default parameter, History; this parameter has the same value in an inner function as the History variable in a wrapper function. Unlike wrapper function parameters, the inner function default parameter can be deleted or renamed, and additional parameters can be added.

Wrapper functions added to Application Speech Controls have one default parameter. Like the parameter for wrapper functions on QA controls, the default parameter cannot be deleted or renamed. It is not passed to the inner function.

Parameter Description
clientControl A string containing information pertaining to the application control.

See Also

Prompting the User | Creating Prompts | Prompts