The Mixed Reality Forums here are no longer being used or maintained.
There are a few other places we would like to direct you to for support, both from Microsoft and from the community.
The first way we want to connect with you is our mixed reality developer program, which you can sign up for at https://aka.ms/IWantMR.
For technical questions, please use Stack Overflow, and tag your questions using either hololens or windows-mixed-reality.
If you want to join in discussions, please do so in the HoloDevelopers Slack, which you can join by going to https://aka.ms/holodevelopers, or in our Microsoft Tech Communities forums at https://techcommunity.microsoft.com/t5/mixed-reality/ct-p/MicrosoftMixedReality.
And always feel free to hit us up on Twitter @MxdRealityDev.
How do I get the Position and Orientation of the Head?
I want to get the position and orientation of the head so I can make a cube move in front of the user when they call for it with the voice command.
Follow up question, how do I get voice commands to work?
I am using MRTK in Unity and I am new to C#.
Please don't refer me to Microsoft tutorials, I find them to be the least useful.
Sorry if this is a silly question with a simple answer, I haven't had much luck searching for it.
Best Answers
-
dbarrett ✭✭✭
Think of your head as the Camera. You can do something like
Camera.main.transform.position
to get the position of your head.In order to get voice commands to work create an empty object and the add the components Speech Input Source and Speech Input Handler to it from the MRTK. Make sure Speech Input Source is first. Then you can press the plus sign under keywords to add a keyword, you can also set a keyboard shortcut which can be used for debugging in the Unity editor. Next, under Speech Input Handler check the Is Global Listener and then from here you want to add the functions you want to perform with the keyword. Drag the object or object containing the script you want to manipulate and then find the method you want it to perform.
Also make sure you have the microphone capability check under the player settings. At the top in between Component and Window you should see HoloToolKit and go to Configure -> Apply HoloLens Capability Settings. You can also set the scene and project settings here automatically if you haven't done so already.
I still suggest you take a look at the Microsoft tutorials as they do help a little bit in getting the correct mindset when programming for the HoloLens. (i.e. the camera is on the player's head.) However, since you said you are new to C# I'd suggest Unity tutorials over Microsoft's only for the fact that they expect you to have a basic understanding of Unity when developing for the HoloLens already.
AR Developer
5 -
dbarrett ✭✭✭
Yes you create a script and add it as a component to an object and then you can get any public method in that script.
You can also look into the ISpeechHandler interface as well if you don't want to work with the components if you are more familiar with script. Below is an example:
public void OnSpeechKeywordRecognized(SpeechKeywordRecognizedEventData eventData) {
String keyword = eventData.RecognizedText; //Debug.Log(keyword); switch (keyword) { case "Spawn": { //Do Spawn stuff here } break; }
}
AR Developer
5
Answers
Think of your head as the Camera. You can do something like
Camera.main.transform.position
to get the position of your head.In order to get voice commands to work create an empty object and the add the components Speech Input Source and Speech Input Handler to it from the MRTK. Make sure Speech Input Source is first. Then you can press the plus sign under keywords to add a keyword, you can also set a keyboard shortcut which can be used for debugging in the Unity editor. Next, under Speech Input Handler check the Is Global Listener and then from here you want to add the functions you want to perform with the keyword. Drag the object or object containing the script you want to manipulate and then find the method you want it to perform.
Also make sure you have the microphone capability check under the player settings. At the top in between Component and Window you should see HoloToolKit and go to Configure -> Apply HoloLens Capability Settings. You can also set the scene and project settings here automatically if you haven't done so already.
I still suggest you take a look at the Microsoft tutorials as they do help a little bit in getting the correct mindset when programming for the HoloLens. (i.e. the camera is on the player's head.) However, since you said you are new to C# I'd suggest Unity tutorials over Microsoft's only for the fact that they expect you to have a basic understanding of Unity when developing for the HoloLens already.
AR Developer
Is there a way to add custom functions?
Yes you create a script and add it as a component to an object and then you can get any public method in that script.
You can also look into the ISpeechHandler interface as well if you don't want to work with the components if you are more familiar with script. Below is an example:
public void OnSpeechKeywordRecognized(SpeechKeywordRecognizedEventData eventData) {
}
AR Developer
See my latest tutorial on using speech based input for the Hololens: https://codeholo.com/2017/12/03/using-voice-based-interactions-on-the-hololens-via-speech-input-source-speech-input-handler/ using 2017 editions of Unity and the MR Toolkit