diff --git a/Scripts/speak-english.ps1 b/Scripts/speak-english.ps1 index c6b15e47..d0e5bfb4 100755 --- a/Scripts/speak-english.ps1 +++ b/Scripts/speak-english.ps1 @@ -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 diff --git a/Scripts/speak-french.ps1 b/Scripts/speak-french.ps1 index adf90223..38374cd8 100644 --- a/Scripts/speak-french.ps1 +++ b/Scripts/speak-french.ps1 @@ -3,7 +3,6 @@ Speaks text with a French text-to-speech voice .DESCRIPTION This script speaks the given text with a French text-to-speech (TTS) voice. - Requires that a French TTS voice is installed. .PARAMETER text Specifies the text to speak .EXAMPLE @@ -19,15 +18,15 @@ param([string]$text = "") try { if ($text -eq "") { $text = read-host "Enter the French text to speak" } - $CurrentVoice = New-Object -ComObject SAPI.SPVoice - $Voices = $CurrentVoice.GetVoices() - foreach ($Voice in $Voices) { - if ($Voice.GetDescription() -notlike "*- French*") { 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 "*- French*") { + $TTSVoice.Voice = $Voice + [void]$TTSVoice.Speak($text) + 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 { "⚠️ Error: $($Error[0]) ($($MyInvocation.MyCommand.Name):$($_.InvocationInfo.ScriptLineNumber))" exit 1 diff --git a/Scripts/speak-german.ps1 b/Scripts/speak-german.ps1 index 01bd5c7d..68fe7107 100755 --- a/Scripts/speak-german.ps1 +++ b/Scripts/speak-german.ps1 @@ -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 { diff --git a/Scripts/speak-italian.ps1 b/Scripts/speak-italian.ps1 index e3f76b87..a63bd0b3 100755 --- a/Scripts/speak-italian.ps1 +++ b/Scripts/speak-italian.ps1 @@ -3,7 +3,6 @@ Speaks text with an Italian text-to-speech voice .DESCRIPTION This script speaks the given text with an Italian text-to-speech (TTS) voice. - Requires that an Italian TTS voice is installed. .PARAMETER text Specifies the text to speak .EXAMPLE @@ -19,15 +18,15 @@ param([string]$text = "") try { if ($text -eq "") { $text = read-host "Enter the Italian text to speak" } - $CurrentVoice = New-Object -ComObject SAPI.SPVoice - $Voices = $CurrentVoice.GetVoices() - foreach ($Voice in $Voices) { - if ($Voice.GetDescription() -notlike "*- Italian*") { 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 "*- Italian*") { + $TTSVoice.Voice = $Voice + [void]$TTSVoice.Speak($text) + 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 { "⚠️ Error: $($Error[0]) ($($MyInvocation.MyCommand.Name):$($_.InvocationInfo.ScriptLineNumber))" exit 1 diff --git a/Scripts/speak-spanish.ps1 b/Scripts/speak-spanish.ps1 index 87dd7db4..a056e33c 100755 --- a/Scripts/speak-spanish.ps1 +++ b/Scripts/speak-spanish.ps1 @@ -3,7 +3,6 @@ Speaks text with a Spanish text-to-speech voice .DESCRIPTION This script speaks the given text with a Spanish text-to-speech (TTS) voice. - Requires that a Spanish TTS voice is installed. .PARAMETER text Specifies the text to speak .EXAMPLE @@ -19,15 +18,15 @@ param([string]$text = "") try { if ($text -eq "") { $text = read-host "Enter the Spanish text to speak" } - $CurrentVoice = New-Object -ComObject SAPI.SPVoice - $Voices = $CurrentVoice.GetVoices() - foreach ($Voice in $Voices) { - if ($Voice.GetDescription() -notlike "*- Spanish*") { 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 "*- Spanish*") { continue } + $TTSVoice.Voice = $Voice + [void]$TTSVoice.Speak($text) + 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 { "⚠️ Error: $($Error[0]) ($($MyInvocation.MyCommand.Name):$($_.InvocationInfo.ScriptLineNumber))" exit 1