AVSpeechSynthesizer executes utterances out of order

In previous releases of the os, AVSpeechSynthesizer executed utterances in the order that were enqueued - this is no longer the case. The following snippet should read the numbers 0 to 100 in order, instead it is read (as far as I can tell) randomly.

I am unsure is this was an intentional change by Apple, if it was, this was not communicated effectively to developers.

import SwiftUI
import AVFoundation

@main struct MyApp: App {
    var body: some Scene {
        WindowGroup {
            ContentView()
        }
    }
}

struct ContentView: View {
    let synthesiser = AVSpeechSynthesizer()
    var body: some View {
        Button("Synthesise") {
            for i in 0...100 {
                let utterance = AVSpeechUtterance(string: i.formatted())
                synthesiser.speak(utterance)
            }
        }
    }
}

#Preview {
    ContentView()
}

FB23194665

Answered by DTS Engineer in 894072022

Hello @The-Wolf,

As documented, AVSpeechSynthesizer is designed to maintain a queue of utterances and speak them in the order they are received. If the synthesizer is already speaking, new utterances are added to this queue and processed sequentially.

It sounds like that behavior has broken in iOS 27 beta. Thank you for filing that Feedback! The appropriate engineering team will be investigating.

Lastly, please continue updating your Feedback on each new release in this beta cycle.

-- Greg

Hello @The-Wolf,

As documented, AVSpeechSynthesizer is designed to maintain a queue of utterances and speak them in the order they are received. If the synthesizer is already speaking, new utterances are added to this queue and processed sequentially.

It sounds like that behavior has broken in iOS 27 beta. Thank you for filing that Feedback! The appropriate engineering team will be investigating.

Lastly, please continue updating your Feedback on each new release in this beta cycle.

-- Greg

AVSpeechSynthesizer executes utterances out of order
 
 
Q