AVSpeechSynthesizer write method is broken in iOS 16

Using the write method from AVSpeechSynthesizer produces the following error:

[AXTTSCommon] TTSPlaybackEnqueueFullAudioQueueBuffer: error -66686 enqueueing buffer

This issue has first been seen on iOS 16.

More information and code snippet: https://stackoverflow.com/questions/73716508/play-audio-buffers-generated-by-avspeechsynthesizer-directly

Hey there, I see on Stack Overflow you mentioned you filed a feedback report on this. Can you please link your feedback ID here so I can make sure the right folks are aware of this issue? Thanks

Same here. Just updated to XCode 14.0.1 and testing on an IPHone 13 Pro Max IOS 16 I got the same error.

    func saveAVSpeechUtteranceToFile() {

        let utterance = AVSpeechUtterance(string: "This is an example of speech")
        utterance.voice = AVSpeechSynthesisVoice(language: "en-US")
        utterance.rate = 0.50

        var output: AVAudioFile?

        synthesizer.write(utterance) { (buffer: AVAudioBuffer) in
//At this point the debbugger throws> TTSPlaybackEnqueueFullAudioQueueBuffer: error -66686 enqueueing buffer several times (due to this callback is called several times)
            guard let pcmBuffer = buffer as? AVAudioPCMBuffer else {
                fatalError("unknown buffer type: \(buffer)")
            }
            if pcmBuffer.frameLength == 0 {
                // Done
            } else {

                do{
                    // this closure is called multiple times. so to save a complete audio, try create a file only for once.

                    let fileURL = self.soundsDirectoryURL()!.appendingPathComponent("test.wav")
                    if output == nil {
                        try  output = AVAudioFile(
                            forWriting: fileURL,
                            settings: pcmBuffer.format.settings,
                            commonFormat: .pcmFormatInt16,
                            interleaved: false)
                    }
                    try output?.write(from: pcmBuffer)

                }catch {
                    print(error.localizedDescription)
                }

            }

        }
    }

And I thought I was doing something wrong. This still hasn't been fixed.

Does anyone know how to hide this error in the console? The writing of the speech works fine, so for now I'd just like to ignore just this error (which comes up dozens of times with what I'm working on).

AVSpeechSynthesizer write method is broken in iOS 16
 
 
Q