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

@ -3,7 +3,6 @@
Speaks text with a German text-to-speech voice
.DESCRIPTION
This script speaks the given text with a German text-to-speech (TTS) voice.
Requires that a German TTS voice is installed.
.PARAMETER text
Specifies the text to speak
.EXAMPLE
@ -19,13 +18,13 @@ param([string]$text = "")
try {
if ($text -eq "") { $text = read-host "Enter the German text to speak" }
$CurrentVoice = New-Object -ComObject SAPI.SPVoice
$Voices = $CurrentVoice.GetVoices()
foreach ($Voice in $Voices) {
if ($Voice.GetDescription() -notlike "*- German*") { continue }
$CurrentVoice.Voice = $Voice
[void]$CurrentVoice.Speak($text)
exit 0 # success
$TTSVoice = New-Object -ComObject SAPI.SPVoice
foreach ($Voice in $TTSVoice.GetVoices()) {
if ($Voice.GetDescription() -like "*- German*") {
$TTSVoice.Voice = $Voice
[void]$TTSVoice.Speak($text)
exit 0 # success
}
}
throw "No German text-to-speech voice found - please install one"
} catch {