Windows built-in text-to-speech engine accepts plain text and turns it into a voice, but it can also be controlled using “Speech Synthesis Markup Language”. This way, you can fine-tune the voice, control pitch, and also language.

Windows ships with localized speech engines, so controlling the language is a good idea. Else, your (English) text may sound weird on a (German) system.

Add-Type -AssemblyName System.speech
$synthesizer = New-Object System.Speech.Synthesis.SpeechSynthesizer

$Text = '
<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>Normal pitch. </p>
        <p><prosody pitch="x-high"> High Pitch. </prosody></p>
    </prosody>
    </voice>
</speak>
'
$synthesizer.SpeakSsml($Text)

Depending on the installed speech engines, you can even switch between languages now:

Add-Type -AssemblyName System.speech
$synthesizer = New-Object System.Speech.Synthesis.SpeechSynthesizer

$Text1 = '
<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>Normal pitch. </p>
        <p><prosody pitch="x-high"> High Pitch. </prosody></p>
    </prosody>
    </voice>
</speak>
'

$text2 = '<speak version="1.0" xmlns="http://www.w3.org/2001/10/synthesis" 
    xml:lang="en-US">
    <voice xml:lang="de-de">
    <prosody rate="1">
        <p>Normale Tonhöhe. </p>
        <p><prosody pitch="x-high"> Höhere Tonlage. </prosody></p>
    </prosody>
    </voice>
</speak>'

$synthesizer.SpeakSsml($Text1)
$synthesizer.SpeakSsml($Text2)

If you’d like to mix languages in one text, you can also resort to the old COM object “Sapi.SpVoice”. This is taken from the previous tip:

$text = "<LANG LANGID=""409"">Your system will restart now!</LANG>
<LANG LANGID=""407""><PITCH MIDDLE = '2'>Oh nein, das geht nicht!</PITCH></LANG>
<LANG LANGID=""409"">I don't care baby</LANG>
<LANG LANGID=""407"">Ich rufe meinen Prinz! Herbert! Tu was!</LANG>
"

$speaker = New-Object -ComObject Sapi.SpVoice
$speaker.Rate = 0
$speaker.Speak($text)

Do you know PowerShell Conference EU 2018, taking place April 17-20 in Hanover, Germany? If you are an advanced PowerShell professional, you shouldn’t miss this year’s agenda: www.psconf.eu: Hover over a session to view its abstract.

With 45 international top speakers including PowerShell inventor Jeffrey Snover, 80 sessions, and workshops, this event is much more than just a conference. It is a one-of-a-kind Advanced PowerShell Training and a very unique opportunity to meet friendly PowerShell gurus, get authoritative answers to even the trickiest PowerShell questions, and bring home fresh ideas.

This conference is not profit-driven, and all speakers volunteer. The delegate fee basically covers venue, food and drinks throughout the conference, evening events with grand dinner, and workshops.

Just don’t wait too long: this unique event is limited to 300 delegates, with 280 seats already taken by the time of this writing. Visit http://www.powershellmagazine.com/2018/02/09/powershell-conference-eu-2018/ for more details, or www.powershell.love for a quick impression of last year.

Twitter This Tip! ReTweet this Tip!

Anonymous