How to set a time limit for speech recognition in ACS?

Nikolaj Wojke 0 Reputation points
2025-01-16T11:37:36.75+00:00

I want to set a limit to the time a caller has to describe their problem after StartRecognizing has started.

I tried to implement this using CancellationToken, but it didn't work, and CancelAllMediaOperations doesn't seem to be effective either. Here is my code:

// Configure the recognition options
var recognizeOptions = new CallMediaRecognizeSpeechOptions(caller)
{
    Prompt = playSource,
    EndSilenceTimeout = TimeSpan.FromMilliseconds(1000),
    OperationContext = operationContext,
    SpeechLanguage = "de-DE"
};
timerDebug.Start();
using (var cts = new CancellationTokenSource())
{
    cts.CancelAfter(TimeSpan.FromSeconds(10));
    try
    {
        // Start recognizing speech and return the result
        StartRecognizingCallMediaResult result = await callMedia.StartRecognizingAsync(recognizeOptions, cts.Token);
        result.WaitForEventProcessor(cts.Token);
    }
    catch(OperationCanceledException ocex)
    {
        logger.LogError($"RecognizeOpenQuestion() cancelled -> {ocex.Message}");
        await callMedia.CancelAllMediaOperationsAsync(cts.Token);
    }
    catch (Exception ex)
    {
        logger.LogError($"RecognizeOpenQuestion() error -> {ex.Message}");
    }
}

Is it possible?

Azure Communication Services
Azure Communication Services
An Azure communication platform for deploying applications across devices and platforms.
987 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
11,261 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.