Share via

【cognitive-services-speech-sdk】startContinuousRecognition will automatically stop

玉洁 朱 0 Reputation points
2023-12-27T06:08:52.9766667+00:00

I downloaded the official iOS SDK "MicrosoftCognitiveServicesSpeech-XCFramework-1.34.0.zip" from your official website.

I want to use [speechRecognizer startContinuousRecognition] to implement real-time continuous recognition, that the speech source come from microphone.

here is my relevant code:

AudioRecorder *recorder = [[AudioRecorder alloc]initWithPushStream:stream];
SPXAudioConfiguration *audioConfig = [[SPXAudioConfiguration alloc]initWithStreamInput:stream];

speechRecognizer = [[SPXSpeechRecognizer alloc] initWithSpeechConfiguration:speechConfig language:lang audioConfiguration:audioConfig];

[speechRecognizer startContinuousRecognition];

when I call [speechRecognizer startContinuousRecognition], it will begin recognizing, but will soon stop immediately.(even though i don't call [speechRecognizer stopContinuousRecognition] ) but if i sleep for N seconds, it will recognize N seconds, and then stop.

AudioRecorder *recorder = [[AudioRecorder alloc]initWithPushStream:stream];
SPXAudioConfiguration *audioConfig = [[SPXAudioConfiguration alloc]initWithStreamInput:stream];

speechRecognizer = [[SPXSpeechRecognizer alloc] initWithSpeechConfiguration:speechConfig language:lang audioConfiguration:audioConfig];

[speechRecognizer startContinuousRecognition];

[NSThread sleepForTimeInterval:3.0f]; // add this code will delay stop

What I expected

if i don't call [speechRecognizer stopContinuousRecognition];, I expect continuous recognition not stopping.

Foundry Tools
Foundry Tools

Formerly known as Azure AI Services or Azure Cognitive Services is a unified collection of prebuilt AI capabilities within the Microsoft Foundry platform


1 answer

Sort by: Most helpful
  1. Mohan Koushik Tupakula 0 Reputation points
    2023-12-27T11:53:16.6933333+00:00

    It seems you’re encountering an issue with the startContinuousRecognition function in the Microsoft Cognitive Services Speech SDK for iOS. Let’s troubleshoot this and find a solution:

    Inconsistent Delays with stopContinuousRecognition:

    1. Potential Solutions:
    • Restart SpeechRecognizer: When your app goes into the foreground (e.g., switching to another app), the Speech Recognizer may stop without any event. Try restarting the SpeechRecognizer when it comes back into the foreground<sup>2</sup>.
    • Check Threads: Ensure that you’re not running out of threads. Make sure you’re managing threads correctly and not blocking the main thread.
    • Verify Audio Stream Handling: Double-check how you’re handling the audio stream. Make sure you’re properly initializing, streaming, and closing the audio stream.
      • Review SDK Documentation: Refer to the official SDK documentation for any specific guidelines or best practices related to continuous recognition.
    1. Sample Code Modification:
      • Consider modifying your code as follows:
          // Initialize SpeechRecognizer and other configurations
    [speechRecognizer startContinuousRecognition];
    [NSThread sleepForTimeInterval:3.0f]; // Add this code to delay stop
    // Call [speechRecognizer stopContinuousRecognition] when needed
          
          ```
    
       - [If you don’t explicitly call `stopContinuousRecognition`, continuous recognition should not stop](https://github.com/Azure-Samples/cognitive-services-speech-sdk/issues/1506)<sup>[1](https://github.com/Azure-Samples/cognitive-services-speech-sdk/issues/1506)</sup>.
    
    Remember to thoroughly test these changes and monitor the behavior. If the issue persists, consider reaching out to the Azure-Samples GitHub community for further assistance. 🌟🔧🎙️
    
    

    Was this answer helpful?

    0 comments No comments

Your answer

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