Processing payload from Twilio Call stream to Speech to Text

Pat O'Neil 25 Reputation points
2023-11-20T20:36:37.7066667+00:00

From all of the different examples I've seen out there, it seem like I should be able to process the "payload" of a websocket message passed from Twilio using the Azure Speech to Text service.

I am running a C# .net core app to process the socket message. In each instance, I am grabbing the payload of the media message and passing into the Azure Speech to Text in order to get that chunk of text from the call in real-time. In the code snippet below, the RecognizedSpeech case is being hit, but it's always with an empty string result.

Should the RecognizeOnceAsync() be able to recognize the text from that payload data chunk?

var speechRecognizer = new SpeechRecognizer(speechConfig, audioConfig);
var speechRecogResult = await speechRecognizer.RecognizeOnceAsync().ConfigureAwait(false);

switch (speechRecogResult.Reason) 
{     
	case ResultReason.RecognizedSpeech:         
 		//do something
	break;
	case ResultReason.NoMatch:         
		Console.WriteLine($"NOMATCH: Speech could not be recognized.");         
		break;     
	case ResultReason.Canceled:         
		var cancellation = CancellationDetails.FromResult(speechRecogResult);         
		break; 
}

Azure AI Speech
Azure AI Speech
An Azure service that integrates speech processing into apps and services.
2,061 questions
Azure
Azure
A cloud computing platform and infrastructure for building, deploying and managing applications and services through a worldwide network of Microsoft-managed datacenters.
1,408 questions
0 comments No comments
{count} vote

Accepted answer
  1. navba-MSFT 27,540 Reputation points Microsoft Employee Moderator
    2023-11-21T04:56:32.5566667+00:00

    @Pat O'Neil Welcome to Microsoft Q&A Forum, Thank you for posting your query here!

    .
    I understand that you are trying to use the Azure Speech to Text service to process the payload of a websocket message passed from Twilio. However, you are encountering an issue where the RecognizeOnceAsync() method is returning an empty string result.
    .

    The RecognizeOnceAsync() method from Azure’s Speech SDK is designed to perform speech recognition and return after a single utterance is recognized. The end of a single utterance is determined by listening for silence at the end or until a timeout period has elapsed.
    .

    In your case, if the RecognizedSpeech case is being hit but always with an empty string result, it might be due to the following reasons:

    • The payload data chunk that you’re passing to the RecognizeOnceAsync() method might not be in the correct format or might not contain valid audio data.
    • There might be an issue with the speechConfig or audioConfig that you’re using to initialize the SpeechRecognizer.

    .
    You could try the following steps to debug the issue:

    • Enable the Speech SDK logging and check the verbose logs for any issue:
    speechConfig.SetProperty(PropertyId.Speech_LogFilename, "LogfilePathAndName");
    
    • Verify that the payload data chunk contains valid audio data.
    • Check the configurations (speechConfig and audioConfig) used for initializing the SpeechRecognizer.
    • Make sure that the audio data in the payload is compatible with the Azure Speech service. .
      Action Plan:
      If you’re still facing issues, you might want to consider using the If you’re still facing issues, you might want to consider using the StartContinuousRecognitionAsync() method for long-running multi-utterance recognition. This could be more suitable if you’re dealing with a stream of audio data chunks and also helps for recognize real-time speech.
      The sample code is here for your reference.
      .

    Remember, it’s always a good idea to handle all possible ResultReason cases, including Canceled, to properly manage any errors or issues that might occur during the recognition process. For example, if the ResultReason is Canceled, you can check the CancellationDetails to get more information about the error.
    .

    Hope this helps. If you have any follow-up questions, please let me know. I would be happy to help.
    .

    **

    Please do not forget to "Accept the answer” and “up-vote” wherever the information provided helps you, this can be beneficial to other community members.


0 additional answers

Sort by: Most helpful

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.