VB+语音识别软件

来源:互联网 发布:诺基亚6120软件下载 编辑:程序博客网 时间:2024/03/29 22:43
这个程序叫Dictation源码如下:Option ExplicitDim WithEvents RecoContext As SpSharedRecoContextDim Grammar As ISpeechRecoGrammarDim m_bRecoRunning As BooleanDim m_cChars As IntegerPrivate Sub Form_Load()    SetState False    m_cChars = 0End SubPrivate Sub command1_Click()    Debug.Assert Not m_bRecoRunning    If (RecoContext Is Nothing) Then        Debug.Print "Initializing SAPI reco context object..."        Set RecoContext = New SpSharedRecoContext        Set Grammar = RecoContext.CreateGrammar(1)        Grammar.DictationLoad    End If        Grammar.DictationSetState SGDSActive    SetState TrueEnd SubPrivate Sub command2_Click()    Debug.Assert m_bRecoRunning    Grammar.DictationSetState SGDSInactive    SetState FalseEnd SubPrivate Sub RecoContext_Recognition(ByVal StreamNumber As Long, _                                    ByVal StreamPosition As Variant, _                                    ByVal RecognitionType As SpeechRecognitionType, _                                    ByVal Result As ISpeechRecoResult _                                    )    Dim strText As String    strText = Result.PhraseInfo.GetText    Debug.Print "Recognition: " & strText & ", " & _        StreamNumber & ", " & StreamPosition    text1.SelStart = m_cChars    text1.SelText = strText & " "    m_cChars = m_cChars + 1 + Len(strText)End SubPrivate Sub SetState(ByVal bNewState As Boolean)    m_bRecoRunning = bNewState    btnStart.Enabled = Not m_bRecoRunning    btnStop.Enabled = m_bRecoRunningEnd Sub commmand1的作用是初始化文本框的内容和启动语音设备(系统自带  语速你可利用speed属性自己调整) command2的作用是暂停语音设备 文本框的名字为text1  就说这么多
0 0
原创粉丝点击