Improve the speak-*.ps1 scripts

This commit is contained in:
Markus Fleschutz
2021-11-27 14:37:44 +01:00
parent 71b72611b7
commit 81edcadf1f
5 changed files with 37 additions and 40 deletions

View File

@ -20,12 +20,13 @@ try {
$TTSVoice = New-Object -ComObject SAPI.SPVoice
foreach ($Voice in $TTSVoice.GetVoices()) {
if ($Voice.GetDescription() -notlike "*- English*") { continue }
$TTSVoice.Voice = $Voice
[void]$TTSVoice.Speak($text)
exit 0 # success
if ($Voice.GetDescription() -like "*- English*") {
$TTSVoice.Voice = $Voice
[void]$TTSVoice.Speak($text)
exit 0 # success
}
}
throw "No English text-to-speech voice found - please install one"
throw "No English text-to-speech voice found - please install one."
} catch {
"⚠️ Error: $($Error[0]) ($($MyInvocation.MyCommand.Name):$($_.InvocationInfo.ScriptLineNumber))"
exit 1