Share via


Prompt Functions

This content is no longer actively maintained. It is provided as is, for anyone who may still be using these technologies, with no warranties or claims of accuracy with regard to the most recent product version or service release.

In a Web-based voice response application, use Prompt Function Editor to write prompt functions that dynamically generate prompts based on the application's dialog flow.

Using Prompt Functions in Web-based Voice Response Applications

A flight booking system might, for example, 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.

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 described in the following table. The default parameter cannot be renamed or deleted.

Parameter Description

History

Holds an array of strings representing the last user response (Command or exception, such as 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 called clientControl. Like the parameter for wrapper functions on QA controls, the default parameter cannot be deleted or renamed. It is also not passed to the inner function.

Parameter Description

clientControl

A string containing information pertaining to the application control.

Achieving Natural-Sounding Output with Telephone Numbers

Authors want their applications to speak telephone numbers in a recorded voice. However, just recording the digits zero through nine and using them to construct phone numbers results in output that sounds strange and artificial. Clearly it is not reasonable to record all possible telephone numbers and then pick a whole recording each time. However, it is possible to produce much more natural output by recording the digits in each context that they appear in the final phone number.

For example, take the phone number (203) 535-3245. Each example of the digit three sounds very different because of its position in the phone number. People normally read phone numbers with a rising intonation for the first block, a relatively flat intonation during the second, and a falling intonation during the final block. The key to getting natural-sounding output is to capture each of the digits in every position in the phone number, tag these contextually different recordings appropriately, and use them to construct the final number. Thus, to make a reasonable capture of all the positional contexts, only 12 recordings are needed. An example of the required recordings is shown in the following list:

  • 321 230 1234
  • 132 302 4123
  • 213 023 3412
  • 654 879 2341
  • 465 798 5678
  • 546 987 8567
  • 987 546 7856
  • 798 465 6785
  • 879 654 9012
  • 023 213 2901
  • 302 132 1290
  • 230 321 0129

Next, identify each digit with a tag that can be easily constructed programmatically in the prompt functions. For example, the tag b3_4_9 refers to the digit nine in position four of the third block of numbers. The output of the prompt function is a string of the form <WITHTAG TAG=b1_1_2> 2 </WITHTAG> <WITHTAG TAG=b1_2_0> 0 </WITHTAG> and so on.

Note

This method only captures the positional context of the digits, not the coarticulatory affects of different bordering digits. For example, in natural speech the two in 206 and in 216 sounds slightly different because of the bordering digits.

Playing an Audio File in a Prompt

Use the Speech Application Language Tags (SALT) content element within prompt functions to play a .wav file. The content element is primarily used to refer to external content like .wav or SSML (Speech Synthesis Markup Language) files, but it can also hold optional inline or XML text that renders if there is a problem with the external content.

To use the content element in Prompt Function Editor, pass the .wav file path as a parameter and build the content element around it. For example, the following statement speaks the prompt "Your recording follows" and then plays the .wav file referenced by the file path parameter strPlayBackURL. If the .wav file is not available, the alternate prompt "I'm sorry, the recording wasn't found" plays.

return ("Your recording follows.<salt:content href=\"" + strPlayBackURL + "\">I'm sorry, the recording wasn't found.</salt:content>");

Overriding a Single Application Control Prompt

Application controls contain built-in prompts, which makes them immediately usable with little or no modification. However, sometimes changing built-in prompts can improve the dialog. This is easily done by writing a prompt select function for the application control. The prompt returned by the application control overrides the default prompt. However, authors want to change one of the built-in prompts only. This can be achieved by returning null from the prompt select function instead of a prompt. The application control then plays the built-in prompt. In the following code example (part of the prompt select function), the confirmation prompt is changed but the acknowledge prompt is not.

function NaturalNumber1_prompt_confirm (lastCommandOrException, count)
    {
          return ???Do you want to book a table for??? + GuestNumber.value + ???????;
    }
    
    function NaturalNumber1_prompt_acknowledge(lastCommandOrException, count)
    {
          return null;
    }

See Also

Other Resources

Prompt Functions in Web-based Voice Response Applications
Develop Prompts with Speech Prompt Tools