Voice Commands With the Mixed Reality Toolkit
What you’ll need
If you haven’t done so already, be sure you’ve properly setup your development environment and you’ve imported the Mixed Reality Toolkit into your project. You’ll also need to be familiar with the Unity Editor and its interface controls. If you are not, there is a great tutorial series to get you started.
Getting Started
Note: This Feature is only availible for Windows Standalone and UWP Build Targets.
- Voice Input
- Create a new scene
- Run the MRTK scene wizard via:
MixedRealityToolkit/Configure/Apply Scene Settings
- Create a Cube
- Create a new script named
SpeechHandler
- Attach the
SpeechHandler
to your Cube - Open the new script in any text editor
- Implement the
ISpeechHandler
interface - Add switch statement for
eventData.RecognizedText
with a case for each command you wish to use.
Note:
Select
and other Voice Commands are reserved by the OS and cannot be used.
ProTip: Use simple Voice Commands that are one or two words.
using UnityEngine; using HoloToolkit.Unity.InputModule; public class SpeechHandler : MonoBehaviour, ISpeechHandler { void ISpeechHandler.OnSpeechKeywordRecognized(SpeechEventData eventData) { switch (eventData.RecognizedText.ToLower()) { case "your voice command": DoAction(); break; } } public void DoAction() { // TODO: Action } }
Now, let’s take it a step further and use Dictation to input text.