From e74c9f1010011884d9db83255ef179fb45c75c85 Mon Sep 17 00:00:00 2001 From: Markus Fleschutz Date: Sun, 24 Nov 2024 21:00:34 +0100 Subject: [PATCH] Updated speak-checklist.ps1 --- scripts/speak-checklist.ps1 | 41 +++++++++++++++++++++++++------------ 1 file changed, 28 insertions(+), 13 deletions(-) diff --git a/scripts/speak-checklist.ps1 b/scripts/speak-checklist.ps1 index b039d490..6e15bc33 100755 --- a/scripts/speak-checklist.ps1 +++ b/scripts/speak-checklist.ps1 @@ -3,31 +3,46 @@ Speaks a checklist by text-to-speech .DESCRIPTION This PowerShell script speaks the given checklist by text-to-speech (TTS). -.PARAMETER Name +.PARAMETER name Specifies the name of the checklist .EXAMPLE - PS> ./speak-checklist.ps1 + PS> ./speak-checklist.ps1 handwashing .LINK https://github.com/fleschutz/PowerShell .NOTES 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 { - 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 } + if ($name -eq "") { $name = Read-Host "Enter the name of the checklist" } + 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" - $Dummy = Read-Host " Say or press to continue" - $Step++ + Write-Host "$($step). $line" -foregroundColor yellow + & "$PSScriptRoot/speak-english.ps1" $line + Write-Host " Say to continue..." + Write-Host "" + WaitForCheck + $step++ } exit 0 # success } catch {