Like speech recognition, TTS also requires the ID_CAP_SPEECH_RECOGNITION capability. The capability must present in the WMAppManifest.xml file.
The SpeechSynthesizer
class is the main class for achieving TTS. The class exists in the Windows.Phone.Speech.Synthesis namespace.
Out of the box, the speech synthesizer is able to speak using a default voice, as shown:
SpeechSynthesizer synthesizer = new SpeechSynthesizer();
synthesizer.SpeakTextAsync("Hi from Windows Phone!");
The SDK’s speech synthesizer is able to speak using a variety of languages, as spoken in a specific country or regions. See Table 23.1 for the list of speech supported country and region codes.
If no language is specified, the speech synthesizer uses a voice that matches the language that the user has selected in Settings/Speech page on the phone.
In addition to the language and region, the gender of the voice can be specified, effectively doubling the number of speaking voices available.
A speaking voice can be selected by locating a particular voice from the InstalledVoices.All
collection, and then assigning it to the SpeechSynthesizer
using its SetVoice
method.
The following example creates an instance of a speech synthesizer and sets its language and gender. A LINQ query is used to retrieve a male English (Great Britain) speaking voice.
SpeechSynthesizer synthesizer = new SpeechSynthesizer();
VoiceInformation gbVoice = (from voice in InstalledVoices.All
where voice.Language == "en-GB"
&& voice.Gender == VoiceGender.Male
select voice).First();
synthesizer.SetVoice(gbVoice);
Note
The voice selection not only affects the character and intonation of the spoken words, but also, in some cases, what is said. For example, when using the U.S. English voice (en-US), the synthesizer knows that 32°C should be pronounced 32 degrees Celsius. The GB English voice fails to do to this and skips the °C altogether. The author’s guess is that it is because the U.S. voice has had more effort spent on it.
18.223.238.171