textswift3avfoundationavspeechsynthesizeravspeechutterance

Join 2 different labels for text to speech conversion (swift3)


Using the speech to text feature I can easily get one label to be spoken. But I want utterance2 to be joined to utterance. I want utterance to be spoken first then when it is finished for utterance2 to be spoken right after.

     let utterance = AVSpeechUtterance(string: dptext.text!)
     let utterance2 = AVSpeechUtterance(string: dptext2.text!)

     let synthesizer = AVSpeechSynthesizer()
     synthesizer.speak(utterance)

Solution

  • I think the simplest way to handle this situation is to combine the two string with space.

    let combineString = dptext.text! + " " + dptext2.text!
    let utterance = AVSpeechUtterance(string: combineString)
    let synthesizer = AVSpeechSynthesizer()
    synthesizer.speak(utterance)