Search code examples
.netpowershelltext-to-speech

Listing and selecting installed voice (for text to speech)


As seen here (pardon the French UI), I have 3 text-to-speech voices installed on my computer:

enter image description here

However, when I run:

Add-Type -AssemblyName System.Speech
$speak = New-Object System.Speech.Synthesis.SpeechSynthesizer
$speak.GetInstalledVoices().VoiceInfo

It only returns "Microsoft Zira Desktop":

Gender                : Female
Age                   : Adult
Name                  : Microsoft Zira Desktop
Culture               : en-US
Id                    : TTS_MS_EN-US_ZIRA_11.0
Description           : Microsoft Zira Desktop - English (United States)
SupportedAudioFormats : {}
AdditionalInfo        : {[Age, Adult], [Gender, Female], [Language, 409], [Name, Microsoft Zira Desktop]...}

My goal is to be able to list all installed voices and then select one with PowerShell.

I'm really confused as to why the voices work and can be selected in the UI but not via PowerShell?


Solution

  • Thanks to Jeff Zeitlin for pointing me in the right direction!

    You have to copy voices to different paths within the registry. This script from GitHub does the trick :) Now all voices can be used and selected within PowerShell AND other third party programs!

    $sourcePath = 'HKLM:\software\Microsoft\Speech_OneCore\Voices\Tokens' #Where the OneCore voices live
    $destinationPath = 'HKLM:\SOFTWARE\Microsoft\Speech\Voices\Tokens' #For 64-bit apps
    $destinationPath2 = 'HKLM:\SOFTWARE\WOW6432Node\Microsoft\SPEECH\Voices\Tokens' #For 32-bit apps
    cd $destinationPath
    $listVoices = Get-ChildItem $sourcePath
    foreach($voice in $listVoices)
    {
    $source = $voice.PSPath #Get the path of this voices key
    copy -Path $source -Destination $destinationPath -Recurse
    copy -Path $source -Destination $destinationPath2 -Recurse
    }
    

    https://gist.github.com/hiepxanh/8b6ad80f6d620cd3eaaaa5c1d2c660b2

    Detailed explanation: https://www.reddit.com/r/Windows10/comments/96dx8z/how_unlock_all_windows_10_hidden_tts_voices_for/