这个程序叫Dictation
源码如下:
Option Explicit
Dim WithEvents RecoContext As SpSharedRecoContext
Dim Grammar As ISpeechRecoGrammar

Dim m_bRecoRunning As Boolean
Dim m_cChars As Integer

Private Sub Form_Load()
    SetState False
    m_cChars = 0
End Sub

Private 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 True
End Sub

Private Sub command2_Click()
    Debug.Assert m_bRecoRunning
    Grammar.DictationSetState SGDSInactive
    SetState False
End Sub
Private 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 Sub
Private Sub SetState(ByVal bNewState As Boolean)
    m_bRecoRunning = bNewState
    btnStart.Enabled = Not m_bRecoRunning
    btnStop.Enabled = m_bRecoRunning
End Sub 
commmand1的作用是初始化文本框的内容和启动语音设备(系统自带  语速你可利用speed属性自己调整) command2的作用是暂停语音设备 文本框的名字为text1  就说这么多
Logo

CSDN联合极客时间,共同打造面向开发者的精品内容学习社区,助力成长!

更多推荐