The market for Windows Phone apps extends across many countries and regions. Supporting other languages is sometimes critical to effectively monetizing your app. Fortunately, the speech features of the Windows Phone SDK make it possible for you to provide speech capabilities for numerous languages.
In this section we look at selecting a language and region-specific speech recognizer to recognize speech in a non-English language.
The sample for this section is located in the Speech/NonEnglishRecognizer directory of the WPUnleashed.Examples project in the downloadable sample code.
Windows Phone 8 supports speech recognition and Text-to-Speech (TTS) for the languages and regions in Table 23.1.
A default speech recognizer language is selected automatically by the OS, depending on the language settings of the device. You can, however, substitute a different language by calling SetRecognizer
on the SpeechRecognizer
instance. A language-specific SpeechRecognizerInformation
can be retrieved from the static InstalledSpeechRecognizers.All
property, as shown in Listing 23.12.
SpeechRecognizerUI GetSpeechRecognizerUI()
{
if (recognizerUI == null)
{
recognizerUI = new SpeechRecognizerUI();
recognizerUI.Settings.ReadoutEnabled = true;
IEnumerable<SpeechRecognizerInformation> frenchRecognizers
= from recognizerInfo in InstalledSpeechRecognizers.All
where recognizerInfo.Language == "fr-FR"
select recognizerInfo;
recognizerUI.Recognizer.SetRecognizer(frenchRecognizers.Single());
/* Create a list grammar from the string array
* and add it to the grammar set. */
recognizerUI.Recognizer.Grammars.AddGrammarFromList(
"frenchNumbers", frenchNumbers);
}
return recognizerUI;
}
In this example, a list grammar is used to define the set of words that the speech recognizer listens for. The viewmodel contains the following array of numbers in French:
readonly string[] frenchNumbers = { "un", "deux", "trois", "quatre", "cinq",
"six", "sept", "huit", "neuf", "dix" };
The use of a speech recognizer that has been initialized for a nondefault language remains the same. The ListenText
and ExampleText
properties of the recognizer’s Settings
should be set to strings in the applicable language. See Listing 23.13.
async void Prompt()
{
SpeechRecognizerUI recognizer = GetSpeechRecognizerUI();
recognizer.Settings.ListenText = "Say a French number.";
recognizer.Settings.ExampleText = " 'un', 'deux', 'trois', 'quatre' ";
SpeechRecognitionUIResult uiResult = await recognizer.RecognizeWithUIAsync();
if (uiResult.ResultStatus == SpeechRecognitionUIStatus.Succeeded)
{
RecognizedText = uiResult.RecognitionResult.Text;
}
}
There is no limit placed on combining different languages in your app, which allows you to build rich, multilingual applications.
18.224.52.200