同时使用两个 AVSpeechSynthesizer 实例
Using two instances of AVSpeechSynthesizer simultaneously
我想同时使用两个 AVSpeechSynthesizer 实例。
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)
}
当我调用foo()
和bar()
时,文本不是同时阅读而是一个接一个阅读。
I would like to use two instances of AVSpeechSynthesizer simultaneously.
iOS12肯定不行,一次只处理一个语音合成。
但是an audio session可以和语音合成一起播放
我想同时使用两个 AVSpeechSynthesizer 实例。
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)
}
当我调用foo()
和bar()
时,文本不是同时阅读而是一个接一个阅读。
I would like to use two instances of AVSpeechSynthesizer simultaneously.
iOS12肯定不行,一次只处理一个语音合成。
但是an audio session可以和语音合成一起播放