Alphonse Jose B
Member
- Joined
- Nov 4, 2019
- Messages
- 6
- Programming Experience
- 1-3
How to provide dynamic grammar or command for voice recognition in vb.net
Some issues in reg_SpeechRecognized event,which is not worked when data loaded from db to voice recognition.What have you tried and where are you stuck?
Below mentioned codesI have five classes wrote out on a whole program using pre-programmed grammar as well as predictive text with a lookup service for specific words to match. Be a bit more specific and put some effort into your question, and I might translate it from c# to vb.net for you. I'd also be interested to see how far you've gotten yourself, or what you've tried.
Imports System.Speech
Imports System.Speech.Recognition
Imports System.Threading
Imports System.Globalization
Imports Infragistics.Win.UltraWinGrid
Public Class dynamicvoice
Dim lst As New List(Of String)
Dim orcl As New orcl_class
Dim objForm As Form
Dim sValue As String
Dim FullTypeName As String
Dim FormInstanceType As Type
Dim WithEvents reg As New Recognition.SpeechRecognitionEngine
Private Sub reg_RecognizeCompleted(sender As Object, e As RecognizeCompletedEventArgs) Handles reg.RecognizeCompleted
reg.RecognizeAsync()
End Sub
Private Sub reg_SpeechRecognized(sender As Object, e As SpeechRecognizedEventArgs) Handles reg.SpeechRecognized
Select Case e.Result.Text
Case e.Result.Text
'fetch form name from data base corresponding to voice commands
orcl.execquery("select VOICE_VALUE from TM_VOICETEST where VOICENAME='" & e.Result.Text & "'")
If orcl.rcount > 0 Then
sValue = orcl.dt.Rows(0).Item("VOICE_VALUE")
FullTypeName = Application.ProductName & "." & sValue
FormInstanceType = Type.GetType(FullTypeName, True, True)
objForm = CType(Activator.CreateInstance(FormInstanceType), Form)
objForm.Show()
End If
End Select
End Sub
Private Sub searchDB()
'fetch voice commands from data base
orcl.execquery("select VOICENAME from TM_VOICETEST")
For i = 0 To orcl.dt.Rows.Count - 1
lst.Add(orcl.dt.Rows(i).Item(0))
Next
End Sub
'form load
Private Sub dynamicvoice_Load(sender As Object, e As EventArgs) Handles MyBase.Load
reg.SetInputToDefaultAudioDevice()
Thread.CurrentThread.CurrentUICulture = New CultureInfo("en-GB")
searchDB()
reg.LoadGrammar(New Grammar(New GrammarBuilder(New Choices(lst.ToArray()))))
reg.RecognizeAsync()
End Sub
End Class