iosswiftavspeechsynthesizeravspeechutterance

Using two instances of AVSpeechSynthesizer simultaneously


I would like to use two instances of AVSpeechSynthesizer simultaneously.

let firstSynthesizer = AVSpeechSynthesizer()
let secondSynthesizer = AVSpeechSynthesizer()

func foo() {
   let utterance = AVSpeechUtterance(string: "Foo Foo Foo Foo Foo")
   utterance.rate = 0.4
   utterance.voice = AVSpeechSynthesisVoice(language: "en-US")
   firstSynthesizer.speak(utterance)
}

func bar() {
   let utterance = AVSpeechUtterance(string: "Bar Bar Bar Bar Bar")
   utterance.rate = 0.4
   utterance.voice = AVSpeechSynthesisVoice(language: "en-US")
   secondSynthesizer.speak(utterance)
}

When I call foo() and bar(), the texts are not read at the same time but one after the other.


Solution

  • I would like to use two instances of AVSpeechSynthesizer simultaneously.

    It's definitely not possible in iOS 12, only one speech synthesis is vocally processed at a time.

    However, an audio session can be played together with the speech synthesis.