Exercise - Use voice commands
In this exercise, You'll learn how to create speech commands and how to control them globally. You'll also learn how to control local speech commands that require the user to look at the object that controls the speech command.
Ensure the microphone capability is enabled
In the Unity menu, select Mixed Reality > Toolkit > Utilities > Configure Project for MRTK to open the MRTK Project Configurator window. Then, in the UWP Capabilities section, verify that Enable Microphone Capability is greyed out:
Create speech commands
In the Hierarchy window, select the MixedRealityToolkit object, and then in the Inspector window, select the MixedRealityToolkit > Input tab and take the following steps:
- Expand the Speech section
- Clone the DefaultMixedRealitySpeechCommandsProfile and give it a suitable name for example, GettingStarted_MixedRealitySpeechCommandsProfile
- Verify that Start Behavior is set to Auto Start
In the Speech > Speech Commands section, click the + Add a New Speech Command button four times to add four new speech commands to the list of the existing speech commands, and then in the Keyword fields enter the following phrases:
- Enable Indicator
- Enable Tap to Place
- Enable Bounds Control
- Disable Bounds Control
Control speech commands
In the Project window, navigate to the Package > Mixed Reality Toolkit Foundation > SDK > Features > UX > Prefabs > ToolTip folder to locate the tooltip prefabs:
In the Hierarchy window, right-click on an empty spot and select Create Empty to add an empty object to your scene. Name the object SpeechInputHandler_Global, and then in the Inspector window, use the Add Component button to add the SpeechInputHandler component and configure it as follows:
- Unselect the Is Focus Required checkbox, so the user isn't required to look at the object with the SpeechInputHandler component to trigger the speech command.
- From the Project window, assign the SpeechConfirmation Tooltip prefab to the Speech Confirmation Tooltip Prefab field, to have this prefab appear when a speech command is recognized.
On the SpeechInputHandler component, click the small + icon three times to add three keyword elements:
Expand Element 0 and configure it as follows:
- In the Keyword field, enter Enable Indicator, to reference the Enable Indicator speech command you created in the previous section.
- Click the small + icon to add an event.
- From the Hierarchy window, assign the Indicator object to the None (Object) field.
- From the No Function dropdown, select GameObject > SetActive (bool) to set this function as the action to be executed when the event is triggered.
- Select the argument checkbox, so it's selected
Expand Element 1 and configure it as follows:
- In the Keyword field, enter Enable Bounds Control, to reference the Enable Bounds Control command you created in the previous section.
- Click the small + icon to add an event.
- From the Hierarchy window, assign the RoverExplorer object to the None (Object) field.
- From the No Function dropdown, select BoundsControl > bool enabled to update this property value when the event is triggered.
- Select the argument checkbox, so it's selected
- Click the small + icon to add another event
- From the Hierarchy window, assign the RoverExplorer object to the None (Object) field
- From the No Function dropdown, select ObjectManipulator > bool enabled to update this property value when the event is triggered
- Select the argument checkbox, so it's selected.
Expand Element 2 and configure it as follows:
- In the Keyword field, enter Disable Bounds Control, to reference the Disable Bounds Control command you created in the previous section.
- Click the small + icon to add an event.
- From the Hierarchy window, assign the RoverExplorer object to the one (Object) field.
- From the No Function dropdown, select BoundsControl > bool enabled to update this property value when the event is triggered.
- Verify that the argument checkbox is unselected.
- Click the small + icon to add another event.
- From the Hierarchy window, assign the RoverExplorer object to the None (Object) field.
- From the No Function dropdown, select ObjectManipulator > bool enabled to update this property value when the event is triggered.
- Verify that the argument checkbox is unselected.
In the Hierarchy window, select the RoverExplorer > RoverAssembly object, and then in the Inspector window, use the Add Component button to add the SpeechInputHandler component and configure it as follows:
- Verify that the Is Focus Required checkbox is selected, so the user is required to look at the object with the SpeechInputHandler component, that is, the RoverAssembly, to trigger the speech command.
- From the Project window, assign the SpeechConfirmation Tooltip prefab to the Speech Confirmation Tooltip Prefab field, to have this prefab appear when a speech command is recognized.
On the SpeechInputHandler component, click the small + icon to add a keyword element, expand the newly created element, and then configure it as follows:
- In the Keyword field, enter Enable Tap to Place, to reference the Enable Tap to Place command you created in the previous section.
- Click the small + icon to add an event.
- From the Hierarchy window, assign the object itself, that is, the same RoverAssembly object, to the None (Object) field.
- From the No Function dropdown, select TapToPlace > bool enabled to update this property value when the event is triggered.
- Select the argument checkbox, so it's selected
Trebate pomoć? Pogledajte naš vodič za rješavanje problema ili pošaljite željene povratne informacije prijavljivanjem problema.