1
0
mirror of https://github.com/fleschutz/PowerShell.git synced 2025-02-18 18:51:05 +01:00

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,20 +23,15 @@ function GetTempDir {
} }
try { try {
# print reply on the console: Write-Host '“'$text' ”' # to write the reply on the console
"$text"
# speak by text-to-speech (TTS):
if (!$IsLinux) { if (!$IsLinux) {
$TTSVoice = New-Object -ComObject SAPI.SPVoice $TTS = New-Object -ComObject SAPI.SPVoice
foreach ($Voice in $TTSVoice.GetVoices()) { foreach($Voice in $TTS.GetVoices()) {
if ($Voice.GetDescription() -like "*- English*") { $TTSVoice.Voice = $Voice } if ($Voice.GetDescription() -like "*- English*") { $TTS.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])"