gpt4 book ai didi

IOS/swift/AVSpeechSynthesizer : Control Speed of Enqueued Utterances

转载 作者:行者123 更新时间:2023-11-29 13:54:54 25 4
gpt4 key购买 nike

为了本着this tutorial的精神对言论施加更大的控制对于有声读物,虽然我没有完全遵循它,但我尝试发送较小的字符串片段,例如单独 block 中的短语。语音合成器将每个话语排入队列并一个接一个地说出来。从理论上讲,这应该可以让您更好地控制语音听起来不那么机械化。

我可以让合成器按顺序说出这些 block ,但是每个 block 之间有很长的延迟,所以这听起来比同时发送所有文本要糟糕得多。

有没有办法加快队列的速度,让话语一个接一个地讲出来,没有延迟?

将属性:utt.preUtteranceDelay 和 utt.postUtteranceDelay 设置为零秒似乎没有任何效果

这是我的代码:

phraseCounter = 0
func readParagraph(test: String) {
let phrases = test.components(separatedBy: " ")
for phrase in phrases {
phraseCounter = phraseCounter+1
let utt = AVSpeechUtterance(string:phrase)
let preUtteranceDelayInSecond = 0
let postUtteranceDelayInSecond = 0
utt.preUtteranceDelay = TimeInterval.init(exactly:preUtteranceDelayInSecond)!
utt.postUtteranceDelay = TimeInterval.init(exactly:postUtteranceDelayInSecond)!
voice.delegate = self
if (phraseCounter == 2) {
utt.rate = .8
}
voice.speak(utt)
}
}

最佳答案

Is there anyway to speed up the queue so that the utterances are spoken one after the other with no delay?

正如您所做的,唯一的方法是将后置和前置 UtteranceDelay 属性设置为 0,顺便说一句,这是默认值。 enter image description here

推荐here ,我在 (Xcode 10、Swift 5.0 和 iOS 12.3.1) 之后实现了代码片段,以检查不同 UtteranceDelay 值的影响 ⟹ 0 是最佳解决方案提高排队话语的速度

var synthesizer = AVSpeechSynthesizer()
var playQueue = [AVSpeechUtterance]()


override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)

for i in 1...10 {

let stringNb = "Sentence number " + String(i) + " of the speech synthesizer."

let utterance = AVSpeechUtterance(string: stringNb)
utterance.rate = AVSpeechUtteranceDefaultSpeechRate
utterance.pitchMultiplier = 1.0
utterance.volume = 1.0

utterance.postUtteranceDelay = 0.0
utterance.preUtteranceDelay = 0.0

playQueue.append(utterance)
}

synthesizer.delegate = self

for utterance in playQueue {
synthesizer.speak(utterance)
}
}

如果延迟对于代码中的“0”值来说太重要了,传入的字符串可能是问题所在? (根据您的需要调整上面的代码片段)

关于IOS/swift/AVSpeechSynthesizer : Control Speed of Enqueued Utterances,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57172098/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com