Voice Recognition in VB .NET
Having recently installed VB .NET 2005, I figured it would be a good idea to upgrade the Voice Recognition articles to include VB .NET as well. Because most of the basics are the same, I will cover only the changes necessary to get the Speech SDK to work on VB .NET. Part 1 covered using the Voice Command Control. Now, I will cover how to use it in VB .NET. After installing the Speech SDK, start a new project in VB .NET.
On the Tools menu, select Choose Toolbox Items and select the COM Objects tab. In the list, tick vCommand Class and click OK. vCommand Class is now listed under Common Controls. Select it and add it to your Form. You now can use it as described in Part One. Included in the downloads is a VB .NET version of the first project.
Note: Some of the properties and methods have sightly different names in Vb .NET. For example, VoiceCmd.Enabled is now VoiceCmd.CtlEnabled.
Look closer at the project and you will see a few minor differences. The only one I'm going to cover is in the Form load event.
Private Sub Frm_Voice_Command_Load(ByVal eventSender As System.Object, _
ByVal eventArgs As System.EventArgs) Handles MyBase.Load
Dim Category, Command, Description, Action As String
Dim Flags As Integer
Command = vbNull
Description = vbNull
Category = vbNull
Action = vbNull
VoiceCmd.Initialized = 1
My_menu = VoiceCmd.get_MenuCreate("My Commands", "commands State", 4)
VoiceCmd.CtlEnabled = 1
.....
VoiceCmd.AddCommand(My_menu, 1, "stop listening", "Stop Listen", _
"listen list", 0, "")
VoiceCmd.Activate(My_menu)
Cmd_Start.Text = "Stop Listening"
Lst_Commands.Items.Clear()
TCount = VoiceCmd.get_CountCommands(My_menu)
For Loop_1 = 1 To TCount
VoiceCmd.GetCommand(My_menu, Loop_1, Command, Description, _
Category, Flags, Action)
Lst_Commands.Items.Add(Command)
Next Loop_1
The first few seem to be a requirement from VB .NET; the variables have to be assigned a value before they can be passed to the control. So, you set them to VbNull to overcome the problem. The last one is the name change explained in the note above.
Part 2 covered adding the Voice Diction Control to your application. Again, most of the methods and properties are identical, with only minor changes as listed previously required.
To add the Voice Diction control, you use the same process as before, except, in the list, select the vDict Class. Included is a VB .NET download of Project 3.
Part 4 covered adding the Direct Speach Synthesizer Control to your application. To add the Direct Speach Synthesizer Control, you use the same process as before, except, in the list, select the DirectSS Class. Again, there are no major changes required to get it to work. The code ports into VB .NET without complications. In the downloads is a VB .NET version of the datapad clone project.
As you may notice when working on this project, Microsoft has made a lot of changes to the advanced options of VB in the .NET range, but most of the basics remain the same. Using voice recognition in .NET may take some time to debug 100%, but it is not as difficult as you may assume.
Happy programming...

Comments
the exception is on :
Posted by iamlina on 08/17/2010 10:17amVoiceCmd.Initialized = 1 no one here really i need help what should i do
Replythe same Exception from HRESULT: 0x80040613
Posted by iamlina on 08/17/2010 10:14amException from HRESULT: 0x80040613 it is also in VBNProj1.zip VBNProj3.zip
Replysos me too there is an Exception
Posted by iamlina on 08/17/2010 10:03amsos me too there is an Exception in project1 please i need your help solve it thanks in advance
ReplyException Prob PLZ HLP
Posted by draculaa_xx on 07/28/2008 01:07pmSir your post is a great asset for programers it will help me a lot but when i run project 2 3 or 4 it gives me exception massage detail is here plz help me. System.Runtime.InteropServices.COMException was unhandled ErrorCode=-2147219949 Message="Exception from HRESULT: 0x80040613" Source="Interop.HSRLib" StackTrace: at HSRLib.IVcommand.set_Initialized(Int32 pVal) at AxHSRLib.AxVcommand.set_Initialized(Int32 value) at Project3.Frm_Main.Frm_Main_Load(Object eventSender, EventArgs eventArgs) in C:\Documents and Settings\Usama\Desktop\VBNProj3\Frm_Voice_Command2.vb:line 43 at System.Windows.Forms.Form.OnLoad(EventArgs e) at System.Windows.Forms.Form.OnCreateControl() at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible) at System.Windows.Forms.Control.CreateControl() at System.Windows.Forms.Control.WmShowWindow(Message& m) at System.Windows.Forms.Control.WndProc(Message& m) at System.Windows.Forms.ScrollableControl.WndProc(Message& m) at System.Windows.Forms.ContainerControl.WndProc(Message& m) at System.Windows.Forms.Form.WmShowWindow(Message& m) at System.Windows.Forms.Form.WndProc(Message& m) at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m) at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m) at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam) at System.Windows.Forms.SafeNativeMethods.ShowWindow(HandleRef hWnd, Int32 nCmdShow) at System.Windows.Forms.Control.SetVisibleCore(Boolean value) at System.Windows.Forms.Form.SetVisibleCore(Boolean value) at System.Windows.Forms.Control.set_Visible(Boolean value) at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context) at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context) at System.Windows.Forms.Application.Run(Form mainForm) at Project3.Frm_Main.Main() in C:\Documents and Settings\Usama\Desktop\VBNProj3\Frm_Voice_Command2.Designer.vb:line 1 at System.AppDomain.nExecuteAssembly(Assembly assembly, String[] args) at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args) at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly() at System.Threading.ThreadHelper.ThreadStart_Context(Object state) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) at System.Threading.ThreadHelper.ThreadStart() i am using vb 2005ReplyDictation mode?
Posted by surrri@rediffmail.com on 02/07/2007 09:33amHi is it possible to add "Dictation" mode on .net application?! Actually i want to display the word on textbox when i speak through microphone. Similar like MSOffice Speech Dictation. Thanks in advance
Reply