Skip to content

Instantly share code, notes, and snippets.

@FedeRotoli
Created March 31, 2020 13:57
Show Gist options
  • Save FedeRotoli/d16d570974fe0aca1c53f86dcb23e4bf to your computer and use it in GitHub Desktop.
Save FedeRotoli/d16d570974fe0aca1c53f86dcb23e4bf to your computer and use it in GitHub Desktop.
private func startAudioEngine() {
do {
let request = try SNClassifySoundRequest(mlModel: soundClassifier.model)
try analyzer.add(request, withObserver: resultsObserver)
} catch {
print("Unable to prepare request: \(error.localizedDescription)")
return
}
audioEngine.inputNode.installTap(onBus: 0, bufferSize: 8000, format: inputFormat) { buffer, time in
self.analysisQueue.async {
self.analyzer.analyze(buffer, atAudioFramePosition: time.sampleTime)
}
}
do{
try audioEngine.start()
}catch( _){
print("error in starting the Audio Engin")
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment