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 4

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
Common Files: Client-Side Scripting
The globally scoped client-side script files for the application are:

  • Speech.js: NoReco/Silence event handler and object accessors
  • Routines.js: String-formatting routines
  • Debug.js: Client-side debugging utilities
  • FMStocks7V.js: Global Navigation Event Handlers
  • PromptGenerator.js: Prompt Generation Utility
A few of the more interesting functions of these scripts are outlined below:

HandleNoRecoAndSilence (Speech.js): HandleNoRecoAndSilence takes care of handling cases where the user repeatedly responds to a prompt with silence or with an unrecognizable input. To avoid frustration, we don't want to repeat the same prompt over and over again. This function, executed each time a QA is made active, counts the number of consecutive times the input is invalid. It increments a counter that the prompt generation utility (see below) uses to generate an appropriate prompt. If the count exceeds a maximum (in this application, 3), we redirect the user to a Customer Service Representative.

This function is defined as the OnClientActive event handler for the BaseQAStyle in the GlobalSpeechElement's MainStyleSheet. Each QA that accepts user input must use this style in order for the function to be called correctly.

function HandleNoRecoAndSilence( eventSource, lastCommandOrException, count, semanticItemList) { if (count == 1) PromptGenerator.noRecoOrSilenceCount = 0; if (lastCommandOrException == "Silence" || lastCommandOrException == "NoReco") { PromptGenerator.noRecoOrSilenceCount++; if (PromptGenerator.noRecoOrSilenceCount >= representativeXferCount) Goto(representativeXferPage); } else { PromptGenerator.noRecoOrSilenceCount = 0; } }

Navigator Functions (Speech.js)
Speech.js contains the following functions to make working with the Navigator application control easier:

ActivateNavigator(navigatorName, active): In the Speech SDK, speech-controls are activated and deactivated by modifying the semantic state of the control's associated Semantic Item. The same is true for Navigator application controls, though the semantic item is hidden from the user. In order to make activation and deactivation of Navigators simpler, we created a function that sets the Navigator's "ExitSemanticItem" to some dummy value. If the value is empty, the Navigator is activated. If not, the Navigator is inactive.

function ActivateNavigator(navigatorName, active) { var si = eval (navigatorName + "_ExitSemanticItem"); if(active || arguments.length == 1) si.Clear(); else si.SetText("x", true); // value can be anything return active; }

GetNavigator(navigatorName): Returns a Navigator object reference given its name as a string.

GetNavigatorCount(navigatorName): Returns the count of items in the given navigator.

GetNavigatorData(navigatorName, columnName): Returns the data contained in the currently-selected row of the specified navigator's specified column.

GetNavigatorQA(navigatorName): Returns a reference to a Navigator's internal QA control.

Prompt Generation (PromptGenerator.js)
Prompt Generation is perhaps the most central element when creating a successful voice-only application. Providing a consistent voice interface is essential to creating a successful user experience. PromptGenerator.js does just this by encapsulating all common prompt-generation functionality in one place.

A prompt function in a typical page will always return the result of a call PromptGenerator.Generate() as its prompt:



return PromptGenerator.Generate( lastCommandOrException, count, "Prompt Text Here", "Help Text Here" );

Notice that the prompt function passes both its main prompt and its help prompt into the function every time. PromptGenerator.Generate() decides the appropriate prompt to play given the current lastCommandOrException, the NoReco/Silence state (see HandleNoRecoAndSilence, above), and other factors:

function PromptGenerator.Generate(lastCommandOrException, count, text, help) { help += " You can always say Instructions " + "for more options." switch (lastCommandOrException) { case "NoReco": if (PromptGenerator.noRecoOrSilenceCount > 1) return "Sorry, I still don't understand you." + help; else return "Sorry, I am having trouble " + "understanding you. " + "If you need help, say help. " + text; case "Silence": if (PromptGenerator.noRecoOrSilenceCount > 1) return "Sorry, I still don't hear you. " + help; else return "Sorry, I am having trouble " + "hearing you. " + "If you need help, say help. " + text; case "Help": PromptGenerator.RepeatPrompt = help; return help; case "Instructions": var instructionsPrompt = "Okay, here are a few instructions..."; PromptGenerator.RepeatPrompt = instructionsPrompt + text; return instructionsPrompt; case "Repeat": return "I repeat: " + PromptGenerator.RepeatPrompt; default: PromptGenerator.RepeatPrompt = text; return text; } }

Note: Some of the longer strings have been shortened in the above code sample to save space.

A note on "Repeat": The PromptGenerator.RepeatPrompt variable stores the current text that will be read if the user says, "Repeat." The first time the function is executed for any prompt, the RepeatPrompt will be set to the standard text. The RepeatPrompt is then only reset when the user says, "Help," or "Instructions."

Other PromptGenerator functions: PromptGenerator also includes a few other functions for generating prompts in the application. They include:

GenerateNavigator(lastCommandOrException, count, text, help): This function adds to the functionality of Generate() by including standard prompts commonly needed while in a Navigator control. These prompts include additional help text and messages for when the user tries to navigate beyond the boundaries of the navigator.

ConvertNumberToWords(number, isMoney): In order to generate recorded prompts for all possible number values, we must convert numbers (i.e. 123,456) to a readable string (i.e. "one hundred twenty three thousand four hundred fifty six). This reduces the number of unique words that must be recorded to a manageable amount.



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