Updated speak-countdown.ps1 and speak-english.ps1

This commit is contained in:
Markus Fleschutz 2024-11-20 11:50:21 +01:00
parent 5fb74da197
commit 2301e9a226
2 changed files with 7 additions and 7 deletions

View File

@ -3,24 +3,25 @@
Speaks a countdown by text-to-speech Speaks a countdown by text-to-speech
.DESCRIPTION .DESCRIPTION
This PowerShell script speaks a countdown by text-to-speech (TTS) starting from a given number. This PowerShell script speaks a countdown by text-to-speech (TTS) starting from a given number.
.PARAMETER StartNumber .PARAMETER startNumber
Specifies the number to start from (10 by default) Specifies the number to start from (10 by default)
.EXAMPLE .EXAMPLE
PS> ./speak-countdown.ps1 60 PS> ./speak-countdown.ps1 60
(listen and enjoy)
.LINK .LINK
https://github.com/fleschutz/PowerShell https://github.com/fleschutz/PowerShell
.NOTES .NOTES
Author: Markus Fleschutz | License: CC0 Author: Markus Fleschutz | License: CC0
#> #>
param([int]$StartNumber = 10) param([int]$startNumber = 10)
try { try {
for ([int]$i = $StartNumber; $i -gt 0; $i--) { for ([int]$i = $startNumber; $i -gt 0; $i--) {
& "$PSScriptRoot/speak-english.ps1" $i & "$PSScriptRoot/speak-english.ps1" $i
Start-Sleep -milliseconds 200 Start-Sleep -milliseconds 200
} }
& "$PSScriptRoot/speak-english.ps1" "zero" & "$PSScriptRoot/speak-english.ps1" "Zero and lift-off!"
exit 0 # success exit 0 # success
} catch { } catch {
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])" "⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"

View File

@ -22,11 +22,10 @@ try {
foreach ($voice in $TTS.GetVoices()) { foreach ($voice in $TTS.GetVoices()) {
if ($voice.GetDescription() -like "*- English*") { if ($voice.GetDescription() -like "*- English*") {
$TTS.Voice = $voice $TTS.Voice = $voice
[void]$TTS.Speak($text)
exit 0 # success
} }
} }
throw "No English text-to-speech voice found - please install one." [void]$TTS.Speak($text)
exit 0 # success
} catch { } catch {
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])" "⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
exit 1 exit 1