Improve the scripts

This commit is contained in:
Markus Fleschutz
2021-04-08 13:27:03 +02:00
parent f18ff005f6
commit bb5bb64827
5 changed files with 18 additions and 19 deletions

View File

@ -1,7 +1,7 @@
#!/usr/bin/pwsh
<#
.SYNTAX speak-countdown.ps1 [start-number]
.DESCRIPTION speaks a countdown by text-to-speech (TTS)
.DESCRIPTION starts a countdown by text-to-speech (TTS)
.LINK https://github.com/fleschutz/PowerShell
.NOTES Author: Markus Fleschutz / License: CC0
#>
@ -11,8 +11,9 @@ param([int]$StartNumber = 10)
try {
for ([int]$i = $StartNumber; $i -gt 0; $i--) {
& "$PSScriptRoot/speak-english.ps1" $i
start-sleep -milliseconds 1000
start-sleep -milliseconds 200
}
& "$PSScriptRoot/speak-english.ps1" "zero"
exit 0
} catch {
write-error "ERROR: line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"

View File

@ -7,20 +7,19 @@
#>
param($Text = "")
if ($Text -eq "") { $Text = read-host "Enter the text to speak" }
if ("$Text" -eq "") { $Text = read-host "Enter the text to speak" }
try {
$Voice = new-object -ComObject SAPI.SPVoice
$Voices = $Voice.GetVoices()
foreach ($OtherVoice in $Voices) {
$Description = $OtherVoice.GetDescription()
if ($Description -like "*- English*") {
write-progress "$Text"
$Voice.Voice = $OtherVoice
[void]$Voice.Speak($Text)
write-progress -complete "$Text"
exit 0
}
if ($Description -notlike "*- English*") { continue }
# write-progress "$Text"
$Voice.Voice = $OtherVoice
[void]$Voice.Speak($Text)
# write-progress -complete "$Text"
exit 0
}
write-error "Sorry, no English text-to-speech (TTS) voice found"
exit 1

View File

@ -14,13 +14,12 @@ try {
$Voices = $Voice.GetVoices()
foreach ($OtherVoice in $Voices) {
$Description = $OtherVoice.GetDescription()
if ($Description -like "*- German*") {
write-progress "$Text"
$Voice.Voice = $OtherVoice
[void]$Voice.Speak($Text)
write-progress -complete "$Text"
exit 0
}
if ($Description -notlike "*- German*") { continue }
# write-progress "$Text"
$Voice.Voice = $OtherVoice
[void]$Voice.Speak($Text)
# write-progress -complete "$Text"
exit 0
}
write-error "No German text-to-speech (TTS) voice found"
exit 1