Skip to content

Instantly share code, notes, and snippets.

@FedeRotoli
Created March 31, 2020 14:05
Show Gist options
  • Save FedeRotoli/97a0ca5a8a4875b4685edce433f8538f to your computer and use it in GitHub Desktop.
Save FedeRotoli/97a0ca5a8a4875b4685edce433f8538f to your computer and use it in GitHub Desktop.
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