-
-
Notifications
You must be signed in to change notification settings - Fork 546
Expand file tree
/
Copy pathtell-joke.ps1
More file actions
executable file
·26 lines (23 loc) · 683 Bytes
/
tell-joke.ps1
File metadata and controls
executable file
·26 lines (23 loc) · 683 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
<#
.SYNOPSIS
Tells a random joke by text-to-speech
.DESCRIPTION
This PowerShell script selects a random Chuck Norris joke from data/jokes.csv and speaks it by text-to-speech (TTS).
.EXAMPLE
PS> ./tell-joke.ps1
(listen and enjoy)
.LINK
https://github.com/fleschutz/PowerShell
.NOTES
Author: Markus Fleschutz | License: CC0
#>
try {
$table = Import-CSV "$PSScriptRoot/data/jokes.csv"
$randomNumberGenerator = New-Object System.Random
$row = [int]$randomNumberGenerator.next(0, $table.count - 1)
& "$PSScriptRoot/speak-english.ps1" $table[$row].Joke
exit 0 # success
} catch {
"⚠️ ERROR: $($Error[0]) (script line $($_.InvocationInfo.ScriptLineNumber))"
exit 1
}