Update tell-quote.ps1

This commit is contained in:
Markus Fleschutz 2023-08-09 17:18:53 +02:00
parent 937739e4a1
commit 7055e9fef5

View File

@ -2,9 +2,10 @@
.SYNOPSIS
Tells a quote by text-to-speech
.DESCRIPTION
This PowerShell script selects a random quote in Data/quotes.csv and speaks it by text-to-speech (TTS).
This PowerShell script selects a random quote from Data/quotes.csv and speaks it by text-to-speech (TTS).
.EXAMPLE
PS> ./tell-quote
PS> ./tell-quote.ps1
(listen and enjoy)
.LINK
https://github.com/fleschutz/PowerShell
.NOTES
@ -12,14 +13,14 @@
#>
try {
$Table = Import-CSV "$PSScriptRoot/../Data/quotes.csv"
$table = Import-CSV "$PSScriptRoot/../Data/quotes.csv"
$Generator = New-Object System.Random
$Index = [int]$Generator.next(0, $Table.Count - 1)
$Quote = $Table[$Index].QUOTE
$Author = $Table[$Index].AUTHOR
$randomNumberGenerator = New-Object System.Random
$row = [int]$randomNumberGenerator.next(0, $table.Count - 1)
$quote = $table[$row].QUOTE
$author = $table[$row].AUTHOR
& "$PSScriptRoot/speak-english.ps1" "$Quote (by $Author)"
& "$PSScriptRoot/speak-english.ps1" "$quote (by $author)"
exit 0 # success
} catch {
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"