ContinuousRecognitionAsync doesn't work in Unity build

Keiron Interactive 0 Reputation points
2024-08-27T08:49:58.64+00:00

Development Environment

Windows

Unity 2023.2.8f1

Visual Studio 2022

Microsoft.CognitiveServices.Speech package

Hi everyone, I'm using the speech sdk in Unity for detect what a user says with Continuous Recognition. The problem is that on Unity Editor everything works like a charm, but in Windows Build it seems to not work. This is the simple code that I'm using:

public async Task StartContinuousRecognizerAsync()
{
    recognizer = new SpeechRecognizer(speechConfig, fileConfig);
    recognizer.Recognizing += Recognizer_Recognizing;
    recognizer.Recognized += Recognizer_Recognized;
    recognizer.Canceled += Recognizer_Canceled;
    recognizer.SessionStarted += Recognizer_SessionStarted;
    recognizer.SessionStopped += Recognizer_SessionStopped;

    Debug.Log("Starting a new recognizer session...");

    await recognizer.StartContinuousRecognitionAsync();
}
public async Task StopContinuousRecognizerAsync()
{
    if (recognizer != null)
    {
        Debug.Log("Stopping existing recognizer...");

        await recognizer.StopContinuousRecognitionAsync();
        recognizer.Recognizing -= Recognizer_Recognizing;
        recognizer.Recognized -= Recognizer_Recognized;
        recognizer.Canceled -= Recognizer_Canceled;
        recognizer.SessionStarted -= Recognizer_SessionStarted;
        recognizer.SessionStopped -= Recognizer_SessionStopped;

        recognizer.Dispose();
        recognizer = null;
    }
    Debug.Log("Recognizer session stopped!");
}
private async void Recognizer_SessionStopped(object sender, SessionEventArgs e)
{
    Debug.Log($"{e.SessionId} REGONIZING STOPPED!");
    await StopContinuousRecognizerAsync();
}
private void Recognizer_SessionStarted(object sender, SessionEventArgs e)
{
    Debug.Log($"{e.SessionId} REGONIZING STARTED!");
}
private void Recognizer_Canceled(object sender, SpeechRecognitionCanceledEventArgs e)
{
    if (e.Reason == CancellationReason.Error)
    {
        Debug.LogError($"{e.SessionId} REGONIZER ERROR WITH CODE {e.ErrorCode} - DETAILS: {e.ErrorDetails}");
    }
}
private void Recognizer_Recognized(object sender, SpeechRecognitionEventArgs e)
{
    if (e.Result.Reason == ResultReason.RecognizedSpeech)
    {
        AutoDetectSourceLanguageResult autoDetectSourceLanguageResult = AutoDetectSourceLanguageResult.FromResult(e.Result);
        resultText = e.Result.Text;
        Debug.Log($"{e.SessionId} REGONIZED WITH Text: {e.Result.Text} Language: {autoDetectSourceLanguageResult.Language}");
        Debug.Log($"{e.SessionId} RECOGNIZED WITH Properties: {e.Result.Properties.GetProperty(PropertyId.SpeechServiceResponse_JsonResult)}");
        OnResultTextReady?.Invoke(this, resultText);
    }
    else if (e.Result.Reason == ResultReason.NoMatch)
    {
        Debug.Log($"{e.SessionId} RECOGNIZED Nomatch!");
    }
    else
    {
        Debug.Log($"{e.SessionId} RECOGNIZED WITH unknown reason: {e.Result.Reason}!");
    }
}
private void Recognizer_Recognizing(object sender, SpeechRecognitionEventArgs e)
{
    Debug.Log($"{e.SessionId} REGONIZING...");
}

In Editor, I successfully receive logs from "Recognizer_Recognized" method. In Build the logs stop at StartContinuousRecognizerAsync. I don't receive response from any event and, I don't know why, but I don't receive any error or exception.

Is there something I can do?

Azure AI Speech
Azure AI Speech
An Azure service that integrates speech processing into apps and services.
2,061 questions
Azure AI services
Azure AI services
A group of Azure services, SDKs, and APIs designed to make apps more intelligent, engaging, and discoverable.
3,602 questions
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.