System.Speech.Recognition
のように表示されます。ここではPowerShellで書かれても、使用例である:このリンクはので、私は戻ってマシン道からそれを掘っ404を行ってきました
http://huddledmasses.org/control-your-pc-with-your-voice-and-powershell/
。
制御あなたのあなたの声を持つPC ...とPowerShellの
25 - 6月 - 2009ジョエルJaykul "ベネット
あなたがあなたのコンピュータの質問をできるようにしたかったし、それはあなたに答える必要がありZWaveやX10のホームオートメーションで遊んだことがあり、あなたのデバイスの音声制御が明らかになると思ったことがありますか?あなたのコンピュータがStar Trek Enterpriseを実行しているものに近いかどうか疑問に思ったことがありますか?次のステップ?
さて、私はライトをオンにする方法、またはホームオートメーションで作業する方法を紹介するつもりはありませんが、それが私にこの音声認識のことを考えさせる主なものです。オタクがリビングルームに入って「コンピュータ:ライト・オン」と言い、それを動作させたいと思わないものは何ですか?
代わりに、PowerShellを使って簡単な音声コマンド認識スクリプトを実行する方法を説明しましょう。あなたが書く気になるPowerShellスクリプトを起動できます。次のコードは実際にはモジュールですが、これをスクリプトとしてドットソースすることはできますが、実際にはPowerShell 2.0が必要ですが、OisinのPSEventingライブラリを使用してPowerShell 1.0をリファクタリングするのは簡単です。
$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
ここで心配する必要のある機能は、New-VoiceCommandsです。文字列をscriptblockにマップするハッシュテーブルを渡します。-Listenswitchを使用すると、そのすべてがそこにあります。あなたはまた、手動でコールスタートを聞くことができます。もちろん、私はコンピュータの話しを簡単にするためにSay機能を提供しています...
コンピュータが "リッスン"していると、あなたの命令の一つによって。私はそれが偶然によってスクリプトを実行しないことを保証するので、私はそれが好きですが、あなたがそれが必要ではないと思われる場合は${Env:ComputerName},
文字列をGrammarBuilderの先頭から削除するか、コンピュータ名以外にハードコードすることができます「Hal、please、please be ...」や「Computer、please」などのように。
あなたはこれで何かをすることができます...何か、本当に...しかし、あなたが理解しやすい例を与えるために、私は非常に単純なことをやろうとしています。私に話しかけて質問をしてから、いくつかのコマンドを追加して、アプリやウェブページを起動させてください。あなたはそれがいかに簡単に見る
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" } }
? 「Say」を使用するとテキストを話すことができます(他のものより良い結果が得られます)。また、Webデータを取得するHttpRestコマンド、WindowsオートメーションのWASPコマンド、PowerBootコマンドを表示するなど、他のPowerShellコマンドを呼び出すことができます大文字で出力するか、コマンドレットでX10またはZWaveデバイスを制御することができます...ご存知のように、何か
聞くことができるかどうかわかりませんが、話す方法を教えてくれてありがとうございます。upvoted –
これらは2つの異なる問題を終了しています。 – Joey