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

View File

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