How to detect end of speech with Nuance Vocalizer, Speechkit 2, for iOS

520 Views Asked by At

I am using Nuance's Speechkit 2 with swift, iOS 9.3. Ineed to detect when the TTS finishes, according to this documentation:

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

...These are the 3 delegate methods available for TTS:

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

Also, here is a sample Swift project (https://developer.nuance.com/public/index.php?task=prodDev), where the TTS example uses an extra, SKAudioPlayerDelegate, and in the code I saw this delegate method, however it NEVER triggers:

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

I am calling TTS with:

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

However, "didFinishWithSuggestion" always triggers long before the TTS voice has finished speaking, which seems like a bug for me. Nuance technical support won't reply, can anybody help me? Thanks.

1

There are 1 best solutions below

0
On BEST ANSWER

I found the solution. It turns out, that a 2nd delegate is responsible for detecting the beginning, and end, of TTS playback:

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

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

These are the delegate methods:

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