Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


advertisement
 

Buy and Sell Stocks with the Sound of Your Voice Using the .NET Speech SDK : Page 12

Some applications are even more useful when people can interact with them using nothing but a telephone. We used the .NET Speech SDK to voice-enable the existing FMStocks sample application—and learned some useful lessons along the way.


advertisement
Step 7 - Confirmation
Now that the company has been selected, and the siTicker semantic item has been set, we want to confirm with the user that we have the right company name.

We use the "Confirms" tab in the SelectedTickerConfirm control to both confirm whether the company name is correct, but also to accept a different answer if they say "No." For example, the user is prompted, "I understood Yahoo! Inc., is that correct?" and replies "No, Microsoft Corporation." "Microsoft Corporation" is now filled in to siTicker (see Figure 7).

Figure 7: The "Confirms" tab in the SelectedTickerConfirm control contains information about confirming company names.
We do not use the Extra Answers tab here, because we are not asking for an additional answer; rather we are asking for a replacement to the answer we already have.

//SelectedTickerConfirm OnClientComplete function SubmitOnDenyCompany(eventSource, lastCommandOrException, count, semanticItemList) { if(siTicker.NeedsConfirmation() && lastCommandOrException == "") SpeechCommon.Submit(); }

In the case where the user rejects the company confirmation, the page is submitted manually. The server-side LoadCompanies function begins again, as the user may have specified a different company or ticker, and the possible company match list will have to be retrieved from the database for these new criteria.

If the user accepts the company choice, the semantic item's state is set to "Confirmed," and we move on to the next QA while remaining on the client.

In-Depth: Buy Stock Feature—Extra Answers
In the Buy Stock process, after the user has placed the order, the user is given the option to buy more stock. At this point, we use the Speech SDK's Extra Answers feature to allow expert users to quickly place more orders.

Without the use of Extra Answers, the user replays the entire Buy Stock process:

[prompt] "Do you want to buy more stock?" [user] "Yes." [prompt] "Please say the name of the company or spell the ticker symbol you are interested in." [user] "Microsoft." [prompt] "I understood Microsoft Corporation, is this correct?" [user] "Yes." [prompt] "How many shares would you like to purchase?" [user] "Four." [prompt] "I understood Microsoft Corporation, is this correct?" [user] "Yes." [prompt] "I understood four shares, is this correct?" [user] "Yes." [prompt] "So you want to purchase four shares of Microsoft Corporation. Would you like to complete this order?" [user] "Yes."

With Extra Answers, the conversation is much simpler:



[prompt] "Do you want to buy more stock?" [user] "Yes, I would like four shares of Microsoft Corporation." [prompt] "So you want to purchase four shares of Microsoft Corporation. Would you like to complete this order?" [user] "Yes."

The Extra Answers feature (see Figure 8) works like regular Answers, but it doesn't have to be filled for the QA to complete.

Figure 8: The Extra Answers feature works like regular Answers, but it doesn't have to be filled for the QA to complete.
Semantic items siTicker and siNumberOfShares are added to the Extra Answers collection of the BuyMoreQA control, so that when any of the SML elements "Ticker," "Company," or "NumberOfShares" are matched, the appropriate semantic item is automatically filled.

We also must handle the case if the user indicates that they are done (by saying "no"), as well as set the confirmation status of the semantic items that they do fill in should they say "yes." We add an OnClientComplete function for the BuyMoreQA control to handle these cases.

Important: The fact that we are at the last QA on the page implies that the siTicker and siNumberOfShares semantic items are in a CONFIRMED state. If the user supplies these as extra answers, they will go from a state of CONFIRMED to a state of NEEDSCONFIRMATION. This will activate the confirmation QAs for these semantic items; we don't want this. Instead, we want to immediately proceed to the order confirmation QA. We set semantic item states in the OnClientComplete EventHandler for the BuyMoreQA:

// BuyMoreQA OnClientComplete function GoToMainMenuIfNo(eventSource, lastCommandOrException, count, semanticItemList) { if(lastCommandOrException == "") { if(siBuyMore.value == "No") Goto("MainMenu.aspx"); else { siBuyMore.Clear(); siOrder.Clear(); if(siNumberOfShares.IsConfirmed()) siNumberOfShares.Clear(); else siNumberOfShares.Confirm(); if(siTicker.IsConfirmed()) siTicker.Clear(); else { siTicker.Confirm(); SpeechCommon.Submit(); } } } }

In this code snippet, the case "no" is straightforward. If the user responds "no" to the question "Do you want to buy more stock?", the user is redirected to the Main Menu.

If the user says "yes," we take the following actions:

  • Clear siBuyMore and siOrder: Clear out the last two QA's (by clearing their corresponding semantic items) so that they will run again.
  • Check answer for siNumberOfShares: See if the user said the number of shares that they want. Because of the way the Extra Answers feature has been set up, we can do this by checking the semantic state.
  • If the user did not say anything, siNumberOfShares would still be confirmed from the purchase that was just completed. We then manually clear the semantic item, so that on the next loop, the user will be prompted to enter the number of shares.
  • If the user did give a number, the semantic item's state would change to "NeedConfirmation." We then manually set the item's state to "Confirmed" because we do not want to run the control NumberOfSharesConfirm.
  • Check answer for siTicker: Next, we see if the user has entered a new company. Take the same logic with setting the semantic state as above.
  • Manually submit the page: Finally, if the user did specify a new company name, submit the page so that the server-side LoadCompanies method can retrieve the possible company match list from the database using these new criteria.


Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date