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...



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.

Downloads

Comments

  • voice command in vb.net 2008 for windows xp

    Posted by suraj on 03/06/2014 08:00am

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

    Reply
  • error 0xc000007b when run project

    Posted by Christopher Simanjuntak on 01/23/2014 01: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

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

    Posted by Sinan on 12/25/2013 02: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

    Reply
  • the exception is on :

    Posted by iamlina on 08/17/2010 10:17am

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

    Reply
  • the same Exception from HRESULT: 0x80040613

    Posted by iamlina on 08/17/2010 10:14am

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

    Reply
  • sos me too there is an Exception

    Posted by iamlina on 08/17/2010 10:03am

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

    Reply
  • Exception Prob PLZ HLP

    Posted by draculaa_xx on 07/28/2008 01: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
      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 2005

    Reply
  • Dictation mode?

    Posted by surrri@rediffmail.com on 02/07/2007 09:33am

    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

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

Top White Papers and Webcasts

  • Live Event Date: May 7, 2014 @ 1:00 p.m. ET / 10:00 a.m. PT This eSeminar will explore three popular games engines and how they empower developers to create exciting, graphically rich, and high-performance games for Android® on Intel® Architecture. Join us for a deep dive as experts describe the features, tools, and common challenges using Marmalade, App Game Kit, and Havok game engines, as well as a discussion of the pros and cons of each engine and how they fit into your development …

  • Download the Information Governance Survey Benchmark Report to gain insights that can help you further establish business value in your Records and Information Management (RIM) program and across your entire organization. Discover how your peers in the industry are dealing with this evolving information lifecycle management environment and uncover key insights such as: 87% of organizations surveyed have a RIM program in place 8% measure compliance 64% cannot get employees to "let go" of information for …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds