Updated speak-checklist.ps1

This commit is contained in:
Markus Fleschutz 2024-11-24 21:00:34 +01:00
parent db0169521b
commit e74c9f1010

View File

@ -3,31 +3,46 @@
Speaks a checklist by text-to-speech Speaks a checklist by text-to-speech
.DESCRIPTION .DESCRIPTION
This PowerShell script speaks the given checklist by text-to-speech (TTS). This PowerShell script speaks the given checklist by text-to-speech (TTS).
.PARAMETER Name .PARAMETER name
Specifies the name of the checklist Specifies the name of the checklist
.EXAMPLE .EXAMPLE
PS> ./speak-checklist.ps1 PS> ./speak-checklist.ps1 handwashing
.LINK .LINK
https://github.com/fleschutz/PowerShell https://github.com/fleschutz/PowerShell
.NOTES .NOTES
Author: Markus Fleschutz | License: CC0 Author: Markus Fleschutz | License: CC0
#> #>
param([string]$Name = "") param([string]$name = "handwashing")
function WaitForCheck {
Add-Type -AssemblyName System.Speech
$engine = New-Object -typeName System.Speech.Recognition.SpeechRecognitionEngine
$grammar = New-Object -typeName System.Speech.Recognition.GrammarBuilder
$grammar.Append("check");
$engine.LoadGrammar($grammar);
$engine.InitialSilenceTimeout = 5
$engine.SetInputToDefaultAudioDevice();
do {
$recognized = $engine.Recognize();
} while ("$($recognized.text)" -ne "check")
}
try { try {
if ($Name -eq "") { $Name = Read-Host "Enter the name of the checklist" } if ($name -eq "") { $name = Read-Host "Enter the name of the checklist" }
$Lines = Get-Content -path "$PSScriptRoot/../data/checklists/$Name.txt"
clear-host
$Step = 1
foreach($Line in $Lines) {
if ($Line -like "HEAD*") { & "$PSScriptRoot/write-big.ps1" "$($Line.substring(5))"; continue }
Clear-Host
$lines = Get-Content -path "$PSScriptRoot/../data/checklists/$name.txt"
$step = 1
foreach($line in $lines) {
if ($line -like "HEAD*") { & "$PSScriptRoot/write-big.ps1" "$($line.substring(5))"; continue }
"" ""
& "$PSScriptRoot/speak-english.ps1" "$($Step). $Line" Write-Host "$($step). $line" -foregroundColor yellow
$Dummy = Read-Host " Say <Check> or press <Return> to continue" & "$PSScriptRoot/speak-english.ps1" $line
$Step++ Write-Host " Say <CHECK> to continue..."
Write-Host ""
WaitForCheck
$step++
} }
exit 0 # success exit 0 # success
} catch { } catch {