Question Voice Recognition

Sheepings

Senior Programmer
Joined
Mar 7, 2014
Messages
33
Location
UK
Programming Experience
10+
I 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.
 
Joined
Nov 4, 2019
Messages
5
Programming Experience
1-3
I 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.
Below mentioned codes

VB.NET:
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
 
Last edited by a moderator:

jmcilhinney

VB.NET Forum Moderator
Staff member
Joined
Aug 17, 2004
Messages
14,139
Location
Sydney, Australia
Programming Experience
10+
Firstly, I have formatted your code for you, which you need to do yourself. As you can see, it is eminently more readable. If you've ever used a text editor then you know how to edit the text it contains.

Secondly, you need to be far more specific about the issue. Dumping all your code and saying "it doesn't work" is just too vague. You should have a good - if not perfect - understanding of what each and every line of code is supposed to do so, when you debug it, you can check whether what actually happens matches that expectation. If it doesn't, you can report EXACTLY where and how. You should then post ONLY the relevant code.
 
Joined
Nov 4, 2019
Messages
5
Programming Experience
1-3
Now my issue in convert string variable into form object.


During execution,when break pointer reach below statement error shows:
FormInstanceType = Type.GetType(FullTypeName, True, True)

Error:
An unhandled exception of type 'System.Reflection.TargetInvocationException' occurred in mscorlib.dll
Additional information: Exception has been thrown by the target of an invocation.
 
Joined
Nov 4, 2019
Messages
5
Programming Experience
1-3
Thank-you Everyone...
i have come-up with the solution & resolved the issue.
Actually i have replaced the entire conversion code(string variable into form object. )
'You need to - Imports System.Reflection.
sValue = orcl.dt.Rows(0).Item("VOICE_VALUE")
sValue = [Assembly].GetEntryAssembly.GetName.Name & "." & sValue
frm = DirectCast([Assembly].GetEntryAssembly.CreateInstance(sValue), Form)
frm.Show()
 
Top Bottom