mirror of
https://github.com/fleschutz/PowerShell.git
synced 2025-04-02 12:24:11 +02:00
Improved voice-control.ps1
This commit is contained in:
parent
1be2c719e6
commit
0609414148
@ -9,30 +9,32 @@
|
|||||||
[double]$MinConfidence = 0.05
|
[double]$MinConfidence = 0.05
|
||||||
$PathToRepo = "$PSScriptRoot/.."
|
$PathToRepo = "$PSScriptRoot/.."
|
||||||
|
|
||||||
write-output "Initializing the speech recognition engine..."
|
try {
|
||||||
$speechRecogEng = [System.Speech.Recognition.SpeechRecognitionEngine]::new();
|
write-output "Initializing the speech recognition engine..."
|
||||||
#$speechRecogEng.InitialSilenceTimeout = 15
|
$null = [Reflection.Assembly]::LoadWithPartialName("System.Speech")
|
||||||
$speechRecogEng.SetInputToDefaultAudioDevice();
|
$speechRecogEng = [System.Speech.Recognition.SpeechRecognitionEngine]::new()
|
||||||
|
#$speechRecogEng.InitialSilenceTimeout = 15
|
||||||
|
$speechRecogEng.SetInputToDefaultAudioDevice()
|
||||||
|
|
||||||
write-output "Loading the grammar..."
|
write-output "Loading the grammar..."
|
||||||
$Items = get-childItem -path "$PathToRepo/Scripts/"
|
$Items = get-childItem -path "$PathToRepo/Scripts/"
|
||||||
$Count = 0
|
$Count = 0
|
||||||
foreach ($Item in $Items) {
|
foreach ($Item in $Items) {
|
||||||
$Name = $Item.Name.Split('.')[0]
|
$Name = $Item.Name.Split('.')[0]
|
||||||
if ($Name -eq "") { continue }
|
if ($Name -eq "") { continue }
|
||||||
$grammar1 = [System.Speech.Recognition.GrammarBuilder]::new()
|
$grammar1 = [System.Speech.Recognition.GrammarBuilder]::new()
|
||||||
$grammar1.Append($Name)
|
$grammar1.Append($Name)
|
||||||
$speechRecogEng.LoadGrammar($grammar1)
|
$speechRecogEng.LoadGrammar($grammar1)
|
||||||
$Count++
|
$Count++
|
||||||
}
|
}
|
||||||
|
|
||||||
$grammar2 = [System.Speech.Recognition.GrammarBuilder]::new();
|
$grammar2 = [System.Speech.Recognition.GrammarBuilder]::new()
|
||||||
$grammar2.Append("exit");
|
$grammar2.Append("exit")
|
||||||
$speechRecogEng.LoadGrammar($grammar2);
|
$speechRecogEng.LoadGrammar($grammar2)
|
||||||
|
|
||||||
write-output "Got $Count voice commands, listening now..."
|
write-output "Got $Count voice commands, listening now..."
|
||||||
$done = $false
|
$done = $false
|
||||||
do {
|
do {
|
||||||
$recognized = $speechRecogEng.Recognize()
|
$recognized = $speechRecogEng.Recognize()
|
||||||
write-host -nonewline "."
|
write-host -nonewline "."
|
||||||
if ($recognized.confidence -lt $MinConfidence) { continue }
|
if ($recognized.confidence -lt $MinConfidence) { continue }
|
||||||
@ -47,6 +49,9 @@ do {
|
|||||||
if ($myWords -match "exit") {
|
if ($myWords -match "exit") {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
} until ($done)
|
} until ($done)
|
||||||
|
exit 0
|
||||||
exit 0
|
} catch {
|
||||||
|
write-error "ERROR in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user