microsoft / MixedRealityToolkit-Unity

This repository is for the legacy Mixed Reality Toolkit (MRTK) v2. For the latest version of the MRTK please visit https://github.com/MixedRealityToolkit/MixedRealityToolkit-Unity
https://aka.ms/mrtkdocs
MIT License
6k stars 2.12k forks source link

Immersive application voice commands stop working leaving and resuming #10249

Closed tletie closed 9 months ago

tletie commented 3 years ago

Describe the bug

Immersive application voice commands (utilize UnityEngine.Windows.Speech.KeywordRecognizer) stop working when user open other app like Edge, File Explorer while immersive application still running.

To reproduce

Steps to reproduce the behavior:

While immersive app is running, if we launch other app like edge, file explorer, photo. Then we go back to immersive app and issue voice commands, it should works.

Your setup (please complete the following information)

Target platform (please complete the following information)

ARGs-code commented 2 years ago

We appear to be running into this issue. Has this been resolved all?

rsaru-libre commented 2 years ago

@ARGs-code We're able to fix it with the Unity 2019 update but some time updating the HL OS result in the same situation. We tried 2020 LTS and it seems to be working with that.

ARGs-code commented 2 years ago

We are on 2020.3.30f1 and still having this issue.

rsaru-libre commented 2 years ago

@ARGs-code Also I forgot to mention you need to enable and disable the MRTK speech handle.

Here is the code `

private bool registered;

void Awake()
{
    UnityEngine.WSA.Application.windowActivated += ReRegister;
}

private void ReRegister(WindowActivationState state)
{
    switch (state)
    {
        case WindowActivationState.CodeActivated:
            UnRegister();
            Register();
            break;
        case WindowActivationState.Deactivated:
            UnRegister();
            break;
        case WindowActivationState.PointerActivated:
            break;
        default:
            throw new ArgumentOutOfRangeException(nameof(state), state, null);
    }
}

private void UnRegister()
{
    if (registered)
    {
        if (CoreServices.InputSystem != null)
        {
            CoreServices.InputSystem.UnregisterHandler<IMixedRealitySpeechHandler>(this);
        }

        registered = false;
    }
    else
    {
        logger.Log(LogLevel.Error, "Keyword listener already unregistered");
    }
}

private void Register()
{
    if (!registered)
    {
        registered = true;
        CoreServices.InputSystem.RegisterHandler<IMixedRealitySpeechHandler>(this);
    }
    else
    {
        logger.Log(LogLevel.Error, "Keyword listener already registered");
    }
}

Ignore those unrelated logger statement.

ARGs-code commented 2 years ago

Thanks for the suggestion @rsaru-libre

This work around doesn't fix my issue, despite executing all the calls.

rsaru-libre commented 2 years ago

@ARGs-code I've no words how to fix this one then. I fixed this issue using this script and then it works for 2-3 month but after certain hololens os update it stop working and then we looked into the unity2020 and seems to be working in the build. So I assume its something related to the HL OS version which is messing with the voice command.

ARGs-code commented 2 years ago

No problem, it might not be the same issue. It is frustrating that these issues have just been closed, including the one I opened recently. Appreciate the help and your suggestions.

sos263665629 commented 1 year ago

@ARGs-code I have used your code, but the problem still exists.

sos263665629 commented 1 year ago

I solved the problem using the following script.

`using UnityEngine; using UnityEngine.Windows.Speech;

public class ApplicationBehaviour : MonoBehaviour { private void Awake() { DontDestroyOnLoad(gameObject); }

private void OnApplicationPause(bool pause)
{
    if (!pause)
    {
        //Delayed restart of speech recognition
        //Note: You must delay for a few seconds, otherwise it will not have any effect.
        Invoke("RecongnitionRestart", 5);
    }
}

// restart of speech recognition
private void RecongnitionRestart()
{
    PhraseRecognitionSystem.Shutdown();
    PhraseRecognitionSystem.Restart();
}

}`

IssueSyncBot commented 9 months ago

We appreciate your feedback and thank you for reporting this issue.

Microsoft Mixed Reality Toolkit version 2 (MRTK2) is currently in limited support. This means that Microsoft is only fixing high priority security issues. Unfortunately, this issue does not meet the necessary priority and will be closed. If you strongly feel that this issue deserves more attention, please open a new issue and explain why it is important.

Microsoft recommends that all new HoloLens 2 Unity applications use MRTK3 instead of MRTK2.

Please note that MRTK3 was released in August 2023. It features an all-new architecture for developing rich mixed reality experiences and has a minimum requirement of Unity 2021.3 LTS. For more information about MRTK3, please visit https://www.mixedrealitytoolkit.org.

Thank you for your continued support of the Mixed Reality Toolkit!