mardi 11 septembre 2018

Swift- Only run text to speech audio if the text is different than the previous

I am trying to combine Apple machine learning with the simple aspects of the AVFoundation. I want the sound to only repeat if the identifier is different than what it was in the previous reading. Currently, it repeats the sound like 10 times for each identifier. I'm confused as to how I can save the current identifier and compare it with the next identifier (or compare the current identifier with the previous identifier).

var previousSound = firstObservation.identifier

if(previousSound != firstObservation.identifier){

print(firstObservation.identifier, firstObservation.confidence)
        let utterance = AVSpeechUtterance(string: "\    (firstObservation.identifier)")
        utterance.voice = AVSpeechSynthesisVoice(language: "en-GB")


let synthesizer = AVSpeechSynthesizer()
        synthesizer.speak(utterance)

} 

I know that currently the same variable is being checked and it will always be true. However, I cannot think of a way to save the previous identifier without making it the same as the current identifier. Thanks for your help.

Aucun commentaire:

Enregistrer un commentaire