How to set a time limit for speech recognition in ACS?
Nikolaj Wojke
0
Reputation points
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?
Sign in to answer