[add] TTS 暫停等功能
This commit is contained in:
@@ -13,16 +13,28 @@ class TTS_S: NSObject {
|
||||
|
||||
let synth = AVSpeechSynthesizer()
|
||||
|
||||
// 播放
|
||||
@IBAction func play(msg: String) {
|
||||
|
||||
let myUtterance = AVSpeechUtterance(string: msg)
|
||||
myUtterance.voice = AVSpeechSynthesisVoice(language: "zh-TW")
|
||||
myUtterance.rate = 0.5
|
||||
synth.speak(myUtterance)
|
||||
}
|
||||
|
||||
@IBAction func endHandler(_ sender: UIButton) {
|
||||
synth.stopSpeaking(at: .word)
|
||||
// 暂停
|
||||
@IBAction func pause() {
|
||||
synth.pauseSpeaking(at: .immediate)
|
||||
}
|
||||
|
||||
// 继续
|
||||
@IBAction func continuePlay() {
|
||||
synth.continueSpeaking()
|
||||
|
||||
}
|
||||
|
||||
// 停止
|
||||
@IBAction func stopPlay() {
|
||||
synth.stopSpeaking(at: .immediate)
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user