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.

Dictation recognizer not displaying result unity hololens

here is my code

using HoloToolkit.Unity.InputModule;
using System.Collections;
using System.Text;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.Windows.Speech;

public class MicrophoneManager : MonoBehaviour
{
[Tooltip("A text area for the recognizer to display the recognized strings.")]
public Text DictationDisplay;

private DictationRecognizer dictationRecognizer;

// Use this string to cache the text currently displayed in the text box.
private StringBuilder textSoFar;

// Using an empty string specifies the default microphone. 
private static string deviceName = string.Empty;
private int samplingRate;
private const int messageLength = 10;

// Use this to reset the UI once the Microphone is done recording after it was started.
private bool hasRecordingStarted;



void Awake()
{
    /* TODO: DEVELOPER CODING EXERCISE 3.a */


    dictationRecognizer = new DictationRecognizer();


    dictationRecognizer.DictationHypothesis += DictationRecognizer_DictationHypothesis;


    dictationRecognizer.DictationResult += DictationRecognizer_DictationResult;


    // This event is fired when the recognizer stops, whether from Stop() being called, a timeout occurring, or some other error.
    dictationRecognizer.DictationComplete += DictationRecognizer_DictationComplete;


    dictationRecognizer.DictationError += DictationRecognizer_DictationError;

    // Query the maximum frequency of the default microphone. Use 'unused' to ignore the minimum frequency.
    int unused;
    Microphone.GetDeviceCaps(deviceName, out unused, out samplingRate);

    // Use this string to cache the text currently displayed in the text box.
    textSoFar = new StringBuilder();

    // Use this to reset the UI once the Microphone is done recording after it was started.
    hasRecordingStarted = false;

}

void Update()
{
    // 3.a: Add condition to check if dictationRecognizer.Status is Running
    if (hasRecordingStarted && !Microphone.IsRecording(deviceName) && dictationRecognizer.Status == SpeechSystemStatus.Running)
    {
        // Reset the flag now that we're cleaning up the UI.
        hasRecordingStarted = false;

        // This acts like pressing the Stop button and sends the message to the Communicator.
        // If the microphone stops as a result of timing out, make sure to manually stop the dictation recognizer.
        // Look at the StopRecording function.

    }
}

/// <summary>
/// Turns on the dictation recognizer and begins recording audio from the default microphone.
/// </summary>
/// <returns>The audio clip recorded from the microphone.</returns>
public void StartRecording()
{
    // 3.a Shutdown the PhraseRecognitionSystem. This controls the KeywordRecognizers
    PhraseRecognitionSystem.Shutdown();

    Text text = GetComponentInChildren<Text>();
    text.text = "Listening...";
    // 3.a: Start dictationRecognizer
    dictationRecognizer.Start();

    // 3.a Uncomment this line


    // Set the flag that we've started recording.
    hasRecordingStarted = true;

    Debug.Log("StartRecording");
    // Start recording from the microphone for 10 seconds.

}

/// <summary>
/// Ends the recording session.
/// </summary>
public void StopRecording()
{
    // 3.a: Check if dictationRecognizer.Status is Running and stop it if so
    if (dictationRecognizer.Status == SpeechSystemStatus.Running)
    {
        dictationRecognizer.Stop();
    }

    Microphone.End(deviceName);
}

/// <summary>
/// This event is fired while the user is talking. As the recognizer listens, it provides text of what it's heard so far.
/// </summary>
/// <param name="text">The currently hypothesized recognition.</param>
private void DictationRecognizer_DictationHypothesis(string text)
{
    Debug.Log("DictationRecognizer_DictationHypothesis");
    // 3.a: Set DictationDisplay text to be textSoFar and new hypothesized text
    // We don't want to append to textSoFar yet, because the hypothesis may have changed on the next event
    DictationDisplay.text = textSoFar.ToString() + " " + text + "...";
}

/// <summary>
/// This event is fired after the user pauses, typically at the end of a sentence. The full recognized string is returned here.
/// </summary>
/// <param name="text">The text that was heard by the recognizer.</param>
/// <param name="confidence">A representation of how confident (rejected, low, medium, high) the recognizer is of this recognition.</param>
private void DictationRecognizer_DictationResult(string text, ConfidenceLevel confidence)
{
    // 3.a: Append textSoFar with latest text
    Debug.Log("DictationRecognizer_DictationResult");
    textSoFar.Append(text + ". ");

    // 3.a: Set DictationDisplay text to be textSoFar
    DictationDisplay.text = textSoFar.ToString();
}

/// <summary>
/// This event is fired when the recognizer stops, whether from Stop() being called, a timeout occurring, or some other error.
/// Typically, this will simply return "Complete". In this case, we check to see if the recognizer timed out.
/// </summary>
/// <param name="cause">An enumerated reason for the session completing.</param>
private void DictationRecognizer_DictationComplete(DictationCompletionCause cause)
{
    Debug.Log("DictationRecognizer_DictationComplete");
    // If Timeout occurs, the user has been silent for too long.
    // With dictation, the default timeout after a recognition is 20 seconds.
    // The default timeout with initial silence is 5 seconds.
    if (cause == DictationCompletionCause.TimeoutExceeded)
    {
        Microphone.End(deviceName);

        DictationDisplay.text = "Dictation has timed out. Please press the record button again.";

    }
}

/// <summary>
/// This event is fired when an error occurs.
/// </summary>
/// <param name="error">The string representation of the error reason.</param>
/// <param name="hresult">The int representation of the hresult.</param>
private void DictationRecognizer_DictationError(string error, int hresult)
{
    // 3.a: Set DictationDisplay text to be the error string
    DictationDisplay.text = error + "\nHRESULT: " + hresult;
}

private IEnumerator RestartSpeechSystem(KeywordManager keywordToStart)
{
    while (dictationRecognizer != null && dictationRecognizer.Status == SpeechSystemStatus.Running)
    {
        yield return null;
    }

    keywordToStart.StartKeywordRecognizer();
}

}

here is the console output

StartRecording
UnityEngine.Debug:Log(Object)
MicrophoneManager:StartRecording() (at Assets/Scripts/MicrophoneManager.cs:99)
UnityEngine.EventSystems.EventSystem:Update()

DictationRecognizer_DictationComplete
UnityEngine.Debug:Log(Object)
MicrophoneManager:DictationRecognizer_DictationComplete(DictationCompletionCause) (at Assets/Scripts/MicrophoneManager.cs:152)
UnityEngine.Windows.Speech.DictationRecognizer:DictationRecognizer_InvokeCompletedEvent(DictationCompletionCause)
and yes microphone capability is enabled

Can anyone tell where am i going wrong , basicallt the internal functions are not getting called

Answers

Sign In or Register to comment.