import SwiftUI
import SoundAnalysis

struct Findings {
   let name: String
   let start: TimeInterval
}
class AudioObserver: NSObject, SNResultsObserving {
   var findings: [Findings] = []

   func request(_ request: any SNRequest, didProduce result: any SNResult) {
      if let results = result as? SNClassificationResult {
         let classifications = results.classifications
         let sorted = classifications.sorted { $0.confidence > $1.confidence }

         if let classification = sorted.first, classification.confidence > 0.5 {
            let name = classification.identifier
            let time = results.timeRange.start.seconds
            findings.append(Findings(name: name, start: time))
         }
      }
   }
}