i'm trying to use this for dication, i have downloaded the sdk and i am able to run the vb 6.0 app that comes with the download fine, i tried to convert it viusal basic .net but the RecoContext_Recognition does not get fired. Does any one know how to get this to work. Please help.
This is my code
Imports SpeechLib
Public Class Form1
Inherits System.Windows.Forms.Form
Dim WithEvents RecoContext As SpeechLib.SpSharedRecoContext
Dim Grammar As SpeechLib.ISpeechRecoGrammar
Dim m_bRecoRunning As Boolean
Dim m_cChars As Integer
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
End Sub
'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents DataView1 As System.Data.DataView
Friend WithEvents txtSpeech As System.Windows.Forms.TextBox
Friend WithEvents btnStart As System.Windows.Forms.Button
Friend WithEvents btnStop As System.Windows.Forms.Button
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.DataView1 = New System.Data.DataView
Me.txtSpeech = New System.Windows.Forms.TextBox
Me.btnStart = New System.Windows.Forms.Button
Me.btnStop = New System.Windows.Forms.Button
CType(Me.DataView1, System.ComponentModel.ISupportInitialize).BeginInit()
Me.SuspendLayout()
'
'txtSpeech
'
Me.txtSpeech.Location = New System.Drawing.Point(32, 8)
Me.txtSpeech.Multiline = True
Me.txtSpeech.Name = "txtSpeech"
Me.txtSpeech.ScrollBars = System.Windows.Forms.ScrollBars.Horizontal
Me.txtSpeech.Size = New System.Drawing.Size(384, 168)
Me.txtSpeech.TabIndex = 0
Me.txtSpeech.Text = ""
'
'btnStart
'
Me.btnStart.Location = New System.Drawing.Point(104, 208)
Me.btnStart.Name = "btnStart"
Me.btnStart.Size = New System.Drawing.Size(144, 24)
Me.btnStart.TabIndex = 1
Me.btnStart.Text = "start"
'
'btnStop
'
Me.btnStop.Location = New System.Drawing.Point(256, 208)
Me.btnStop.Name = "btnStop"
Me.btnStop.Size = New System.Drawing.Size(112, 24)
Me.btnStop.TabIndex = 2
Me.btnStop.Text = " Stop"
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(456, 266)
Me.Controls.Add(Me.btnStop)
Me.Controls.Add(Me.btnStart)
Me.Controls.Add(Me.txtSpeech)
Me.Name = "Form1"
Me.Text = "Form1"
CType(Me.DataView1, System.ComponentModel.ISupportInitialize).EndInit()
Me.ResumeLayout(False)
End Sub
#End Region
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
SetState(False)
m_cChars = 0
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
Private Sub btnStart_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStart.Click
Debug.Assert(Not m_bRecoRunning)
' Initialize recognition context object and grammar object, then
' start dictation
If (RecoContext Is Nothing) Then
MsgBox("Initializing SAPI reco context object...")
RecoContext = New SpSharedRecoContext
Grammar = RecoContext.CreateGrammar(1)
Grammar.DictationLoad()
End If
Grammar.DictationSetState(SpeechRuleState.SGDSActive)
SetState(True)
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 Object, _
ByVal RecognitionType As SpeechRecognitionType, _
ByVal Result As ISpeechRecoResult _
)
Dim strText As String
strText = Result.PhraseInfo.GetText
MsgBox("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.SelectionStart = m_cChars
txtSpeech.SelectedText = strText & " "
m_cChars = m_cChars + 1 + Len(strText)
End Sub
Private Sub btnStop_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStop.Click
Debug.Assert(m_bRecoRunning)
Grammar.DictationSetState(SpeechRuleState.SGDSInactive)
SetState(False)
End Sub
End Class
This is my code
Imports SpeechLib
Public Class Form1
Inherits System.Windows.Forms.Form
Dim WithEvents RecoContext As SpeechLib.SpSharedRecoContext
Dim Grammar As SpeechLib.ISpeechRecoGrammar
Dim m_bRecoRunning As Boolean
Dim m_cChars As Integer
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
End Sub
'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents DataView1 As System.Data.DataView
Friend WithEvents txtSpeech As System.Windows.Forms.TextBox
Friend WithEvents btnStart As System.Windows.Forms.Button
Friend WithEvents btnStop As System.Windows.Forms.Button
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.DataView1 = New System.Data.DataView
Me.txtSpeech = New System.Windows.Forms.TextBox
Me.btnStart = New System.Windows.Forms.Button
Me.btnStop = New System.Windows.Forms.Button
CType(Me.DataView1, System.ComponentModel.ISupportInitialize).BeginInit()
Me.SuspendLayout()
'
'txtSpeech
'
Me.txtSpeech.Location = New System.Drawing.Point(32, 8)
Me.txtSpeech.Multiline = True
Me.txtSpeech.Name = "txtSpeech"
Me.txtSpeech.ScrollBars = System.Windows.Forms.ScrollBars.Horizontal
Me.txtSpeech.Size = New System.Drawing.Size(384, 168)
Me.txtSpeech.TabIndex = 0
Me.txtSpeech.Text = ""
'
'btnStart
'
Me.btnStart.Location = New System.Drawing.Point(104, 208)
Me.btnStart.Name = "btnStart"
Me.btnStart.Size = New System.Drawing.Size(144, 24)
Me.btnStart.TabIndex = 1
Me.btnStart.Text = "start"
'
'btnStop
'
Me.btnStop.Location = New System.Drawing.Point(256, 208)
Me.btnStop.Name = "btnStop"
Me.btnStop.Size = New System.Drawing.Size(112, 24)
Me.btnStop.TabIndex = 2
Me.btnStop.Text = " Stop"
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(456, 266)
Me.Controls.Add(Me.btnStop)
Me.Controls.Add(Me.btnStart)
Me.Controls.Add(Me.txtSpeech)
Me.Name = "Form1"
Me.Text = "Form1"
CType(Me.DataView1, System.ComponentModel.ISupportInitialize).EndInit()
Me.ResumeLayout(False)
End Sub
#End Region
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
SetState(False)
m_cChars = 0
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
Private Sub btnStart_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStart.Click
Debug.Assert(Not m_bRecoRunning)
' Initialize recognition context object and grammar object, then
' start dictation
If (RecoContext Is Nothing) Then
MsgBox("Initializing SAPI reco context object...")
RecoContext = New SpSharedRecoContext
Grammar = RecoContext.CreateGrammar(1)
Grammar.DictationLoad()
End If
Grammar.DictationSetState(SpeechRuleState.SGDSActive)
SetState(True)
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 Object, _
ByVal RecognitionType As SpeechRecognitionType, _
ByVal Result As ISpeechRecoResult _
)
Dim strText As String
strText = Result.PhraseInfo.GetText
MsgBox("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.SelectionStart = m_cChars
txtSpeech.SelectedText = strText & " "
m_cChars = m_cChars + 1 + Len(strText)
End Sub
Private Sub btnStop_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStop.Click
Debug.Assert(m_bRecoRunning)
Grammar.DictationSetState(SpeechRuleState.SGDSInactive)
SetState(False)
End Sub
End Class