如何使用Nuance Vocalizer,Speechkit 2,为iOS检测语音结束

时间:2016-06-29 15:39:34

标签: ios swift swift2 text-to-speech speechkit

我正在使用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技术支持无法回复,任何人都可以帮助我吗?感谢。

1 个答案:

答案 0 :(得分: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")
}