The HoloToolkit offers a great many, simple ways to add what seems like extremely complex features of the HoloLens, but it can be a bit tricky if you're new to Windows Holographic. So this will be the first in an ongoing series designed to help new developers understand what exactly we can do with the HoloLens, and we'll start with voice commands.
Using voice commands is actually quite simple thanks to the HoloToolkit, so let's see how it's done. To follow this tutorial, you will need to have a fresh project with the HoloToolkit installed. If you have any questions in this regard, make sure your setup is all good, and that you've played around in Unity a bit (you can skip steps 5 and 6).
Once you are ready to start, Unity should look something like this:
![HoloToolkit: How to Add Voice Commands to Your HoloLens App](https://img.reality.news/img/30/42/63616667114661/0/holotoolkit-add-voice-commands-your-hololens-app.w1456.jpg)
For this project, we are going to make a simple "Hello World" and have the colors change based on a few keywords.
Step 1: Create a 3D Text That Says 'Hello World'
Select "GameObject" from the main menu bar and select "3D Object," then "3D Text."
![HoloToolkit: How to Add Voice Commands to Your HoloLens App](https://img.reality.news/img/25/75/63616726569661/0/holotoolkit-add-voice-commands-your-hololens-app.w1456.jpg)
When that is done, you should see something that looks like this:
![HoloToolkit: How to Add Voice Commands to Your HoloLens App](https://img.reality.news/img/47/29/63616667671209/0/holotoolkit-add-voice-commands-your-hololens-app.w1456.jpg)
We need to make a few quick adjustments to our "Hello World" object.
In the Inspector window, under the Transform heading:
- Change the X position to -0.6.
- Change the Z position to 3.
Now under the Text Mesh heading:
- Change character size to 0.05.
- Change font size to 48.
![HoloToolkit: How to Add Voice Commands to Your HoloLens App](https://img.reality.news/img/56/77/63616667966817/0/holotoolkit-add-voice-commands-your-hololens-app.w1456.jpg)
Step 2: Create the Manager Object
One common system of organization in Unity is to create a game or application manager. This is where many of the management scripts are stored.
Here, we will create an empty GameObject that will act as our Keyword Manager. In the Hierarchy window, click the "Create" button and select "Create Empty."
![HoloToolkit: How to Add Voice Commands to Your HoloLens App](https://img.reality.news/img/84/37/63616727054598/0/holotoolkit-add-voice-commands-your-hololens-app.w1456.jpg)
Rename the new GameObject to "Manager."
![HoloToolkit: How to Add Voice Commands to Your HoloLens App](https://img.reality.news/img/51/62/63616727271114/0/holotoolkit-add-voice-commands-your-hololens-app.w1456.jpg)
Click on the "Add Component" button, then select the "Keyword Manager" script under HoloToolkit.Unity.
![HoloToolkit: How to Add Voice Commands to Your HoloLens App](https://img.reality.news/img/95/69/63616727291801/0/holotoolkit-add-voice-commands-your-hololens-app.w1456.jpg)
The Keyword Manager component should appear in the Inspector like this:
![HoloToolkit: How to Add Voice Commands to Your HoloLens App](https://img.reality.news/img/15/61/63616727858083/0/holotoolkit-add-voice-commands-your-hololens-app.w1456.jpg)
Step 3: Create a Script to Change the Color of 'Hello World'
Select the "New Text" object. In the Inspector window, click on the "Add Component" button and select "New Script." Type in "ColorChange" as the script name and click the "Create and Add" button to continue.
![HoloToolkit: How to Add Voice Commands to Your HoloLens App](https://img.reality.news/img/69/67/63616727900817/0/holotoolkit-add-voice-commands-your-hololens-app.w1456.jpg)
Double-click on the "ColorChange" script in new component to open up Visual Studio.
![HoloToolkit: How to Add Voice Commands to Your HoloLens App](https://img.reality.news/img/29/01/63616729430036/0/holotoolkit-add-voice-commands-your-hololens-app.w1456.jpg)
This script is really basic.
First, we get a reference to our Text Mesh (or 3D text). Then, we create three functions to change the colors. One note to point out—for the Keyword Manager to use these functions, they must have the keyword public.
![HoloToolkit: How to Add Voice Commands to Your HoloLens App](https://img.reality.news/img/54/92/63616727952567/0/holotoolkit-add-voice-commands-your-hololens-app.w1456.jpg)
Step 4: Create the Voice Commands in the Keyword Manager
Select our "Manager" GameObject and go to the "Keyword Manager" component.
![HoloToolkit: How to Add Voice Commands to Your HoloLens App](https://img.reality.news/img/80/27/63616722061348/0/holotoolkit-add-voice-commands-your-hololens-app.w1456.jpg)
In the Keyword And Responses section, the size is set to 0 (zero). For now, we need to set it to 1 (one) and click on the arrow next to "Element 0" to expand its options.
![HoloToolkit: How to Add Voice Commands to Your HoloLens App](https://img.reality.news/img/44/25/63616728079989/0/holotoolkit-add-voice-commands-your-hololens-app.w1456.jpg)
This is where we create our keywords and link functions for those keywords to perform. Type "Go Blue" into the keyword input field. In the Response () section, click the plus (+) symbol.
A new UI element appears in the Response () section. Here, we need to link the GameObject we are going to control with our voice. Click on the small circle below the words "Runtime Only." When the Select Object window appears, select "New Text" from the objects list.
![HoloToolkit: How to Add Voice Commands to Your HoloLens App](https://img.reality.news/img/79/12/63616729800348/0/holotoolkit-add-voice-commands-your-hololens-app.w1456.jpg)
The next step will be selecting the actual function we are linking to the keyword "Go Blue." Click on the drop-down box currently labeled "No Function," and when the options appear, click on "ColorChange," then "ColorBlue ()." Now the ColorBlue () function is set to trigger when the words "Go Blue" are said aloud.
![HoloToolkit: How to Add Voice Commands to Your HoloLens App](https://img.reality.news/img/90/79/63616728527301/0/holotoolkit-add-voice-commands-your-hololens-app.w1456.jpg)
In the Size field now, change the number from 1 (one) to 3 (three). This was a shortcut of sorts. Due to how this works in Unity, when you add numbers to the Keyword Managers' size, it duplicates the last keyword to the increased keyword's count.
![HoloToolkit: How to Add Voice Commands to Your HoloLens App](https://img.reality.news/img/09/61/63616728568255/0/holotoolkit-add-voice-commands-your-hololens-app.w1456.jpg)
So now we need to change the second "Go Blue" to "Go Green" and the last to "Go Red." Then we need to change the associated functions to "ColorChange.ColorGreen" and "ColorChange.ColorRed."
![HoloToolkit: How to Add Voice Commands to Your HoloLens App](https://img.reality.news/img/43/09/63616728613614/0/holotoolkit-add-voice-commands-your-hololens-app.w1456.jpg)
Woot! We are done!
Now, build, compile, and deploy. Once you load the application, say "Go Blue," "Go Green," and "Go Red" and see what happens.
![HoloToolkit: How to Add Voice Commands to Your HoloLens App](https://img.reality.news/img/42/22/63616725479614/0/holotoolkit-add-voice-commands-your-hololens-app.w1456.jpg)
Did you have any hiccups in this process? If so, make sure and let me know.
Just updated your iPhone? You'll find new features for Podcasts, News, Books, and TV, as well as important security improvements and fresh wallpapers. Find out what's new and changed on your iPhone with the iOS 17.5 update.
Be the First to Comment
Share Your Thoughts