mirror of
https://github.com/fleschutz/PowerShell.git
synced 2024-11-23 00:13:36 +01:00
Added speak-joke.ps1
This commit is contained in:
parent
69d86a33a9
commit
cb6c6a3dec
@ -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)
|
||||||
|
|
@ -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
40
Scripts/speak-joke.ps1
Executable 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
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user