我有一个不工作的代码块,但也没有给我一个运行时错误。演讲者没有讲话。
let synth = AVSpeechSynthesizer()
var myUtterance = AVSpeechUtterance(string: audioTextField.text)
myUtterance.rate = 0.3
synth.speak(myUtterance)有没有什么我遗漏的代码,或者是别的什么?如果能帮上忙,我们将不胜感激。
编辑:它在任何@IBActions中都不工作,但在视图的加载函数中工作得很好……
override func viewDidLoad() {
super.viewDidLoad()
speechRecognizer?.delegate = self
timer = Timer.scheduledTimer(timeInterval: 1.0, target: self, selector: #selector(tick), userInfo: nil, repeats: true)
tick()
requestSpeechAuth()
//WORKS HERE
}
@IBAction func audioButtonPressed(_ sender: Any) {
//DOESN"T WORK HERE
if isRecording {
stopRecording()
} else {
startRecording()
}
}发布于 2017-02-03 20:15:36
这段代码工作正常(来自Apple文档)
let string = "Hello, World!"
let utterance = AVSpeechUtterance(string: string)
utterance.voice = AVSpeechSynthesisVoice(language: "en-US")
let synth = AVSpeechSynthesizer()
synth.speak(utterance)记住要导入AVFoundation
import AVFoundationhttps://stackoverflow.com/questions/42023612
复制相似问题