Hello there, I have a piece of code that write text-to-speech audios into local files. However it stopped working since iOS 16.
I have checked a similar post and can confirm there is a strong reference to the instance of AVSpeechSynthesizer
across the app lifecycle.
This looks like a regression in AVFoundation for iOS 16. Could someone take a look and help?
let utterance = AVSpeechUtterance(string: text.text)
utterance.voice = AVSpeechSynthesisVoice(language: text.languageCode)
let soundDir = try FileManager.default.soundDir()
let fileURL = text.fileURL(baseURL: soundDir)
var avFile: AVAudioFile?
self.avSpeechSynthesizer.write(utterance) { (buffer: AVAudioBuffer) in
//This closure is never called in iOS 16
guard let pcmBuffer = buffer as? AVAudioPCMBuffer else {
fatalError("unknown buffer type: \(buffer)")
}
if pcmBuffer.frameLength != 0 {
if avFile == nil {
avFile = try? AVAudioFile(
forWriting: fileURL,
settings: pcmBuffer.format.settings,
commonFormat: .pcmFormatInt16,
interleaved: false
)
}
try? avFile?.write(from: pcmBuffer)
}
}
The Xcode console output that might be relevant:
2022-09-17 14:57:44.732219-0700 CueTimer[38975:1142525] [AXTTSCommon] File did not exist at content path: (null) (null). Attempting to fallback to default voice for language: (null)
2022-09-17 14:57:44.741347-0700 CueTimer[38975:1142480] [catalog] Unable to list voice folder
2022-09-17 14:57:44.757943-0700 CueTimer[38975:1142480] [catalog] Unable to list voice folder
2022-09-17 14:57:44.761232-0700 CueTimer[38975:1142480] [catalog] Unable to list voice folder
2022-09-17 14:57:44.772778-0700 CueTimer[38975:1142480] [catalog] Unable to list voice folder
2022-09-17 14:57:44.799620-0700 CueTimer[38975:1142525] [AXTTSCommon] Error: Unable to speak. No speech service: voice: (null) identifier: (null), language: (null), resource: (null)