1

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)
4

2 回答 2

0

我认为处理这种情况的最简单方法是将两个字符串与space.

let combineString = dptext.text! + " " + dptext2.text!
let utterance = AVSpeechUtterance(string: combineString)
let synthesizer = AVSpeechSynthesizer()
synthesizer.speak(utterance)
于 2017-06-23T05:32:06.457 回答
0

我希望先说出话语,然后在完成后立即说出 utterance2。

没有必要为要说出的两个话语进行连接:要记住的最重要的事情是保留您的AVSpeechSynthesizer实例,直到完成完整的演讲

let synthesizer = AVSpeechSynthesizer()

override func viewDidAppear(_ animated: Bool) {
    super.viewDidAppear(animated)
    
    let utterance = AVSpeechUtterance(string: dptext.text!)
    let utterance2 = AVSpeechUtterance(string: dptext2.text!)
    
    synthesizer.speak(utterance)
    synthesizer.speak(utterance2)
}

按照这个原理,您可以:

  • 说话时为话语添加前/后延迟。
  • 让尽可能多的话语说话。

每一个话语都将被放入语音合成器队列中,并按照接收到的顺序被说出。

于 2019-05-07T19:54:07.380 回答