使用 Xcode 7.2 ,不同的部署目标(例如7.1和9.2)和不同的虚拟设备(例如iPhone 6s plus和iPhone 5s)我无法切换语音TTS语言。这是我的代码:
z=theano.function([x],w_v_bias)
z(datax[0])
两种文本都被阅读,但仅限于设备的标准语言。
此外,当我运行代码时出现以下错误:
import UIKit
import AVFoundation
class ViewController: UIViewController {
let synth = AVSpeechSynthesizer()
var myUtterance = AVSpeechUtterance()
func speak(locale: String, text: String) {
if let voice = AVSpeechSynthesisVoice(language: locale) {
myUtterance.voice = voice
// I read that the delays might cure the issue,
// but they don't. Language switching does not
// work with or without this.
myUtterance.preUtteranceDelay = 0.005
myUtterance.postUtteranceDelay = 0.005
// I read that an empty text cures the issue,
// but is doesn't. Language switching does not
// work with or without this.
for t in [" ", text] {
myUtterance = AVSpeechUtterance(string: t)
synth.speakUtterance(myUtterance)
}
} else {
debugPrint("bad voice")
}
}
override func viewDidLoad() {
super.viewDidLoad()
speak("de-DE", text: "Ich blicke auf einen blauen Himmel!")
speak("en-US", text: "This is a text, which I like very much!")
}
}
在iPhone 4上运行应用程序(不是虚拟的,它是iOS 7.1.2的真实设备)应用程序启动并且不会发生此错误,但TTS根本不起作用。
提前多多感谢