【发布时间】:2021-01-16 01:52:05
【问题描述】:
大家好,这是我的代码:
func configureSpeechButton() {
contentView.addSubview(speechButton)
speechButton.setImage(speechImage, for: .normal)
speechButton.addTarget(self, action: #selector(speechButtontapped), for: .touchUpInside)
//Constraints
speechButton.translatesAutoresizingMaskIntoConstraints = false
speechButton.topAnchor.constraint(equalTo: contentView.topAnchor, constant: 40).isActive = true
speechButton.trailingAnchor.constraint(equalTo: contentView.trailingAnchor, constant: -20).isActive = true
speechButton.widthAnchor.constraint(equalToConstant: 50).isActive = true
speechButton.heightAnchor.constraint(equalToConstant: 50).isActive = true
}
@objc func speechButtontapped() {
let speech = AVSpeechUtterance(string: "\(testSpeech)")
speech.voice = AVSpeechSynthesisVoice(language: "de")
let synth = AVSpeechSynthesizer()
synth.speak(speech)
}
let testSpeech = "This is a test"
我将按钮放在滚动视图的内容视图上,谁能告诉我问题出在哪里?提前致谢
【问题讨论】:
-
您确定“de”语言代码是有效值吗?
标签: swift avfoundation siri