In order to do voice recognition, you need to define the words and phrases you want to handle to put in the Commands collection. While this collection has a few different properties and methods than the typical collection, the Visual Basic For Each statement will work the same as in any other collection.
When running your program, a user can see a list of the commands understood by the Agent character by right-clicking on the Agent icon in the system tray and selecting Open Commands Window. This displays a Command window with the list of commands, as shown in Figure 14.11. The user also can see the same list of commands as a pop-up menu by right-clicking on the Agent character, as shown in Figure 14.12. Since this is a standard pop-up menu, the user can select any of the menu items, and it will be handled just as if he or she spoke the corresponding phrase.
Figure 14.11: A typical Commands window
Figure 14.12: A pop-up menu showing the same commands
The properties of the Commands collection are listed in Table 14.9. The Caption property contains the text that will be displayed as a heading in the Commands window in the Agent server (if the Visible property is True). The Voice property contains the text that will be passed to the voice recognition software if the user chooses this entry from the Commands window.
Table 14.9: Commands Collection Properties
Property | Description |
Caption | Displays the specified text in the Commands window and the pop-up menu |
Count | Contains the number of objects in the Commands collection |
Item | Returns the specified Command object |
Visible | When set to True, means that the command’s caption will appear in the character’s pop-up menu |
Voice | Specifies the text that will be passed to the voice recognition engine for processing |
The methods of the Commands collection are listed in Table 14.10. The Add method adds a new Command object to the Commands collection. The Insert method is also used to add new Command objects to the Commands collection; however, with the Insert method, you also can specify the relative location where the new object will be placed. This method is useful because it affects the order of the items in the pop-up menu and the Commands window.
Table 14.10: Commands Collection Methods
Method | Description |
Add | Adds a new command to the collection |
Command | Returns the specified Command object |
Insert | Adds a new command to the collection at the specified location |
Remove | Removes the specified command from the collection |
RemoveAll | Removes all of the commands in the collection |
NOTE: The name of the game: The first parameter of the Add and the Insert methods is Name. This value is used to retrieve a specific Command object using either Item or Command, but it is not stored in the Command object. You will not be able to retrieve this value after you use it.
The Remove and RemoveAll methods are used to remove the specified member or all the members from the collection, respectively. The Command method is similar to the Item property; it returns the Command object with the specified name.
Table 14.11 lists the properties available for the Command object. The speech recognition engine attempts to find a match between the words you spoke and the words in the Voice property. The ConfidenceText property will be displayed in the Listen Tip window if the confidence level of the match is less than the value in the Confidence property. Confidence levels must be in the range of –100 to +100.
Table 14.11: Command Object Properties
Property | Description |
Caption | Displays the specified text in the Commands window and the pop-up menu |
Confidence | Contains the confidence level for this command |
ConfidenceText | Contains the text displayed when the confidence level of the input is less than Confidence |
Enabled | When set to True, the command is enabled in the pop-up menu |
Visible | When set to True, means that the command’s caption will appear in the character’s pop-up window |
Voice | Contains the text that will be matched by the speech recognition engine |
The Caption property contains the text that will be displayed on the pop-up menu and the Command window if the Visible property is True. If the Enabled property is False, the Caption will be grayed out; otherwise, the Caption will be displayed normally.