Speech commands in MRTK not working in OpenXR (Solved)

After vainly trying to get speech commands to work in my own app, I

  • pulled your own Magic Leap MRTK code from Github
  • switched to mrtk3_MagicLeap2_OpenXR
  • Built the app with as only active scene the SpeechInputExamples scene
  • Deployed the app on my ML2
  • Run it,
  • Asks for 3 permissions, voice input is one of them
  • scene opens
  • No response to any speech commands.

The funny things is, it works fine in the Unity editor

Used:

  • Unity 2022.3.40f1
  • Magic Leap OS 1.11.0

Edit: also tried:

  • pulling mrtk3_Unity6_MagicLeap2
  • using Unity 6000.0.25f1

Same result. No speech command, although the app asks for voice input permissions on startup

What's going on here?

Right. So you have to enable voice commands at SYSTEM LEVEL. I probably turned that on ages ago, forgot about it, and after an OS upgrade haywire I flashed the device I got the default setting back, which is off.

May I respectfully point out it's a bit weird the device actually asks for permission for a permission it cannot use because it's turned off? Maybe it's a good idea to actually give a hint for that in the prompt when it asks for permission?

1 Like

I have reported your feedback to our voice of customer team. In the meantime, you may be able check the current system settings via an Android object. You can reference the JavaUtils script inside the MRTK 3 package.

Here is a simplified example of how you could read the system settings:

  private void ReadSystemVoiceInputSettings()
    {
        try
        {
            // Access the UnityPlayer class to get the current Android activity
            AndroidJavaClass unityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
            AndroidJavaObject currentActivity = unityPlayer.GetStatic<AndroidJavaObject>("currentActivity");

            // Get the ContentResolver from the current activity
            AndroidJavaObject contentResolver = currentActivity.Call<AndroidJavaObject>("getContentResolver");

            // Access the android.provider.Settings$System class
            AndroidJavaClass systemSettings = new AndroidJavaClass("android.provider.Settings$System");

            // Read the value of the system setting "enable_voice_cmds"
            int mlVoiceEnabled = systemSettings.CallStatic<int>("getInt", contentResolver, "enable_voice_cmds");

            // Check the value and log the result
            if (mlVoiceEnabled == 1)
            {
                Debug.Log("ML Voice Input is Enabled");
            }
            else
            {
                Debug.Log("ML Voice Input is Disabled");
            }
        }
        catch (AndroidJavaException e)
        {
            // Handle potential exceptions (e.g., setting not found or permission issues)
            Debug.LogError("Error reading system settings: " + e.Message);
        }
    }

Thanks! That is useful!