Created
March 31, 2020 14:05
-
-
Save FedeRotoli/97a0ca5a8a4875b4685edce433f8538f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
protocol EmotionClassifierDelegate { | |
func displayPredictionResult(identifier: String, confidence: Double) | |
} | |
extension SoundAnalyzerController: EmotionClassifierDelegate { | |
func displayPredictionResult(identifier: String, confidence: Double) { | |
DispatchQueue.main.async { | |
let roundConfidence = Double(round(100*confidence)/100) | |
self.transcriberText.text = ("Recognition: \(identifier) with Confidence \(roundConfidence)") | |
} | |
} | |
} | |
class ResultsObserver: NSObject, SNResultsObserving { | |
var delegate: EmotionClassifierDelegate? | |
func request(_ request: SNRequest, didProduce result: SNResult) { | |
guard let result = result as? SNClassificationResult, | |
let classification = result.classifications.first else { return } | |
let confidence = classification.confidence * 100.0 | |
if confidence > 60 { | |
delegate?.displayPredictionResult(identifier: classification.identifier, confidence: confidence) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment