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 $TTSVoice = New-Object -ComObject SAPI.SPVoice
foreach ($Voice in $TTSVoice.GetVoices()) { foreach ($Voice in $TTSVoice.GetVoices()) {
if ($Voice.GetDescription() -notlike "*- English*") { continue } if ($Voice.GetDescription() -like "*- English*") {
$TTSVoice.Voice = $Voice $TTSVoice.Voice = $Voice
[void]$TTSVoice.Speak($text) [void]$TTSVoice.Speak($text)
exit 0 # success 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 { } catch {
"⚠️ Error: $($Error[0]) ($($MyInvocation.MyCommand.Name):$($_.InvocationInfo.ScriptLineNumber))" "⚠️ Error: $($Error[0]) ($($MyInvocation.MyCommand.Name):$($_.InvocationInfo.ScriptLineNumber))"
exit 1 exit 1

View File

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

View File

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

View File

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

View File

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