self.synthesizer.write(utterance) { buffer in
DispatchQueue.main.async {
guard let pcmBuffer = buffer as? AVAudioPCMBuffer, pcmBuffer.frameLength > 0 else {
return
}
// Need to convert the buffer to different format because AVAudioEngine does not support the format returned from AVSpeechSynthesizer
guard self.converter != nil,
let pcmFormat = AVAudioFormat(commonFormat: AVAudioCommonFormat.pcmFormatFloat32, sampleRate: pcmBuffer.format.sampleRate, channels: pcmBuffer.format.channelCount, interleaved: false), let convertedBuffer = AVAudioPCMBuffer(pcmFormat: pcmFormat, frameCapacity: pcmBuffer.frameCapacity) else {
return
}
do {
try self.converter?.convert(to: convertedBuffer, from: pcmBuffer)
self.bufferCounter += 1
self.scheduleNextBuffer(convertedBuffer)
self.converter?.reset()
}
catch {
self.handleTextToSpeechError()
}
}
}
When playing audio from Text to Speech using AVSpeechSynthesizer write method with AVAudioFormat and AVAudioPCMBuffer, the audio is choppy and sounds distorted. This was not an issue on iOS 16 and below.
Post not yet marked as solved
Up vote post of ThinningThoughts
Down vote post of ThinningThoughts
354
views
This issue is frequently happen in iOS 17 Beta 1
This issue is frequently happen in iOS 17 Beta 2