Last active
May 22, 2021 07:59
-
-
Save carfesh/2b3c7492a007800f30c91fb72788b728 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Requires -RunAsAdministrator | |
# copy OneCore (mobile) voices into desktop voices so that they can be used via SAPI | |
# mobile voices should only be converted if a desktop voice of the same friendly name does not exist | |
$ErrorActionPreference = 'Stop' | |
Set-StrictMode -Version 2 | |
$VoicesPath = '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 | |
$64BitDesktopVoices = @{} | |
$DesktopVoices = Get-ChildItem $destinationPath | |
ForEach($DesktopVoice In $DesktopVoices) { | |
$Name = $DesktopVoice.Name | |
If($DesktopVoice.Name -Match "\\TTS_MS_[A-Z]{2}-[A-Z]{2}_([A-Z]+)_\d{2}\.\d$") { | |
$VoiceFriendlyName = $Matches[1] | |
$64BitDesktopVoices.Add($VoiceFriendlyName, "") | |
} ElseIf($DesktopVoice.Name -Match "\\MSTTS_V\d+_[a-zA-z]{4}_([a-zA-Z]+)M$") { | |
$VoiceFriendlyName = $Matches[1] | |
Write-Warning "Ignoring converted mobile voice $VoiceFriendlyName..." | |
} | |
Else { | |
Throw "Unknown desktop voice naming scheme, aborting." | |
} | |
} | |
$Voices = Get-ChildItem $VoicesPath | |
ForEach($Voice in $Voices) { | |
If($Voice.Name -Match "\\MSTTS_V\d+_[a-zA-z]{4}_([a-zA-Z]+)M$") { | |
$VoiceFriendlyName = $Matches[1] | |
If(-Not($64BitDesktopVoices.ContainsKey($VoiceFriendlyName))) { | |
$NewKey = Join-Path -Path destinationPath -ChildPath $Voice.Name | |
If(-Not(Test-Path $NewKey)) { | |
Write-Output "Copying voice $VoiceFriendlyName to 64 bit key..." | |
Copy-Item -Path $Voice.PSPath -Destination $destinationPath -Recurse | |
} | |
$NewKey2 = Join-Path -Path destinationPath2 -ChildPath $Voice.Name | |
If(-Not(Test-Path $NewKey2)) { | |
Write-Output "Copying voice $VoiceFriendlyName to 32 bit key..." | |
Copy-Item -Path $Voice.PSPath -Destination $destinationPath2 -Recurse | |
} | |
} | |
Else { | |
Write-Warning "Ignoring voice $VoiceFriendlyName as desktop voice of the same name already exists." | |
} | |
} | |
Else { | |
Throw "Unknown OneCore voice naming scheme, aborting." | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment