Speech-Week: Using Advanced Speech Synthesizer Options Synthesizer

The .NET speech engine accepts more than just plain text. If you use SpeakSsml() instead of Speak(), you can use XML to switch languages, speak rate, and other parameters within a text.

The following example requires both an English and a German voice installed. If you don’t have a German voice installed, change the language ID in the script appropriately. Here is how you find out the language IDs available on your system:

 
PS C:\> Add-Type -AssemblyName System.Speech 

PS C:\> $speak.GetInstalledVoices() | Select-Object -ExpandProperty VoiceInfo | Select-Object -ExpandProperty Culture | Sort-Object -Unique

LCID             Name             DisplayName                                                                                         
----             ----             -----------                                                                                         
1031             de-DE            German (Germany)                                                                                    
1033             en-US            English (United States)
 

And here is the full example:

#requires -Version 2.0
Add-Type -AssemblyName System.Speech
$speak = New-Object System.Speech.Synthesis.SpeechSynthesizer
$ssml = '
<speak version="1.0" xmlns="http://www.w3.org/2001/10/synthesis" 
    xml:lang="en-US">
    <voice xml:lang="en-US">
    <prosody rate="1">
        <p>I can speak English!</p>
    </prosody>
    </voice>
    <voice xml:lang="de-DE">
    <prosody rate="1">
        <p>und ich kann auch deutsch sprechen!</p>
    </prosody>
    </voice>
    <voice xml:lang="en-US">
    <prosody rate="0">
        <p>...and sometimes I get really tired.</p>
    </prosody>
    </voice>
</speak>
'

$speak.SpeakSsml($ssml)

Twitter This Tip! ReTweet this Tip!