Twenty-first century computer technology allows users to talk to their computers. Speech recognition software converts human speech into digital data that computers can recognize. Several commercial products, such as Dragon NaturallySpeaking and MacSpeech, allow users to perform a variety of speech recognition tasks. Using software built into Microsoft's Visual Studio development environment, you can create your own voice command programs using the latest version of Visual Basic.
Instructions
- 1Launch Microsoft Visual Studio and click "New Project" to open the "New Project" window. Click "Visual Basic" to highlight it, and then double-click "Windows Forms Application" to create a new Windows forms project. Code files will appear on the right side of the user interface in the Solution Navigator panel. An empty form named "Form1" will also appear on the user interface.
- 2Click "Project," and then click "Add Reference" to display the "Add Reference" pop-up window. Type "Speech" (without the quotes) in the text box and press "Enter." The name "System.Speech" will appear in the search results. Click "Add" to add it to your project, and then click "Close" to close the "Add Reference" window.
- 3Double-click the title bar of the empty form named "Form1." This causes Visual Studio to open a code window and display the following code:
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
This method, named "Form1_Load," executes when the application starts and loads the form.
- 4Add the following code before the "End Sub" statement shown in the previous step:
Dim engine As New Speech.Recognition.SpeechRecognitionEngine
Dim dictionGrammar As New Speech.Recognition.DictationGrammar
Dim recognitionResult As Speech.Recognition.RecognitionResult
Dim timeSpan As New TimeSpan(0, 0, 10)
engine.SetInputToDefaultAudioDevice()
engine.LoadGrammar(dictionGrammar)
recognitionResult = engine.Recognize(timeSpan)
For Each word As RecognizedWordUnit In recognitionResult.Words
MessageBox.Show(word.Text)
Next
The first four lines initialize the Microsoft speech recognition engine. Line five sets the engine's audio input parameters. Line six tells Visual Basic to use the standard speech recognition dictionary that Windows uses. The line that begins with "recognitionResult" starts the speech recognition engine. The final three lines of code display the words that the program recognizes when someone speaks into a microphone.
- 5Connect a microphone to your computer, and press the "F5" key to launch the application.
- 6Speak several words into the microphone. The "engine.Recognize(timeSpan)" code will capture your words and store them in the variable named "recognitionResult." Visual Basic will then display your words in a pop-up window.