PowerShell/Scripts/tell-joke.ps1
2021-11-27 14:16:50 +01:00

28 lines
688 B
PowerShell
Executable File

<#
.SYNOPSIS
Tells a joke by text-to-speech
.DESCRIPTION
This script selects a random Chuck Norris joke in Data/jokes.csv and speaks it by text-to-speech (TTS).
.EXAMPLE
PS> ./tell-joke
.NOTES
Author: Markus Fleschutz · License: CC0
.LINK
https://github.com/fleschutz/PowerShell
#>
try {
$Table = import-csv "$PSScriptRoot/../Data/jokes.csv"
$Generator = New-Object System.Random
$Index = [int]$Generator.next(0, $Table.Count - 1)
$Answer = $Table[$Index].Joke
& "$PSScriptRoot/speak-english.ps1" "$Answer"
write-output "$Answer"
exit 0 # success
} catch {
"⚠️ Error: $($Error[0]) ($($MyInvocation.MyCommand.Name):$($_.InvocationInfo.ScriptLineNumber))"
exit 1
}