Search Unity

  1. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice
  2. Ever participated in one our Game Jams? Want pointers on your project? Our Evangelists will be available on Friday to give feedback. Come share your games with us!
    Dismiss Notice

DictationRecognizer.Status is "Running" but isn't picking up anything

Discussion in 'AR/VR (XR) Discussion' started by auroraland, Aug 12, 2019.

  1. auroraland

    auroraland

    Joined:
    Dec 7, 2017
    Posts:
    5
    Hey guys, I'm using DictationRecognizer for speech detection in VR and am having troubles.

    I got a basic empty scene with one game object, with a script that hooks up to DictationRecognizer and its emitted events. This script uses a while(true) coroutine that checks DictationRecognizer's status.

    I initialize DR timeouts to 10 seconds and hook up callbacks to Hypothesis, Result, Complete and Error events. On Complete (includes timeouts), I Stop() and Start() DR again, so I expected the DR to be always live and listening.

    It does its job well for a good while, but will have these intermittent periods where it doesn't pick up at all, even though the monitor coroutine says its status is Running.

    I've gone about this several ways, mainly through DictationComplete, from:
    1) Disposing of the DR, re-initializing it and restarting it, to
    2) Simply stopping and starting it, or
    3) Just continuously invoking DR.Start() and hope it keeps the service alive.

    After all these three, none have worked and kept the speech recognition properly alive and I'm at a loss.

    I don't think it's my VR device microphone. I've tested this same project on both the Rift and the Vive, even plugged in external microphones but no luck.

    Has anyone observed the same? If so, how did you deal with it?

    Code (csharp):
    1.  
    2. using System.Collections;
    3. using UnityEngine;
    4.  
    5. #if (UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN || UNITY_WINRT || UNITY_WINRT_8_0 || UNITY_WINRT_8_1 || UNITY_WINRT_10_0)
    6. using UnityEngine.Windows.Speech;
    7. #endif
    8.  
    9. public sealed class TestVCService : MonoBehaviour
    10. {
    11. #if (UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN || UNITY_WINRT || UNITY_WINRT_8_0 || UNITY_WINRT_8_1 || UNITY_WINRT_10_0)
    12.  
    13.    ConfidenceLevel _minimumConfidence = ConfidenceLevel.Low;
    14.    DictationRecognizer _dictationRecognizer;
    15.    Coroutine _serviceLifeCheckerCoroutine;
    16.  
    17.    void Start()
    18.    {
    19.       InitializeRecognizer();
    20.       StartRecording();
    21.    }
    22.  
    23.    void OnDestroy()
    24.    {
    25.       if (_dictationRecognizer != null)
    26.       {
    27.          _dictationRecognizer.Dispose();
    28.       }
    29.    }
    30.  
    31.    IEnumerator CheckDictationRecognizerStatusRoutine()
    32.    {
    33.       while (true)
    34.       {
    35.          print(_dictationRecognizer.Status);
    36.          yield return null;
    37.       }
    38.    }
    39.  
    40.    void InitializeRecognizer()
    41.    {
    42.       _dictationRecognizer = new DictationRecognizer(_minimumConfidence, DictationTopicConstraint.Dictation)
    43.       {
    44.          InitialSilenceTimeoutSeconds = 10, AutoSilenceTimeoutSeconds = 10
    45.       };
    46.       _dictationRecognizer.DictationResult += OnDictationResult;
    47.       _dictationRecognizer.DictationHypothesis += OnDictationHypothesis;
    48.       _dictationRecognizer.DictationComplete += OnDictationComplete;
    49.       _dictationRecognizer.DictationError += OnDictationError;
    50.    }
    51.  
    52.    void StartRecording()
    53.    {
    54.       try
    55.       {
    56.          _dictationRecognizer.Start();
    57.          _serviceLifeCheckerCoroutine = StartCoroutine(CheckDictationRecognizerStatusRoutine());
    58.       }
    59.       catch (UnityException ue)
    60.       {
    61.          print(ue.Message);
    62.       }
    63.    }
    64.  
    65.    void StopRecording()
    66.    {
    67.       _dictationRecognizer.Stop();
    68.       StopCoroutine(_serviceLifeCheckerCoroutine);
    69.    }
    70.  
    71.    void OnDictationResult(string text, ConfidenceLevel confidence)
    72.    {
    73.       print("Dictation result: " + text);
    74.    }
    75.  
    76.    void OnDictationHypothesis(string text)
    77.    {
    78.       print("Dictation result: " + text);
    79.    }
    80.  
    81.    void OnDictationComplete(DictationCompletionCause cause)
    82.    {
    83.       print(cause);
    84.       StopRecording();
    85.       StartRecording();
    86.    }
    87.  
    88.    void OnDictationError(string error, int hresult)
    89.    {
    90.       print("Dictation error - " + error + "; HResult = " + hresult);
    91.    }
    92. #else
    93.    void Start()
    94.     {
    95.         print("This service is only supported on Windows.");
    96.     }
    97. #endif
    98. }
    99.  
     
    Last edited: Aug 12, 2019
unityunity