Step 1Prompt Functions and Grammar
The first step in the Buy Stock process is to tell the user what we want. We need to set up some text to be read to the user, so they know what question they are expected to answer. We do this by entering our text and our logic into a client-side
Each prompt function is responsible for determining what is said to a user based on certain criteria. Specifically, we want to read something different if the user says "Help," if the user just entered the page for the first time, or if the user has returned to this QA from a later question.
For BuyStock.aspx, we have one prompt function file that holds all of the prompt functions for all of the speech controls, named BuyStock.pf. Our first function, CompanyOrTickerQA_Prompt will ask the user which company they would like.
missingEntry, userCanceled, zeroMaxShares, company)
var help= "Please say the name of the company " +
"or spell the ticker " +
"symbol, leaving clear pauses between letters...";
var text= "Please say the name of the company " +
"or spell the ticker...";
text= "You canceled. " + text;
else if(missingEntry != null)
text= "I did not find any matches for the " +
"entry " + missingEntry +
". Please make a new entry to search again.";
text= "I understood " + company +
" . You do not have sufficient " +
"funds in your account to buy " +
"shares in this company...";
text= "To buy stock, " + text;
return PromptGenerator.Generate (
lastCommandOrException, count, text, help);
|NOTE: Some of the longer strings have been shortened in the above code sample to save space.
Since it is possible for the user to come back to this QA later, we have had to add some parameters to this prompt function, so that we know which text to prompt the user with.
Holds either null or a Ticker entry which the user entered, but which was not found (i.e. "ZZZZ"
Either true or false, indicating if the user is returning to this prompt after canceling out of the Selectable Navigator
Either true or false. If the user picks a company, and the code-behind determines that the user does not have enough money to buy even one share, we send the user back to this first QA, indicate that they cannot buy any shares, and ask them to enter another company name.
Holds a company name. Used with the zeroMaxShares
parameter, to tell the user which company they don't have enough money to buy.
We choose which text to send based on the values of the parameters, and then we call the PromptGenerator.Generate
function, which will determine if the user spoke one of the global commands, such as "Help," "Repeat," or "Instructions."
Next, we set up a Grammar file to define what phrases we expect the user to say (see Figure 5). Our grammar file contains a list of acceptable companies and their corresponding values, as well as a reference to a grammar rule for ticker symbols.
|Figure 5: The grammar file contains a list of acceptable companies and their corresponding values.|
When one of the choices is matched, the speech engine returns an SML document containing the name of the SML element matched, the text recognized, and the corresponding value. The SML element name and its corresponding value are set in the Assignments window of the grammar editor, as in Figure 5.
In our case, we wanted to set up two different SML element names, to distinguish whether the grammar matched a company name, or matched a ticker symbol. When the speech engine makes a match, it will return one of two SML documents, such as these:
<SML text="m. s. f. t." confidence="1.0">
<Ticker text="m. s. f. t."
<SML text="microsoft" confidence="1.0">
<Company text="microsoft" confidence="1.0">