ios - 如何使用 iOS 版 Nuance Vocalizer、Speechkit 2 检测语音结束

标签 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 种委托(delegate)方法:

// 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,并且在代码中我看到了此委托(delegate)方法,但它永远不会触发:

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 技术支持不会回复,有人可以帮助我吗?谢谢。

最佳答案

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

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

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

这些是委托(delegate)方法:

func audioPlayer(player: SKAudioPlayer!, willBeginPlaying audio: SKAudio!){
  print("Starting TTS")
}
func audioPlayer(player: SKAudioPlayer!, didFinishPlaying audio: SKAudio!) {
   print("TTS FINISHED")
}

关于ios - 如何使用 iOS 版 Nuance Vocalizer、Speechkit 2 检测语音结束,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38104248/

相关文章:

ios - 从按钮快速删除 uitableview 中的最后一个单元格

c# - 如何声明全局变量

ios - 我似乎无法让物理机构在 Playground 内工作

ios - 设置 WatchKit 表

ios - NSData 初始化?(contentsOf url : URL) migration from Swift 2 to Swift 3

ios - 移动我的 SpriteNode Swift SpriteKit

ios - 当应用程序在同一 View iOS Swift 时限制 segue

ios - 如何在 ios 中以编程方式获取设备序列号?

ios - UIViewRepresentable 在 SwiftUI 中列表单元格内的放置

ios - 如何从 Eureka 中的 ImageRow 访问所选图像?