Post

Replies

Boosts

Views

Activity

Reply to AVSpeechSynthesizer write method is broken in iOS 16
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) } } } }
Oct ’22