0

我正在使用 Nuance 的 Speechkit 2 和 swift,iOS 9.3。根据本文档,需要检测 TTS 何时完成:

https://developer.nuance.com/public/Help/DragonMobileSDKReference_iOS/Speech-synthesis.html

...这些是可用于 TTS 的 3 种委托方法:

// SKTransactionDelegate
func transaction(transaction: SKTransaction!, didReceiveAudio audio: SKAudio!) { ... }
func transaction(transaction: SKTransaction!, didFinishWithSuggestion suggestion: String!) { ... }
func transaction(transaction: SKTransaction!, didFailWithError error: NSError!, suggestion: String!) { ... }

此外,这里是一个示例 Swift 项目(https://developer.nuance.com/public/index.php?task=prodDev),其中 TTS 示例使用了一个额外的 SKAudioPlayerDelegate,在代码中我看到了这个委托方法,但是它永远不会触发:

func audioPlayer(player: SKAudioPlayer!, willBeginPlaying audio: SKAudio!) {
        log("willBeginPlaying")
        // The TTS Audio will begin playing.
    }

我打电话给 TTS:

var skTransaction = skSession!.speakString("a long sentence here",withLanguage: "eng-USA",delegate: self)

但是,“didFinishWithSuggestion”总是在 TTS 语音说完之前触发,这对我来说似乎是一个错误。Nuance 技术支持不会回复,有人可以帮助我吗?谢谢。

4

1 回答 1

0

我找到了解决方案。事实证明,第二个代表负责检测 TTS 播放的开始和结束:

class ViewController: UIViewController, SKAudioPlayerDelegate{
    //All your view controller code here...

    func viewDidLoad(){
       //more init. code 
       skSession!.audioPlayer.delegate=self
   }
}

这些是委托方法:

func audioPlayer(player: SKAudioPlayer!, willBeginPlaying audio: SKAudio!){
  print("Starting TTS")
}
func audioPlayer(player: SKAudioPlayer!, didFinishPlaying audio: SKAudio!) {
   print("TTS FINISHED")
}
于 2016-07-05T13:06:32.610 回答