mirror of
https://github.com/fleschutz/PowerShell.git
synced 2025-04-19 00:18:20 +02:00
Improved voice-control.ps1
This commit is contained in:
parent
0609414148
commit
f70b65d3e2
@ -6,17 +6,17 @@
|
|||||||
.NOTES Author: Markus Fleschutz / License: CC0
|
.NOTES Author: Markus Fleschutz / License: CC0
|
||||||
#>
|
#>
|
||||||
|
|
||||||
[double]$MinConfidence = 0.05
|
[double]$MinConfidence = 0.04
|
||||||
$PathToRepo = "$PSScriptRoot/.."
|
$PathToRepo = "$PSScriptRoot/.."
|
||||||
|
|
||||||
try {
|
try {
|
||||||
write-output "Initializing the speech recognition engine..."
|
write-output "Init speech recognition engine..."
|
||||||
$null = [Reflection.Assembly]::LoadWithPartialName("System.Speech")
|
$null = [Reflection.Assembly]::LoadWithPartialName("System.Speech")
|
||||||
$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 "Learn script files..."
|
||||||
$Items = get-childItem -path "$PathToRepo/Scripts/"
|
$Items = get-childItem -path "$PathToRepo/Scripts/"
|
||||||
$Count = 0
|
$Count = 0
|
||||||
foreach ($Item in $Items) {
|
foreach ($Item in $Items) {
|
||||||
@ -28,28 +28,26 @@ try {
|
|||||||
$Count++
|
$Count++
|
||||||
}
|
}
|
||||||
|
|
||||||
|
write-output "Learn internal command (exit)..."
|
||||||
$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 "Listening now ($Count voice commands)..."
|
||||||
$done = $false
|
while ($true) {
|
||||||
do {
|
|
||||||
$recognized = $speechRecogEng.Recognize()
|
$recognized = $speechRecogEng.Recognize()
|
||||||
write-host -nonewline "."
|
if ($recognized.confidence -lt $MinConfidence) { write-host -noNewline "?"; continue }
|
||||||
if ($recognized.confidence -lt $MinConfidence) { continue }
|
|
||||||
$myWords = $recognized.text
|
$myWords = $recognized.text
|
||||||
write-host -nonewline "$myWords ($($recognized.confidence) %)"
|
foreach ($Item in $Items) {
|
||||||
if ($myWords -match "hello") {
|
$Name = $Item.Name.Split('.')[0]
|
||||||
continue
|
if ($Name -eq $myWords) {
|
||||||
}
|
write-host "$Name ($($recognized.confidence) %)..."
|
||||||
if ($myWords -match "open notepad") {
|
& "./$Item"
|
||||||
continue
|
|
||||||
}
|
|
||||||
if ($myWords -match "exit") {
|
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
} until ($done)
|
}
|
||||||
|
if ($myWords -match "exit") { write-host -noNewline "$Name ($($recognized.confidence) %)"; break }
|
||||||
|
}
|
||||||
exit 0
|
exit 0
|
||||||
} catch {
|
} catch {
|
||||||
write-error "ERROR in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
write-error "ERROR in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
||||||
|
Loading…
Reference in New Issue
Block a user