1
0
mirror of https://github.com/fleschutz/PowerShell.git synced 2025-03-30 00:26:57 +01:00

Improved voice-control.ps1

This commit is contained in:
Markus Fleschutz 2021-01-09 11:40:04 +01:00
parent 1be2c719e6
commit 0609414148

View File

@ -9,10 +9,12 @@
[double]$MinConfidence = 0.05
$PathToRepo = "$PSScriptRoot/.."
try {
write-output "Initializing the speech recognition engine..."
$speechRecogEng = [System.Speech.Recognition.SpeechRecognitionEngine]::new();
$null = [Reflection.Assembly]::LoadWithPartialName("System.Speech")
$speechRecogEng = [System.Speech.Recognition.SpeechRecognitionEngine]::new()
#$speechRecogEng.InitialSilenceTimeout = 15
$speechRecogEng.SetInputToDefaultAudioDevice();
$speechRecogEng.SetInputToDefaultAudioDevice()
write-output "Loading the grammar..."
$Items = get-childItem -path "$PathToRepo/Scripts/"
@ -26,9 +28,9 @@ foreach ($Item in $Items) {
$Count++
}
$grammar2 = [System.Speech.Recognition.GrammarBuilder]::new();
$grammar2.Append("exit");
$speechRecogEng.LoadGrammar($grammar2);
$grammar2 = [System.Speech.Recognition.GrammarBuilder]::new()
$grammar2.Append("exit")
$speechRecogEng.LoadGrammar($grammar2)
write-output "Got $Count voice commands, listening now..."
$done = $false
@ -48,5 +50,8 @@ do {
break
}
} until ($done)
exit 0
} catch {
write-error "ERROR in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
exit 1
}