Sembra possibile con System.Speech.Recognition
. Ecco anche l'utilizzo esempio scritto in PowerShell:
http://huddledmasses.org/control-your-pc-with-your-voice-and-powershell/
Questo collegamento è andato 404 così ho scavato fuori dalla via del ritorno macchina.
controllo del PC con la voce ... e PowerShell
By Joel 'Jaykul' Bennett il 25-Giu-2009
Avete mai desiderato di essere in grado di fare le vostre domande computer e farlo si risponde ad alta voce? Ti sei mai chiesto se il tuo computer potrebbe essere più simile a quelli che eseguono Star Trek Enterprise, rispondendo a domande e comandi vocali? Hai suonato con la domotica ZWave o X10 e hai pensato che il controllo vocale dei tuoi dispositivi sarebbe stato ovvio passo successivo?
Bene, ok ... Non ho intenzione di mostrarvi come accendere le luci o lavorare con la domotica - ma questa è la cosa principale che mi fa pensare a questa roba di riconoscimento vocale. Quale geek non vuole entrare nel salotto e dire "Computer: Lights On" e farlo funzionare?
Invece, come primo passo a tutto ciò, mostrerò come utilizzare PowerShell per eseguire semplici script di riconoscimento dei comandi vocali ... che possono attivare qualsiasi script PowerShell che si desidera scrivere! Il codice che segue è in realtà un modulo, sebbene si possa semplicemente dotarlo come uno script, e richiede realmente PowerShell 2.0 per gli eventi, sebbene sarebbe banale attribuirlo a PowerShell 1.0 utilizzando la libreria PSEventing di Oisin.
$null =[Reflection.Assembly]::LoadWithPartialName("System.Speech")
## Create the two main objects we need for speech recognition and synthesis
if(!$Global:SpeechModuleListener){## For XP's sake, don't create them twice...
$Global:SpeechModuleSpeaker =new-objectSystem.Speech.Synthesis.SpeechSynthesizer
$Global:SpeechModuleListener =new-objectSystem.Speech.Recognition.SpeechRecognizer
}
$Script:SpeechModuleMacros = @{}
## Add a way to turn it off
$Script:SpeechModuleMacros.Add("Stop Listening", { $script:listen =$false; Suspend-Listening })
$Script:SpeechModuleComputerName =${Env:ComputerName}
function Update-SpeechCommands {
#.Synopsis
# Recreate the speech recognition grammar
#.Description
# This parses out the speech module macros,
# and recreates the speech recognition grammar and semantic results,
# and then updates the SpeechRecognizer with the new grammar,
# and makes sure that the ObjectEvent is registered.
$choices = new-objectSystem.Speech.Recognition.Choices
foreach($choice in$Script:SpeechModuleMacros.GetEnumerator()){
New-ObjectSystem.Speech.Recognition.SemanticResultValue$choice.Key,
$choice.Value.ToString() |
ForEach-Object{$choices.Add( $_.ToGrammarBuilder()) }
}
if($VerbosePreference -ne"SilentlyContinue") {$Script:SpeechModuleMacros.Keys |
ForEach-Object { Write-Host"$Computer, $_" -Fore Cyan } }
$builder = New-ObjectSystem.Speech.Recognition.GrammarBuilder"$Computer, "
$builder.Append((New-ObjectSystem.Speech.Recognition.SemanticResultKey"Commands",
$choices.ToGrammarBuilder()))
$grammar = new-objectSystem.Speech.Recognition.Grammar$builder
$grammar.Name = "Power VoiceMacros"
## Take note of the events, but only once (make sure to remove the old one)
Unregister-Event"SpeechModuleCommandRecognized" -ErrorAction SilentlyContinue
$null = Register-ObjectEvent$grammar SpeechRecognized `
-SourceIdentifier"SpeechModuleCommandRecognized" `
-Action { iex$event.SourceEventArgs.Result.Semantics.Item("Commands").Value}
$Global:SpeechModuleListener.UnloadAllGrammars()
$Global:SpeechModuleListener.LoadGrammarAsync($grammar )
}
function Add-SpeechCommands {
#.Synopsis
# Add one or more commands to the speech-recognition macros, and update the recognition
#.Parameter CommandText
# The string key for the command to remove
[CmdletBinding()]
Param([hashtable]$VoiceMacros,[string]$Computer=$Script:SpeechModuleComputerName)
## Add the new macros
$Script:SpeechModuleMacros +=$VoiceMacros
## Update the default if they change it, so they only have to do that once.
$Script:SpeechModuleComputerName= $Computer
Update-SpeechCommands
}
function Remove-SpeechCommands {
#.Synopsis
# Remove one or more command from the speech-recognition macros, and update the recognition
#.Parameter CommandText
# The string key for the command to remove
Param([string[]]$CommandText)
foreach($command in $CommandText){$Script:SpeechModuleMacros.Remove($Command)}
Update-SpeechCommands
}
function Clear-SpeechCommands {
#.Synopsis
# Removes all commands from the speech-recognition macros, and update the recognition
#.Parameter CommandText
# The string key for the command to remove
$Script:SpeechModuleMacros = @{}
## Default value: A way to turn it off
$Script:SpeechModuleMacros.Add("Stop Listening", { Suspend-Listening })
Update-SpeechCommands
}
function Start-Listening {
#.Synopsis
# Sets the SpeechRecognizer to Enabled
$Global:SpeechModuleListener.Enabled= $true
Say "Speech Macros are $($Global:SpeechModuleListener.State)"
Write-Host "Speech Macros are $($Global:SpeechModuleListener.State)"
}
function Suspend-Listening {
#.Synopsis
# Sets the SpeechRecognizer to Disabled
$Global:SpeechModuleListener.Enabled= $false
Say "Speech Macros are disabled"
Write-Host "Speech Macros are disabled"
}
function Out-Speech {
#.Synopsis
# Speaks the input object
#.Description
# Uses the default SpeechSynthesizer settings to speak the string representation of the InputObject
#.Parameter InputObject
# The object to speak
# NOTE: this should almost always be a pre-formatted string,
# most objects don't render to very speakable text.
Param([Parameter(ValueFromPipeline=$true)][Alias("IO")]$InputObject )
$null =$Global:SpeechModuleSpeaker.SpeakAsync(($InputObject|Out-String))
}
function Remove-SpeechXP {
#.Synopis
# Dispose of the SpeechModuleListener and SpeechModuleSpeaker
$Global:SpeechModuleListener.Dispose();$Global:SpeechModuleListener = $null
$Global:SpeechModuleSpeaker.Dispose();$Global:SpeechModuleSpeaker = $null
}
set-alias asc Add-SpeechCommands
set-alias rsc Remove-SpeechCommands
set-alias csc Clear-SpeechCommands
set-alias say Out-Speech
set-alias listen Start-Listener
Export-ModuleMember -Function * -Alias * -VariableSpeechModuleListener, SpeechModuleSpeaker
In pratica c'è solo una funzione di cui preoccuparsi: New-VoiceCommands. Si passa a una tabella hash che mappa le stringhe in blocchi di script e, se si utilizza il -Listenswitch, è tutto quello che c'è da fare. Puoi anche chiamare manualmente Start-List e, naturalmente, ho fornito la funzione Say per rendere più semplice l'uso del computer ...
Una volta che il computer "ascolta" ... devi solo dire che è il nome, seguito da uno dei tuoi comandi. Mi piace perché garantisce che non eseguo gli script per sbaglio, ma puoi rimuovere la stringa ${Env:ComputerName},
dall'inizio di GrammarBuilder se ritieni che non sia necessaria oppure puoi codificarla su un nome diverso dal nome del tuo computer , come dire "Hal, per favore, ti prego ..." o "Computer, per favore" o qualsiasi altra cosa.
Puoi fare un sacco di cose con questo ... qualsiasi cosa, davvero ... ma per darti un esempio che puoi capire facilmente, ho intenzione di fare qualcosa di molto semplice, e il mio computer deve solo rispondere ad alcune semplici domande rispondendo a me, quindi aggiungi alcuni comandi per avviare un'applicazione o una pagina Web.
Add-SpeechCommands @{
"What time is it?" = { Say "It is $(Get-Date -f "h:mm tt")" }
"What day is it?" = { Say $(Get-Date -f "dddd, MMMM dd") }
"What's running?" = {
$proc = ps | sort ws -desc
Say $("$($proc.Count) processes, including $($proc[0].name), which is using " +
"$([int]($proc[0].ws/1mb)) megabytes of memory")
}
} -Computer "Laptop" -Verbose
Add-SpeechCommands @{ "Run Notepad"= { &"C:\Programs\DevTools\Notepad++\notepad++.exe"} }
Add-SpeechCommands @{ "Check Gee Mail" = { Start-Process"https://mail.google.com" } }
Vedete come è facile che sia? Puoi usare "Say" per pronunciare qualsiasi testo (anche se il testo otterrà risultati migliori di altri) e puoi richiamare qualsiasi altro comando di powershell, inclusi i comandi HttpRest per recuperare i dati web, oi comandi WASP per l'automazione di Windows oi comandi di PowerBoots da visualizzare output in caratteri di grandi dimensioni, o cmdlet per controllare dispositivi X10 o ZWave ... sai, qualsiasi cosa 
Non è sicuro se può ascoltare, ma grazie per aver mostrato come è possibile parlare, con valori in aumento –
Nota che quelli sono due problemi di uscita. – Joey