cognitive-services-speech-sdk: SPXSpeechSynthesizer stopSpeaking() method cannot return immediately on iOS 17
After calling SPXSpeechSynthesizer startSpeakingSsml() to synthesize the speech, while the speech is playing back, and then call stopSpeaking() to stop the speech, stopSpeaking() cannot return immediately on iOS 17. The speech audio can be stopped immediately, but this method will take 10-20 secs to return.
iOS16 and iOS 15 doesn’t have this issue.
Below is our sample swift code to illustrate this issue on iOS 17
// below is the code snippet to start text to speech
let speechConfig = try SPXSpeechConfiguration(subscription: key, region: region)
synthesizer = try SPXSpeechSynthesizer(speechConfig)
let ssml = """
<speak version="1.0" xmlns="http://www.w3.org/2001/10/synthesis" xmlns:mstts="https://www.w3.org/2001/mstts" xml:lang="en-US">
<voice name="en-US-JennyNeural">
<mstts:express-as style="friendly">
<prosody rate="1.0">
Hello how are you ?
</prosody>
</mstts:express-as>
</voice>
</speak>
"""
try synthesizer?.startSpeakingSsml(ssml)
Below is the code snippet to stop text to speech
try synthesizer?.stopSpeaking() // this method takes 10-20s to return
We’re using MicrosoftCognitiveServicesSpeech-iOS ver 1.32.1
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Comments: 15 (1 by maintainers)
Not really fixed(1.36), synthesizer.addSynthesisCompletedEventHandler still needs 10-20s to receive callback.
Fix has been released in 1.33.0 Speech SDK release. Let us know if there are any problems.
@ssadel thanks for the backtrace, could you please share the sample code how this could be reproduced?
@solossam we have a fix currently for the stop delay, the ETA would be 1.33.0 release (approx. end of the Oct 2023). The problem seems to be due to behavioral change in https://developer.apple.com/documentation/audiotoolbox/1501970-audioqueuestop?language=objc in iOS17 and which causes the delay with Speech SDK.
If your use case is to do synthesis playback via speaker output, one workaround for the issue before the SDK fix is released is to create SpeechSynthesizer using PullAudioOutputStream or PushAudioOutputStream and get the audio bytes from synthesis to your application and then stream the audio bytes to the device speaker using AVFoundation APIs.
If you want to try that route, for Push/PullAudioOutputStream examples, please take a look following Objective-C sample below (For Swift , it is similar, unfortunately we do not have Swift sample for the stream usage). https://github.com/Azure-Samples/cognitive-services-speech-sdk/blob/master/samples/objective-c/ios/synthesis-samples/synthesis-samples/ViewController.m