Update give-reply.ps1 and tell-joke.ps1

This commit is contained in:
Markus Fleschutz 2022-11-05 16:29:55 +01:00
parent 3ccce3044a
commit e40628bad2
2 changed files with 9 additions and 14 deletions

View File

@ -23,22 +23,17 @@ function GetTempDir {
}
try {
# print reply on the console:
"$text"
# speak by text-to-speech (TTS):
if (!$IsLinux) {
$TTSVoice = New-Object -ComObject SAPI.SPVoice
foreach ($Voice in $TTSVoice.GetVoices()) {
if ($Voice.GetDescription() -like "*- English*") { $TTSVoice.Voice = $Voice }
Write-Host '“'$text' ”' # to write the reply on the console
if (!$IsLinux) {
$TTS = New-Object -ComObject SAPI.SPVoice
foreach($Voice in $TTS.GetVoices()) {
if ($Voice.GetDescription() -like "*- English*") { $TTS.Voice = $Voice }
}
[void]$TTSVoice.Speak($text)
[void]$TTS.Speak($text)
}
# remember last reply:
"$text" > "$(GetTempDir)/last_reply_given.txt"
"$text" > "$(GetTempDir)/last_reply_given.txt" # to remember last reply
exit 0 # success
} catch {
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
exit 1
}
}

View File

@ -23,4 +23,4 @@ try {
} catch {
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
exit 1
}
}