mirror of
https://github.com/fleschutz/PowerShell.git
synced 2025-04-22 01:48:20 +02:00
Improved voice-control.ps1
This commit is contained in:
parent
c22f7460d2
commit
4a2281e00d
@ -6,30 +6,36 @@
|
|||||||
.NOTES Author: Markus Fleschutz / License: CC0
|
.NOTES Author: Markus Fleschutz / License: CC0
|
||||||
#>
|
#>
|
||||||
|
|
||||||
|
[double]$MinConfidence = 0.05
|
||||||
|
$PathToRepo = "$PSScriptRoot/.."
|
||||||
|
|
||||||
write-output "Initializing the speech recognition engine..."
|
write-output "Initializing the speech recognition engine..."
|
||||||
$speechRecogEng = [System.Speech.Recognition.SpeechRecognitionEngine]::new();
|
$speechRecogEng = [System.Speech.Recognition.SpeechRecognitionEngine]::new();
|
||||||
$speechRecogEng.InitialSilenceTimeout = 15
|
#$speechRecogEng.InitialSilenceTimeout = 15
|
||||||
$speechRecogEng.SetInputToDefaultAudioDevice();
|
$speechRecogEng.SetInputToDefaultAudioDevice();
|
||||||
|
|
||||||
write-output "Loading the grammar..."
|
write-output "Loading the grammar..."
|
||||||
$grammar1 = [System.Speech.Recognition.GrammarBuilder]::new();
|
$Items = get-childItem -path "$PathToRepo/Scripts/"
|
||||||
$grammar1.Append("hello");
|
$Count = 0
|
||||||
$speechRecogEng.LoadGrammar($grammar1);
|
foreach ($Item in $Items) {
|
||||||
|
$Name = $Item.Name.Split('.')[0]
|
||||||
|
if ($Name -eq "") { continue }
|
||||||
|
$grammar1 = [System.Speech.Recognition.GrammarBuilder]::new()
|
||||||
|
$grammar1.Append($Name)
|
||||||
|
$speechRecogEng.LoadGrammar($grammar1)
|
||||||
|
$Count++
|
||||||
|
}
|
||||||
|
|
||||||
$grammar2 = [System.Speech.Recognition.GrammarBuilder]::new();
|
$grammar2 = [System.Speech.Recognition.GrammarBuilder]::new();
|
||||||
$grammar2.Append("open notepad");
|
$grammar2.Append("exit");
|
||||||
$speechRecogEng.LoadGrammar($grammar2);
|
$speechRecogEng.LoadGrammar($grammar2);
|
||||||
|
|
||||||
$grammar3 = [System.Speech.Recognition.GrammarBuilder]::new();
|
write-output "Got $Count voice commands, listening now..."
|
||||||
$grammar3.Append("exit");
|
$done = $false
|
||||||
$speechRecogEng.LoadGrammar($grammar3);
|
do {
|
||||||
|
|
||||||
write-output "Listening now..."
|
|
||||||
$done = $false;
|
|
||||||
while (!$done) {
|
|
||||||
$recognized = $speechRecogEng.Recognize()
|
$recognized = $speechRecogEng.Recognize()
|
||||||
write-host -nonewline "."
|
write-host -nonewline "."
|
||||||
if ($recognized.confidence -lt 0.30) { continue }
|
if ($recognized.confidence -lt $MinConfidence) { continue }
|
||||||
$myWords = $recognized.text
|
$myWords = $recognized.text
|
||||||
write-host -nonewline "$myWords ($($recognized.confidence) %)"
|
write-host -nonewline "$myWords ($($recognized.confidence) %)"
|
||||||
if ($myWords -match "hello") {
|
if ($myWords -match "hello") {
|
||||||
@ -39,8 +45,8 @@ while (!$done) {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if ($myWords -match "exit") {
|
if ($myWords -match "exit") {
|
||||||
$done = $true
|
break
|
||||||
}
|
}
|
||||||
}
|
} until ($done)
|
||||||
|
|
||||||
exit 0
|
exit 0
|
||||||
|
Loading…
Reference in New Issue
Block a user