Synthesizing Speech – Using Different Voices (Part 4)

by Mar 22, 2018

Windows 10 comes with excellent text-to-speech support and different high-quality voices. To find out which voices are available, try this:

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

$synthesizer.GetInstalledVoices().VoiceInfo | 
  Where-Object { $_.Name -notlike 'Microsoft Server*' } |
  Select-Object -Property Name, Gender, Age, Culture

The result looks similar to this (and depends on your Windows version, culture, and installed components):

 
Name                    Gender   Age Culture
----                    ------   --- -------
Microsoft Zira Desktop  Female Adult en-US  
Microsoft David Desktop   Male Adult en-US  
Microsoft Hedda Desktop Female Adult de-DE  
 

To try out these voices, use SelectVoice():

$sampleText = @{
    [System.Globalization.CultureInfo]::GetCultureInfo("en-us") = "Hello, I am speaking English! I am "
    [System.Globalization.CultureInfo]::GetCultureInfo("de-de") = "Halli Hallo, man spricht deutsch hier! Ich bin "
    [System.Globalization.CultureInfo]::GetCultureInfo("es-es") = "Una cerveza por favor! Soy "
    [System.Globalization.CultureInfo]::GetCultureInfo("fr-fr") = "Vive la france! Je suis "
    [System.Globalization.CultureInfo]::GetCultureInfo("it-it") = "Il mio hovercraft è pieno di anguille! Lo sono "
    
    
    }


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

$synthesizer.GetInstalledVoices().VoiceInfo | 
  Where-Object { $_.Name -notlike 'Microsoft Server*' } |
  Select-Object -Property Name, Gender, Age, Culture |
  ForEach-Object {
      $_
      $synthesizer.SelectVoice($_.Name)
      $synthesizer.Speak($sampleText[$_.Culture] + $_.Name)
  
  }

The voices available to you depend on the languages you installed. Here is a link explaining the voices that ship with Windows 10 for different languages:

https://support.microsoft.com/en-us/help/22797/windows-10-narrator-tts-voices. Note that not all of the installed voices are available via SelectVoice().

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!