Готовый ответ на мой вопрос я не нашел и в доках на сайте микрософта не разобрался.
.Net класс Microsoft.Speech.Recognition.SpeechRrcognitionEngine точно поддерживает, проверял, вот рабочий файл формы Ms VS2010:
- Код: Выделить всё
Public Class Form1
Private MSSpeech_TTS As New SpeechLib.SpVoice
Private CI As New System.Globalization.CultureInfo("ru-RU")
Private WithEvents SRE As New Microsoft.Speech.Recognition.SpeechRecognitionEngine(CI)
Private MyWordChoices As New Microsoft.Speech.Recognition.Choices
Private GB As New Microsoft.Speech.Recognition.GrammarBuilder
Private GR As Microsoft.Speech.Recognition.Grammar
Private MyCommands As New Collection
Private MyWords() As String
Private MyCommand As String
Private Sub Form1_Shown(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Shown
ReDim MyWords(14)
MSSpeech_TTS.Volume = 100
MSSpeech_TTS.Speak("<PITCH MIDDLE=""+10"">Слушаю</PITCH>")
MSSpeech_TTS.Rate = 1
MyWords(0) = "сабина"
MyWords(1) = "анзор"
MyWords(2) = "адам"
MyWords(3) = "тагир"
MyWords(4) = "тимур"
MyWords(5) = "лолита"
MyWords(6) = "пал буьц ахь"
MyWords(7) = "привет"
MyWords(8) = "заткнись"
MyWords(9) = "закройся"
MyWords(10) = "открой калькулятор"
MyWords(11) = "открой Блокнот"
MyWords(12) = "открой ютуб"
MyWords(13) = "очисть список"
MyWords(14) = "отвечай"
For Each MyCommand In MyWords
MyCommands.Add(MyCommands.Count, MyWords(MyCommands.Count))
Next
SRE.SetInputToDefaultAudioDevice()
MyWordChoices.Add(MyWords)
GB.Culture = CI
GB.Append(MyWordChoices)
GR = New Microsoft.Speech.Recognition.Grammar(GB)
SRE.LoadGrammar(GR)
SRE.RecognizeAsync(Microsoft.Speech.Recognition.RecognizeMode.Multiple)
End Sub
Private Sub SRE_SpeechHypothesized(ByVal sender As Object, ByVal e As Microsoft.Speech.Recognition.SpeechHypothesizedEventArgs) Handles SRE.SpeechHypothesized
Dim Result As Microsoft.Speech.Recognition.RecognitionResult = e.Result
Me.Text = "~ " & Result.Text
ListBox1.Items.Add("~ " & Result.Text)
ListBox1.SelectedIndex = ListBox1.Items.Count - 1
End Sub
Private Sub SRE_SpeechRecognitionRejected(ByVal sender As Object, ByVal e As Microsoft.Speech.Recognition.SpeechRecognitionRejectedEventArgs) Handles SRE.SpeechRecognitionRejected
MSSpeech_TTS.Speak("<PITCH MIDDLE=""+10""><RATE SPEED=""+1"">Не поняла</RATE></PITCH>")
End Sub
Private Sub SRE_SpeechRecognized(ByVal sender As Object, ByVal e As Microsoft.Speech.Recognition.SpeechRecognizedEventArgs) Handles SRE.SpeechRecognized
Dim Result As Microsoft.Speech.Recognition.RecognitionResult = e.Result
MyCommand = Result.Text
Me.Text = MyCommand
ListBox1.Items.Add("= " & MyCommand)
ListBox1.SelectedIndex = ListBox1.Items.Count - 1
Timer1.Enabled = True
End Sub
'по таймеру будет обработка полученных комманд
Private Sub Timer1_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Timer1.Enabled = False
Select Case MyCommands.Item(MyCommand)
Case 0 'сабина
MSSpeech_TTS.Speak("<PITCH MIDDLE=""+10""><RATE SPEED=""+1"">Ху бох аш</RATE></PITCH>")
Case 6 'пал буьц ахь
MSSpeech_TTS.Speak("<PITCH MIDDLE=""+10""><RATE SPEED=""+1"">Давалах,о</RATE></PITCH>")
Case 9 'закройся
End
Case 10 'калькулятор
Shell("calc.exe", vbNormalFocus)
Case 11 'блокнот
Shell("notepad.exe", vbNormalFocus)
Case 12 'ютуб
Shell("C:\Program Files\Internet Explorer\iexplore.exe www.youtube.com", vbNormalFocus)
Case 13 'очисть список
ListBox1.Items.Clear()
Case 14 'отвечай
MSSpeech_TTS.Speak("<PITCH MIDDLE=""+10""><RATE SPEED=""+1"">Окей, буду отвечать</RATE></PITCH>")
Case Else
MSSpeech_TTS.Speak("<PITCH MIDDLE=""+10""><RATE SPEED=""+1"">" & MyCommand & "</RATE></PITCH>")
End Select
End Sub
End Class
А в VBScript инициализируется чуть другой SAPI.SpInProcRecoContext, вот рабочий код:
- Код: Выделить всё
'Option Explicit
Dim c_SGDSActive 'c_SGDSInactive, c_SGDSActiveWithAutoPause, c_SGDSActiveUserDelimited
c_SGDSActive = 1 ' c_SGDSInactive = 0 c_SGDSActiveWithAutoPause = 3 c_SGDSActiveUserDelimited = 4
Dim AudioInput_Tokens '25 - 27
AudioInput_Tokens = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Speech\AudioInput\TokenEnums\MMAudioIn\"
'all objects here
Dim SpVoice, h_Context, h_Recognizer, h_Grammar, h_Category, h_Token, gram, colorRule, colorslist
Set SpVoice = WScript.CreateObject("SAPI.SpVoice")
Set SpVoice.Voice = SpVoice.GetVoices.Item(0) 'msgbox SpVoice.Voice.GetDescription
SpVoice.Volume = 100
AtoT
WScript.Quit
Private Function AtoT()
'SpVoice.Speak "Start"
Set h_Context = WScript.CreateObject("SAPI.SpInProcRecoContext", "SpRecEvent_")
Set h_Recognizer = h_Context.Recognizer
Set h_Grammar = h_Context.CreateGrammar()
h_Grammar.Dictationload
h_Grammar.DictationSetState(c_SGDSActive)
Set h_Category = WScript.CreateObject("SAPI.SpObjectTokenCategory")
h_Category.SetId(AudioInput_Tokens)
Set h_Token = WScript.CreateObject("SAPI.SpObjectToken")
h_Token.SetId(AudioInput_Tokens)
Set h_Recognizer.AudioInput = h_Token '28 Set h_Recognizer.AudioInput = h_Recognizer.GetAudioInputs().Item(1)
Set colorslist = WScript.CreateObject("SAPI.SpInProcRecognizer")
For Each gram in colorslist.GetRecognizers("Telephony")
WScript.Echo gram.GetDescription
Next
wscript.sleep 9000
SpVoice.Speak "Green"
wscript.sleep 10000000
'Set h_ObjectEvents = h_Context.Events("SpRecEvent_")
End Function
Function SpRecEvent_Recognition(StreamNumber, StreamPosition, RecognitionType, Result)
WScript.Echo "= " & Result.PhraseInfo.GetText
'SpVoice.Speak "<PITCH MIDDLE=""+10""><RATE SPEED=""1"">" & Result.PhraseInfo.GetText & "</RATE></PITCH>"
SpVoice.Speak Result.PhraseInfo.GetText
End Function
Function SpRecEvent_Hypothesis(StreamNumber, StreamPosition, Result)
WScript.Echo "~ " & Result.PhraseInfo.GetText
End Function