VB and Voice Recognition

I've spent some time following up on Voice recognition. This technology is not that new; actually it's been around for a good 15 years already. So why, you may ask, is it not widely available for you to add to your applications?

Actually, it is. Microsoft has been quietly developing VRS technology and integrating it into Windows. There are many downloads available on the Microsoft Web site that add VRS to your desktop, but very little on how to add this to your applications. This is a short tutorial on how to add voice commands to your application.

Why add voice commands to an application? Well, because it hasn't been properly documented, many programmers have not worried about using it. Yet, there are a few applications where it comes in handy or even is required. Receptionists who spend 90% of their work time talking on the phone could benefit from the use of VRS. Instead of scrolling through an electronic Rolodex to find a number, they could say 'Dial Customer.' The software then would scroll through the Rolodex until a match is found, activate the voice-enabled modem, and dial the requested number.

VRS also can benefit the physically disabled, hence bringing more users to you application. With this method, your application would have to fully implement the voice command system, with a voice prompt for every possible command.

So how do we implement VRS to our application? The first thing you will need is the Speech SDK that is available on the Microsoft Web site. After installing the Speech SDK, you may need to do some voice training so that it can 'learn' how you speak and pronounce words.

Several new components are added to the VB runtime, namely Microsoft Voice Commands, Microsoft Voice Dictation, and Microsoft Voice Text. Also, the Microsoft Direct Speech Recognition, which is installed with VB6, now uses this SDK to complete its functionality. In this article, I will cover only the basic 'Voice commands' section of the SDK. In future articles, I will cover the other functions and components.

First, to understand what you are doing, look at the 'Microsoft Voice' application that is added with this SDK. This application brings a Vocal command to most Windows functions. It allows you to verbally direct the mouse around the screen, scroll through menus, and has a few direct commands such as 'Tell me the time'. Learning to use this can be time consuming; also, the voice commands passed to an application require that you have a menu-driven form, or a visible command button for each function. This can be cumbersome at the best of times.

By adding 'Voice commands' directly to your application, you now can bypass the requirement of a menu and include only key command buttons and avoid the possibility of the spoken command activating some other application. You also will add 'Direct commands' rather than 'Indirect commands'.

Indirect commands are available only if currently visible in the menu, and have to be 'browsed to.' Direct commands do not even have to be listed on the applications menus; they are essentially Direct. You speak the command and the event, procedure, or method is called or executed.

Microsoft Voice Commands is a collection of commands that are is for the Microsoft Voice Application. You can add your own list of commands to this. This is how you do this.

In your project, add the Microsoft Voice Commands component. Add it to your form. In its properties window, set the Name to 'VoiceCmd' and the Visible property to 'false'. (You don't need to see this when your application is run.)

Next, you have to Initiate the VRS and tell it which spoken commands have to be passed through to your application.

Great. Now all that's left is to call your 'Open' and 'Save' Commands. The Microsoft Voice Command has an event called CommandRecognised; this is called when it 'Finds' the spoken command in the list you specified. In this event, you can call your relative functions. Now, add this to you code.

If you now run your application and speak the word 'Open', the Cmd_Open_Click event would be triggered, thus calling the code that you have written to open a file. The same would happen with the 'Save' command.

What more is required to do Voice commands? Nothing; through development the VRS is as simple as Plug and Play. All the Speech SDK requires from your application is the commands you require. When the SDK detects these commands, it passes them back to your application.

In the accompanying example download, I have also demonstrated how to pick up the audio levels of the microphone through the component, and how to perform commands that have no physical event. I hope you enjoy writing applications that you now can verbally command.

VB and Voice Recognition

Okay, so now you have a few simple commands that you can pass to your application. What more can you do with it? You can add Sub Command lists to your collection of commands. In this tutorial, you are going to create the first part of a Voice commanded text editor.

The only code I'm going to display here is code to add and remove Command menus in real time from the Microsoft Voice Commands. The rest of the text editor is in the download.

First, how do you add a second command menu? Almost the same way as you created your original command menu. Create a new menu with a different name. Use a naming convention so that you can easily pick it out.

You will notice that I have used a variable named 'Sub_Menu' to identify the second command list. I passed all the new commands I want to this sub menu. But these commands still are not working; you have to activate them.

Because you only want your extended commands to be active while you have a document open, you have to keep them in the deactivated state until the document opens. After you have opened the first document, you can call Activate Sub Commands, and when you close the last document, you can call Deactivate Sub Commands. And, of course. you cannot forget to release the Sub commands when you end the application.

Next time, I will cover the Voice diction Commands and add some text to speech to your application.

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.

Top White Papers and Webcasts

Thanks to wide spread cloud hosting and innovations small businesses can meet and exceed the legacy systems of goliath corporations.
Explore the freedom to work how you want, with a phone system that will adapt to your evolving needs and actually save you lots of expense—read Get an Enterprise Phone System without High Cost and Complexity.
The article clearly illustrates:
The only hardware you'll need is phone equipment for advanced voice and fax.
How to join all your employees, mobile devices, …

Today, users, applications, and data exist in more places than ever before, creating an unprecedented challenge for IT. How can IT achieve the flexibility and agility it needs to offer multiple types of applications in multiple locations? To better serve business demands for information everywhere, enterprises must develop new strategies for optimizing multiple kinds of networks. Read this white paper to learn how hybrid networks provide an unprecedented level of network dynamism, enterprise agility, and the …