LostAngel
12-31-2007, 09:34 AM
Hello, below is a test program written by VB:
'===================================================================== ========
' This sample demonstrates how to do simple dictation in VB with SAPI 5.1.
'
' It uses shared reco context object, uses the default audio input, loads in
' dictation grammar, sets up event handlers, and shows the recognized text in
' the dialog text box.
'
' Note: since the text box is using system locale, it may not correctly show
' characters in other languages. For example, if you use Chinese Speech
' Recognition engine as the default engine on your English OS, the text box
' may show garbage even though the engine recognizes Chinese.
'
' Copyright @ 2001 Microsoft Corporation All Rights Reserved.
'
'===================================================================== ========
Option Explicit
Dim WithEvents RecoContext As SpSharedRecoContext
Dim Grammar As ISpeechRecoGrammar
Dim lex As SpUnCompressedLexicon
Dim m_bRecoRunning As Boolean
Dim m_cChars As Integer
Private Sub Form_Load()
SetState False
m_cChars = 0
End Sub
Private Sub btnStart_Click()
Debug.Assert Not m_bRecoRunning
' Initialize recognition context object and grammar object, then
' start dictation
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 btnStop_Click()
Debug.Assert m_bRecoRunning
Grammar.DictationSetState SGDSInactive
SetState False
End Sub
' This function handles Recognition event from the reco context object.
' Recognition event is fired when the speech recognition engines recognizes
' a sequences of words.
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
' Append the new text to the text box, and add a space at the end of the
' text so that it looks better
txtSpeech.SelStart = m_cChars
txtSpeech.SelText = strText & " "
m_cChars = m_cChars + 1 + Len(strText)
End Sub
' This function handles the state of Start and Stop buttons according to
' whether dictation is running.
Private Sub SetState(ByVal bNewState As Boolean)
m_bRecoRunning = bNewState
btnStart.Enabled = Not m_bRecoRunning
btnStop.Enabled = m_bRecoRunning
End Sub
It is a voice recognition program dealing with SAPI. My problem is, some words are not recognized (i.e. I will say "Gevalia" and it will either find a 'close' word, or nothing at all. I have found a few hints around that you can add words along with how they are pronounced to your computers grammar dictionary, but haven't found out how. Does anyone know?
'===================================================================== ========
' This sample demonstrates how to do simple dictation in VB with SAPI 5.1.
'
' It uses shared reco context object, uses the default audio input, loads in
' dictation grammar, sets up event handlers, and shows the recognized text in
' the dialog text box.
'
' Note: since the text box is using system locale, it may not correctly show
' characters in other languages. For example, if you use Chinese Speech
' Recognition engine as the default engine on your English OS, the text box
' may show garbage even though the engine recognizes Chinese.
'
' Copyright @ 2001 Microsoft Corporation All Rights Reserved.
'
'===================================================================== ========
Option Explicit
Dim WithEvents RecoContext As SpSharedRecoContext
Dim Grammar As ISpeechRecoGrammar
Dim lex As SpUnCompressedLexicon
Dim m_bRecoRunning As Boolean
Dim m_cChars As Integer
Private Sub Form_Load()
SetState False
m_cChars = 0
End Sub
Private Sub btnStart_Click()
Debug.Assert Not m_bRecoRunning
' Initialize recognition context object and grammar object, then
' start dictation
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 btnStop_Click()
Debug.Assert m_bRecoRunning
Grammar.DictationSetState SGDSInactive
SetState False
End Sub
' This function handles Recognition event from the reco context object.
' Recognition event is fired when the speech recognition engines recognizes
' a sequences of words.
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
' Append the new text to the text box, and add a space at the end of the
' text so that it looks better
txtSpeech.SelStart = m_cChars
txtSpeech.SelText = strText & " "
m_cChars = m_cChars + 1 + Len(strText)
End Sub
' This function handles the state of Start and Stop buttons according to
' whether dictation is running.
Private Sub SetState(ByVal bNewState As Boolean)
m_bRecoRunning = bNewState
btnStart.Enabled = Not m_bRecoRunning
btnStop.Enabled = m_bRecoRunning
End Sub
It is a voice recognition program dealing with SAPI. My problem is, some words are not recognized (i.e. I will say "Gevalia" and it will either find a 'close' word, or nothing at all. I have found a few hints around that you can add words along with how they are pronounced to your computers grammar dictionary, but haven't found out how. Does anyone know?