在使用Swift提供引号时,我遇到了重复相同命令的问题。
这是我现在所拥有的
import AVFoundation
import PlaygroundSupport
PlaygroundPage.current.needsIndefiniteExecution = true
let QuoteArray = [
"Quote1",
"Quote2",
"Quote3",
]
let max = QuoteArray.count
let synthesizer = AVSpeechSynthesizer()
let utterance = AVSpeechUtterance(string: QuoteArray[Int.random(in: 0 ... max)])
utterance.rate = 0.5
utterance.voice = AVSpeechSynthesisVoice(language: "en-AU")
synthesizer.speak(AVSpeechUtterance(string: QuoteArray[Int.random(in: 0 ... max)]))
sleep(5)
synthesizer.speak(AVSpeechUtterance(string: QuoteArray[Int.random(in: 0 ... max)]))
sleep(10)
synthesizer.speak(AVSpeechUtterance(string: QuoteArray[Int.random(in: 0 ... max)]))我不知道如何选择一个随机阵列的位置,以及如何在合成声音和速度上游走。我试图使它,使3个随机引用被随机阅读,但我似乎无法使它正常工作。
如果我修改最后几行,而不是AVSpeechUtterance(string...,他们说utterance,我不能运行第2或第3引号,因为SIGBART错误。
有什么想法吗?
utterance.rate = 35
utterance.pitchMultiplier = 3
utterance.voice = AVSpeechSynthesisVoice(language: "en-AU")
synth.speak(utterance)
sleep(5)
synth.speak(utterance)
sleep(10)
synth.speak(utterance)
sleep(15)如果我试图把它带回到这些话语,我会得到一个
error: Execution was interrupted, reason: signal SIGABRT.
The process has been left at the point where it was interrupted, use "thread return -x" to return to the state before expression evaluation."

发布于 2019-05-25 13:03:41
我不知道如何选择一个随机排列的位置.
下面是在操场空白项目中测试您的问题的解决方案( iOS 12):
import AVFoundation
import UIKit
let synthesizer = AVSpeechSynthesizer()
let QuoteArray = ["Quote1",
"Quote2",
"Quote3"]
func newRandomUtterance() -> AVSpeechUtterance {
let utterance = AVSpeechUtterance(string: QuoteArray[Int.random(in: 0..<QuoteArray.count)])
utterance.rate = AVSpeechUtteranceDefaultSpeechRate
utterance.voice = AVSpeechSynthesisVoice(language: "en-GB")
return utterance
}
for _ in 1...3 { synthesizer.speak(newRandomUtterance()) }..。在综合的声音和速度上胡闹。
有一个详细摘要的WWDC 2018年视频处理语音合成器和一个代码片段的完整解释 (ObjC和Swift),如果上面的例子是不够的。
现在您可以获取一个随机数组并使用特定的语音。
https://stackoverflow.com/questions/56298828
复制相似问题