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.

TapToPlace Script activated by speech

I made a SpeechManager Script and it is like this

using UnityEngine;
using System.Linq;
using UnityEngine.Windows.Speech;
using System.Collections;
using System.Collections.Generic;
using HoloToolkit.Unity;

public class SpeechManager : MonoBehaviour {

KeywordRecognizer keywordRecognizer = null;
Dictionary<string, System.Action> keywords = new Dictionary<string, System.Action>();

// Use this for initialization
void Start () {

    keywords.Add("Move Object", () =>
    {
        var focusObject = GazeManager.Instance.FocusedObject;
        if (focusObject != null)
        {
            focusObject.SendMessage("MoveObject");
        }
    });

    keywordRecognizer = new KeywordRecognizer(keywords.Keys.ToArray());

    // Register a callback for the KeywordRecognizer and start recognizing!
    keywordRecognizer.OnPhraseRecognized += KeywordRecognizer_OnPhraseRecognized;
    keywordRecognizer.Start();

}

private void KeywordRecognizer_OnPhraseRecognized(PhraseRecognizedEventArgs args)
{
    System.Action keywordAction;
    if (keywords.TryGetValue(args.text, out keywordAction))
    {
        keywordAction.Invoke();
    }
}

}

have in mind that i'm using Gaze Manager from the Holo Tool kit.

now the key word "move object" is set to activate Tap to Place Script.
In order to activate it, i tried renaming onSelect method with "MoveObject" but nothing happened.
Can you tell me if i'm doing something wrong or if I have to do something more?
Maybe i'm doing something wrong with definition of focusedObject but it's the only way i have in mind.

Thank a lot.

Tagged:

Comments

  • @angelicaHolo,

    The code looks good to me. Have you tried debugging, yet? Place a break point on if(focusObject != null) and also at the first line of your MoveObject method and finally on keywordAction.Invoke() . This should tell you where the problem is happening.

    James Ashley
    VS 2017 v5.3.3, Unity 2017.3.0f3, MRTK 2017.1.2, W10 17063
    Microsoft MVP, Freelance HoloLens/MR Developer
    www.imaginativeuniversal.com

  • @james_ashley

    it actually works. there is just a small lag between the speech recognition and the start of the method.

    thanks for always being there to help. :)

  • Np @angelicaHolo. Just happy to see so many people learning to develop mixed reality apps for the HoloLens!

    James Ashley
    VS 2017 v5.3.3, Unity 2017.3.0f3, MRTK 2017.1.2, W10 17063
    Microsoft MVP, Freelance HoloLens/MR Developer
    www.imaginativeuniversal.com

  • edited November 2016

    @james_ashley

    can i bother you with another question?

    this piece of code is from 211 tutorial.

    void PerformManipulationStart(Vector3 position)
    {
    manipulationPreviousPosition = position;
    }

    void PerformManipulationUpdate(Vector3 position)
    {
    
        if (GestureManager.Instance.IsManipulating)
        {
           // TODO: DEVELOPER CODING EXERCISE 4.a
            Vector3 moveVector = Vector3.zero;
    
            // 4.a: Calculate the moveVector as position - manipulationPreviousPosition.
            moveVector = position - manipulationPreviousPosition;
    
            // 4.a: Update the manipulationPreviousPosition with the current position.
            manipulationPreviousPosition = position;
    
            // 4.a: Increment this transform's position by the moveVector.
            transform.position += moveVector; 
    
        }
    }
    

    it is called when the user says "Move Astronaut" and then tap the astroman.

    after the command recognition this goes

    private void MoveAstronautCommand(PhraseRecognizedEventArgs args)
    { GestureManager.Instance.Transition(GestureManager.Instance.ManipulationRecognizer);
    }

    which then connects to:

    private void ManipulationRecognizer_ManipulationStartedEvent(InteractionSourceKind source, Vector3 position, Ray ray)
    {
    if (HandsManager.Instance.FocusedGameObject != null)
    {
    IsManipulating = true;
    ManipulationPosition = position; HandsManager.Instance.FocusedGameObject.SendMessageUpwards("PerformManipulationStart", position);
    }
    }

    now, what I want to do is to simply manipulate the object without the use of the voice.
    Remember I use Gesture Manager script from the HTK.

    In my head need an
    if (FocusedObject != null && ManipulationInProgress)
    {
    here, i would like to put
    Vector3 moveVector = Vector3.zero;
    moveVector = position - manipulationPreviousPosition;
    manipulationPreviousPosition = position;

    transform.position += moveVector; 
    

    }

    here is where i get the problem(if this is the only problem).
    In the tutorial,position is taken from the even and i can't figure out where to take the position with what I want to do.

    also tried modifying the gesture manager that i have from HTK
    where i put

    private void ManipulationRecognizer_ManipulationStartedEvent(InteractionSourceKind source, Vector3 cumulativeDelta, Ray headRay)
    {
    /*
    // Don't start another manipulation gesture if one is already underway
    if (!ManipulationInProgress)
    {
    OnManipulation(inProgress: true, offset: cumulativeDelta);
    if (OnManipulationStarted != null)
    {
    OnManipulationStarted(source);
    }
    }
    */

            if (FocusedObject != null)
            {
                ManipulationInProgress = true;
    
                ManipulationOffset = cumulativeDelta;
    
                FocusedObject.SendMessageUpwards("ModifyStart",HandsManager.Instance.ManipulationHandPosition);
    
            }
        }
    

    private void ManipulationRecognizer_ManipulationUpdatedEvent(InteractionSourceKind source, Vector3 cumulativeDelta, Ray headRay)
    {
    //OnManipulation(inProgress: true, offset: cumulativeDelta);

            if (FocusedObject != null)
            {
                ManipulationInProgress = true;
    
                ManipulationOffset = cumulativeDelta;
    
                FocusedObject.SendMessageUpwards("ModifyStartUpdate",HandsManager.Instance.ManipulationHandPosition);
    
            }
        }
    

    but nothing happens and I can't understand why.

    I hope you can help with this one.
    thanks in advance.

  • @james_ashley

    hi! never mind. I managed to make things work :)
    I just don't understand whay the script with the vectorial calculations stops when world achora script is active.
    for now, i have deactivated but that maybe a problem, i dunno. :)

Sign In or Register to comment.