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 10

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 3—Load the Company Matches
After the semantic item is filled, the CompanyOrTickerQA has now been satisfied, but we are still running on the client side. We need to make a few more checks, and to submit the page, so we specify in the property pages that when this QA is satisfied, and the OnClientComplete event is fired, we want a JScript function to run.

function SubmitTickerForSearch(eventSource, lastCommandOrException, count, semanticItemList) { userCanceled= false; CompanyOrTickerNav.Activate(); if(lastCommandOrException == "") SpeechCommon.Submit(); }

In the function SubmitTickerForSearch, we do three things:

  1. Reset userCanceled flag: If the user was in the context of the SelectableNavigator, and cancelled out, they would be sent back to the CompanyOrTickerQA with a slightly different prompt. This variable is what tells the CompanyOrTickerQA prompt function whether the user cancelled out of the navigator control; we reset that value here.
  2. Reactivate Navigator: If the user was in the context of the SelectableNavigator and selected a company, the navigator would have been deactivated. We therefore want to reactivate it in the case that the user is sent back to the first QA.
  3. Manually submit page: Although we could have used the semantic item's AutoPostBack feature, the page would post back every time the semantic item's state changed (i.e. "Empty," "NeedConfirmation," or "Confirmed"). Instead we manually submit the page if the lastCommandOrException parameter is blank.
Once our semantic item has been filled (and therefore its state is no longer "Empty"), we want to retrieve matching values from the database. In the LoadCompanies() function on the server, we decide which method to call and retrieve the data.

switch(siTicker.Attributes["ResponseType"]) { case "Company": dt= tickerObj.ListByCompany(AccountID, siTicker.Text.Replace(" amp ", " & ")); break; case "Ticker": dt= tickerObj.ListByTicker(AccountID, siTicker.Text); break; default: throw new ApplicationException(...)); }

We use the semantic item's "ResponseType" attribute, which we set in the Client Normalization Function SetResponseType, to determine if we received a match on a company or on a ticker. If we get an unrecognized value in "ResponseType," we manually throw an application exception.

Tip: In server-side code, reference a semantic item's attributes collection with an upper-case "A" (siTicker.Attributes); in client-side script, however, remember that it's a lower-case "a" (siTicker.attributes).



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