Added speak-joke.ps1

This commit is contained in:
Markus Fleschutz 2021-02-06 18:13:12 +01:00
parent 69d86a33a9
commit cb6c6a3dec
3 changed files with 42 additions and 0 deletions

View File

@ -79,6 +79,7 @@ simulate-presence.ps1, simulates the human presence against burglars
speak-date.ps1, speaks the current date by text-to-speech (TTS) speak-date.ps1, speaks the current date by text-to-speech (TTS)
speak-epub.ps1, speaks the content of the given Epub file by text-to-speech (TTS) speak-epub.ps1, speaks the content of the given Epub file by text-to-speech (TTS)
speak-file.ps1, speaks the content of the given text file by text-to-speech (TTS) speak-file.ps1, speaks the content of the given text file by text-to-speech (TTS)
speak-joke.ps1, speaks the next joke by text-to-speech (TTS)
speak-test.ps1, performs a speak test by text-to-speech (TTS) speak-test.ps1, performs a speak test by text-to-speech (TTS)
speak-text.ps1, speaks the given text by text-to-speech (TTS) speak-text.ps1, speaks the given text by text-to-speech (TTS)
speak-time.ps1, speaks the current time by text-to-speech (TTS) speak-time.ps1, speaks the current time by text-to-speech (TTS)

1 Filename Description
79 speak-date.ps1 speaks the current date by text-to-speech (TTS)
80 speak-epub.ps1 speaks the content of the given Epub file by text-to-speech (TTS)
81 speak-file.ps1 speaks the content of the given text file by text-to-speech (TTS)
82 speak-joke.ps1 speaks the next joke by text-to-speech (TTS)
83 speak-test.ps1 performs a speak test by text-to-speech (TTS)
84 speak-text.ps1 speaks the given text by text-to-speech (TTS)
85 speak-time.ps1 speaks the current time by text-to-speech (TTS)

View File

@ -87,6 +87,7 @@ The following PowerShell scripts can be found in the [Scripts/](Scripts/) subfol
* [speak-date.ps1](Scripts/speak-date.ps1) - speaks the current date by text-to-speech (TTS) * [speak-date.ps1](Scripts/speak-date.ps1) - speaks the current date by text-to-speech (TTS)
* [speak-epub.ps1](Scripts/speak-epub.ps1) - speaks the content of the given Epub file by text-to-speech (TTS) * [speak-epub.ps1](Scripts/speak-epub.ps1) - speaks the content of the given Epub file by text-to-speech (TTS)
* [speak-file.ps1](Scripts/speak-file.ps1) - speaks the content of the given text file by text-to-speech (TTS) * [speak-file.ps1](Scripts/speak-file.ps1) - speaks the content of the given text file by text-to-speech (TTS)
* [speak-joke.ps1](Scripts/speak-joke.ps1) - speaks the next joke by text-to-speech (TTS)
* [speak-test.ps1](Scripts/speak-test.ps1) - performs a speak test by text-to-speech (TTS) * [speak-test.ps1](Scripts/speak-test.ps1) - performs a speak test by text-to-speech (TTS)
* [speak-text.ps1](Scripts/speak-text.ps1) - speaks the given text by text-to-speech (TTS) * [speak-text.ps1](Scripts/speak-text.ps1) - speaks the given text by text-to-speech (TTS)
* [speak-time.ps1](Scripts/speak-time.ps1) - speaks the current time by text-to-speech (TTS) * [speak-time.ps1](Scripts/speak-time.ps1) - speaks the current time by text-to-speech (TTS)

40
Scripts/speak-joke.ps1 Executable file
View File

@ -0,0 +1,40 @@
#!/snap/bin/powershell
<#
.SYNTAX ./speak-joke.ps1
.DESCRIPTION speaks the next joke by text-to-speech (TTS)
.LINK https://github.com/fleschutz/PowerShell
.NOTES Author: Markus Fleschutz / License: CC0
#>
function Speak { param([string]$Text)
write-progress "$Text"
$Voice = new-object -ComObject SAPI.SPVoice
$Voices = $Voice.GetVoices()
foreach ($OtherVoice in $Voices) {
$Description = $OtherVoice.GetDescription()
if ($Description -like "*- English (United States)") {
$Voice.Voice = $OtherVoice
break
}
}
[void]$Voice.Speak($Text)
write-progress -complete "$Text"
}
try {
$PathToRepo = "$PSScriptRoot/.."
$Table = import-csv "$PathToRepo/Data/jokes.csv"
$Generator = New-Object System.Random
$Index = [int]$Generator.next(0,66)
$Joke = $Table[$Index].Joke
[system.threading.thread]::currentthread.currentculture=[system.globalization.cultureinfo]"en-US"
Speak $Joke
exit 0
} catch {
write-error "ERROR in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
exit 1
}