VB+语音识别软件
答案:1 悬赏:70 手机版
解决时间 2021-03-31 09:36
- 提问者网友:雪舞兮
- 2021-03-30 09:08
VB+语音识别软件
最佳答案
- 五星知识达人网友:酒安江南
- 2021-03-30 10:47
这个程序叫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 就说这么多
源码如下:
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 就说这么多
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯