Creating a Speech Synthesis Markup Language File

,

In addition to allowing TTS with strings, the speech synthesizer allows you to define speech using the Speech Synthesis Markup Language (SSML). SSML offers a powerful language for authoring TTS scripts.

The structure of an SSML document consists of a root speak element, which has an xml:lang attribute that determines the default speaking voice used. See Listing 23.18.

Voice elements define sections of speech that allow the speaking voice to be customized, including gender and language.

The stress and intonation of the speech can be modified using the prosody element, allowing you to vary the volume and pitch of a word or speech fragment. For more detailed information on the prosody element, see http://www.w3.org/TR/speech-synthesis/#edef_prosody.

Mark elements cause an event to be raised by the speech synthesizer when they are encountered during speech output. This can be useful if you need to synchronize some UI elements with points in the script.

LISTING 23.18. IntroductionSsml.xml


<?xml version="1.0" encoding="utf-8" ?>
<speak version="1.0" xmlns="http://www.w3.org/2001/10/synthesis" xml:lang="en-GB">

  <voice gender="female">
    Welcome to the Weather Voice sample.
  </voice>

  <voice gender="male" xml:lang="en-US">
    To activate this sample hold down the hardware Windows button
    and say something like: <mark name="ExampleStart"/>
    <prosody volume="loud" pitch="-20Hz">Weather for Zurich Switzerland</prosody>.
    <mark name="ExampleEnd"/>
  </voice>

  <voice gender="female" xml:lang="fr-FR">
    J'espère que vous appréciez le livre!
  </voice>

</speak>


The sample VoiceCommandViewModel class uses the script in Listing 23.18 to greet the user when the user navigates to the page. During synthesis, the BookmarkReached event is raised when a mark element is encountered. The SpeakSsmlFromUriAsync method loads the SSML file and outputs the spoken text, as shown in the following excerpt:

SpeechSynthesizer synthesizer = new SpeechSynthesizer();
synthesizer.BookmarkReached
    += delegate(SpeechSynthesizer sender, SpeechBookmarkReachedEventArgs args)
    {
        TextHighlighted = args.Bookmark == "ExampleStart";
    };
string path = "ms-appx:///Speech/VoiceCommands/IntroductionSsml.xml";
synthesizer.SpeakSsmlFromUriAsync(new System.Uri(path, UriKind.Absolute));

In addition to the SpeakSsmlFromUriAsync method, the SpeechSynthesizer is also able to speak a string of SSML that you provide as an argument to the SpeakSsmlAsync method.

The Boolean TextHighlighted property is used in the view to change the color of the example text from the SSML file. A custom IValueConverter named BooleanToBrushConverter (presented in Chapter 9, “Enriching the User Experience with the Windows Phone Toolkit Controls”) converts the Boolean value of the property to a brush.

<TextBlock Foreground="{Binding TextHighlighted,
                       Converter={StaticResource BooleanToBrushConverter}}">
                    "Weather for Zurich Switzerland"</TextBlock>

The BooleanToBrushConverter is declared in the page resources as shown:

<phone:PhoneApplicationPage.Resources>
    <ValueConverters:BooleanToBrushConverter x:Name="BooleanToBrushConverter"
            BrushIfFalse="{StaticResource PhoneForegroundBrush}"
            BrushIfTrue="{StaticResource PhoneAccentBrush}" />
</phone:PhoneApplicationPage.Resources>

When the speech synthesizer reaches the text “Weather for Zurich Switzerland,” the same text is highlighted using the phone’s accent color. See Figure 23.3.

Image

FIGURE 23.3 Example text is highlighted using a Mark element.

SSML gives you precise control over how text is spoken, including language, gender, and intonation; bookmarks enable you to coordinate and synchronize screen elements with your speech output.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.116.67.177