Voice Recognition in VB .NET


Desktop-as-a-Service Designed for Any Cloud ? Nutanix Frame

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, "")
Cmd_Start.Text = "Stop Listening"
TCount = VoiceCmd.get_CountCommands(My_menu)
For Loop_1 = 1 To TCount
   VoiceCmd.GetCommand(My_menu, Loop_1, Command, Description, _
                       Category, Flags, Action)
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...

About the Author

Richard Newcombe

Richard Newcombe has been involved in computers since the time of the Commodore 64. Today, he has excelled in programming, and designs. Richard is in his mid 30's and, if or when you looking for him look no further than his computer. Always willing to help and give advice where he can in regard to computer related subjects. At present he is working as a .NET 2008 Software Developer for Syncrony Web Services, South Africa.



  • voice command in vb.net 2008 for windows xp

    Posted by suraj on 03/06/2014 04:00pm

    plz, provide me code for voice command in vb.net for windows xp... to control pc some program........

  • error 0xc000007b when run project

    Posted by Christopher Simanjuntak on 01/23/2014 09:17am

    Hello Sir.Richard Newcomb i'm Christopher from Indonesia I glad to learn your tutor from the source code that you shared I have a problem error 0xc000007b when i run the VBNProj1 of your project Voice Recognition in VB.NET. I have looked for the problem but i don't know where is the problem, I hope You can tell me what of the cause... Regards

  • One of the Worst Tutorials Online - Why? Because there has been no Update..

    Posted by Sinan on 12/25/2013 10:43pm

    First of all I really appereciate your time Explaining. What I dont understand is that the Project is full of Wrong Declarations and wrong coding! Plus when users on here asking for help or advice havnt got any answers! This was published 6-7 years ago and I really hope as a DEVELOPER you could give everyone and updated version or simply allow them to Download the complete Project without leaving a bunch of files that doesnt even make sence to anyone! I tried hard to understand! Your explanation was pretty awesome, but when getting to the Files then nothing make sense. I really hope this could be update

  • the exception is on :

    Posted by iamlina on 08/17/2010 05:17pm

    VoiceCmd.Initialized = 1 no one here really i need help what should i do

  • the same Exception from HRESULT: 0x80040613

    Posted by iamlina on 08/17/2010 05:14pm

    Exception from HRESULT: 0x80040613 it is also in VBNProj1.zip VBNProj3.zip

  • sos me too there is an Exception

    Posted by iamlina on 08/17/2010 05:03pm

    sos me too there is an Exception in project1 please i need your help solve it thanks in advance

  • Exception Prob PLZ HLP

    Posted by draculaa_xx on 07/28/2008 08:07pm

    Sir 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
      Message="Exception from HRESULT: 0x80040613"
           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 2005

  • Dictation mode?

    Posted by surrri@rediffmail.com on 02/07/2007 05:33pm

    Hi 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

  • You must have javascript enabled in order to post comments.

Leave a Comment
  • Your email address will not be published. All fields are required.

Most Popular Programming Stories

More for Developers

RSS Feeds

Thanks for your registration, follow us on our social networks to keep up-to-date