Hello everyone.

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.

Voice Commands using HoloToolKit

Hello,
This is very frustrating but I had it working before with Keywordmanager.cs but now that I am trying to upgrade to Speech Input Handler I cant get things to work. Please help!
All I want to happen is upon HoloLens voice command a parent and its children objects will disappear/reappear.
I've inserted the Speech Input Source and Speech Input Manager into a manager object and the following code to be referenced by the Speech Handler within the gameobject Parent:

using System.Collections;
using System.Collections.Generic;
using HoloToolkit.Unity;
using UnityEngine;

public class HideLayer : MonoBehaviour
{
public void showHidePlane()
{
if(GetComponent().enabled == true)
{
GetComponent().enabled = false;
GetComponentInParent().enabled = false;
}
else
{
GetComponent().enabled = true;
GetComponentInParent().enabled = true;
}
}
}

Any Ideas would make my day!!
Thanks!

Best Answer

Answers

  • At which point are you running into an issue?
    1. Are your speech commands not firing the proper events?
    2. Is your code above not doing what you expect? Is it the same code from your previous working implementation?

    The Toolkit contains a SpeechInputSource scene in HoloToolkit-Tests, which might help you see how these scripts are set-up.

  • Thanks for responding!
    To answer your questions
    1. The speech commands are not firing at all.
    2. The code is not doing what I expect because it is not doing anything and it is the same as my previous working code.
    The only difference, other than now using SpeechInputSource instead of KeywordManager, is that I was removing/showing a canvas instead of a parent gameobject.
    Thanks again!

  • Can you try adding Debug.Log statements in your speech handler code to see if any of those print? Also, can you describe/show me your set-up again? You should have a SpeechInputSource somewhere (perhaps a managers object), and then a SpeechInputHandler on the object you want to respond to the voice command. You'll also want to be gazing at the object when you say the speech command. If you want it to be a global responder (so you don't have to look directly at the object), add the SetGlobalListener script to the object as well.

    Hmm, when I copy your code into a project to test it, I get some errors around the use of GetComponent:

  • Sorry,
    I have referenced my code again and this is what I have for the #c code within the game object parent layer. I also have followed the same implementation format from the unity test prefab. Still no results... No errors

    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;

    namespace HoloToolkit.Unity.InputModule.Tests
    {
    [RequireComponent(typeof(Renderer))]
    public class HideParentLayer : MonoBehaviour
    {
    public void showHidePlane()
    {
    if (GetComponent().enabled == true)
    {
    GetComponent().enabled = false;
    GetComponentInParent().enabled = false;
    }
    else
    {
    GetComponent().enabled = true;
    GetComponentInParent().enabled = true;
    }
    }
    }
    }

    Any ideas?

  • KurtisKurtis mod
    edited August 2017

    Hrm, this still errors for me.

    Changing it to

    GetComponent<Renderer>()
    

    will compile for me though. Does that do anything different?

  • I put in the following with no results:

    using System.Collections;
    using System.Collections.Generic;
    using HoloToolkit.Unity;
    using UnityEngine;

    namespace HoloToolkit.Unity.InputModule.Tests
    {
    public class HideParentLayer : MonoBehaviour
    {
    public void showHidePlane()
    {
    if (GetComponent().enabled == true)
    {
    GetComponent().enabled = false;
    GetComponentInParent().enabled = false;
    }
    else
    {
    GetComponent().enabled = true;
    GetComponentInParent().enabled = true;
    }
    }
    }
    }

    To summarize my install I have the Speech Input Source within my InputManager layer. I then have the Speech Input Handler and the above code on the layer that I would like to appear and disappear.

    Thanks again!!

  • The above code I did write in < Renderer > for all lines. It is just not showing up...

  • KurtisKurtis mod
    edited August 2017

    @holonut Ahhh I see now! For some reason, the post formatter removes that part; weird...

    A couple other things to check:
    1. Do you have the Microphone capability set in your project?
    2. Do you have your SpeechInputSource set to autostart?

  • Yes and yes

  • I built the code into another layer but this time not within the parent. I attached the Speech Input Handler and the code onto a Plane 3D Object within a child only, and now just that 3D Plane Object disappears.
    This tells me that the voice recognition is working and the code is working (to some point) but the ability to attach this code to the parent layer and make it and its children disappear is not functioning.
    I am stumped because I am not a c# coding pro. You could even call me a noob.
    Any help would be appreciated!!

  • Hmm, have you tried GetComponentsInChildren<Renderer>(), if you want the parent and its children to stop rendering? If the script is on the top level, you don't want its parent's component (since it doesn't have a parent itself, if I understand your scenario), you want its children's components. That should let you place the script back on the top object.

    Also, do you have a collider on the parent? I believe the SpeechInputSource can only send events to GameObjects with colliders, otherwise the gaze targeting won't work.

  • Thanks for all your hard work.
    I tried your suggestion of replacing GetComponentsInParent() with GetComponentsInChildren()
    and unfortunately still nothing happens.

    using System.Collections;
    using System.Collections.Generic;
    using HoloToolkit.Unity;
    using UnityEngine;

    namespace HoloToolkit.Unity.InputModule
    {
    public class HideParentLayer : MonoBehaviour
    {
    public void showHidePlane()
    {
    if (GetComponent().enabled == true)
    {
    GetComponent().enabled = false;
    GetComponentInChildren().enabled = false;
    }
    else
    {
    GetComponent().enabled = true;
    GetComponentInChildren().enabled = true;
    }
    }
    }
    }

    < Renderer > might not show again in code but it is after every GetComponent function
    Also to answer your other question I have a box collider on the parent GameObject.
    Thanks again!!

  • Does it matter that the GameObject and its child layers are imports of an FBX file?

  • Instead of grabbing all the renderer components, can you try just calling gameObject.setActive(false) or gameObject.setActive(true) on the parent object? This is a better approach than setting something enabled via properties.

  • Thank you Jesse!
    We are one step closer. The GameObject disappeared with your suggestion of calling gameObject.setActive(false) but now I can't get it to set as gameObject.setActive(true) after it disappears...

    using System.Collections;
    using System.Collections.Generic;
    using HoloToolkit.Unity;
    using UnityEngine;

    namespace HoloToolkit.Unity.InputModule
    {
    public class HideParentLayer : MonoBehaviour
    {
    public void showHidePlane()
    {
    if (GetComponent().enabled == true)
    {
    gameObject.SetActive(false);
    }
    else
    {
    gameObject.SetActive(true);
    }
    }
    }
    }

  • Yeah, so, I think the way you have voice commands set up on the object. Once the object has been set inactive, it no longer receives the voice command. You might have to look at setting up global voice commands, and then cache the reference to your parent object that you want to make active and inactive.

  • Thank you!
    I have set up global voice commands and it works by referencing the cache but it still comes down to the main issue that I cannot resolve. The code that I have does not disable and then enable the parent (AND its children) GameObjects upon voice command.
    To further test out the script I just put it on ten of the 500+ children GameObjects and it does work.
    I just wish I had some code to use on the one Parent so that I didn't have to put the SpeechHandler, Global Listener, and Above Script on every 500+ Children so the GameObject would disappear...
    I am at a loss?!
    Please help if you can.
    Thanks!

  • Maybe you can try something like this.

    The Script "HideParentLayer.cs" looks like this:

    using UnityEngine;
    
    public class HideParentlayer : MonoBehaviour {
    
      public GameObject ParentLayer;
    
      public void ShowParentLayer()
      {
        ParentLayer.SetActive(true);
      }
    
      public void HideParentLayer()
      {
        ParentLayer.SetActive(false);
      }
    }
    

    The Inspector with the Parent and all its children. you can add more if you want. And the other GameObjects. All but the Parent and the SpeechManager are straight from the HTK.

    The configuration of the SpeechManager.

  • Thanks CarlvH
    Unfortunately that script gives me an error when I try to implement it. It says that it Cant add script component because the script class cannot be found...

  • I am sorry. I was just looking through my threads and I noticed that I did not respond back to you! This definitely did the trick! Thank you for your time!!

  • 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

  • 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

Sign In or Register to comment.