Formerly known as Azure AI Services or Azure Cognitive Services is a unified collection of prebuilt AI capabilities within the Microsoft Foundry platform
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:
- The problem you’re facing is that when you call
stopContinuousRecognition, there’s a 2-10 second delay that halts your entire program. - You’ve experimented with threading and async versions, but the inconsistency persists.
- One possible cause is that the halting occurs when the stop function is called while a connection process is happening behind the scenes.
- As a workaround, consider switching to using the synchronous versions of the start and stop functions from your background thread<sup>1</sup>.
- 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.
- 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. 🌟🔧🎙️