iosswiftcoremlcreateml

'Error updating tree format' when using iOS SoundAnalysis Framework


I'm using the SoundAnalysis framework in conjunction with a CoreML model I created using CreateML.

I was able to use SNAudioFileAnalyzer to perform an analysis on audio files embedded in the app bundle, but not when using SNAudioStreamAnalyzer on live audio from the microphone.

when using the code below:

    // Create a new audio engine.
    audioEngine = AVAudioEngine()

    //https://forums.developer.apple.com/thread/44833
    audioEngine.mainMixerNode

    do {
        // Start the stream of audio data.
        try audioEngine.start()
    } catch {
        print("Unable to start AVAudioEngine: \(error.localizedDescription)")
    }

    // Get the native audio format of the engine's input bus.
    let inputFormat = audioEngine.inputNode.inputFormat(forBus: 0)

    // Create a new stream analyzer.
    var streamAnalyzer = SNAudioStreamAnalyzer(format: inputFormat)

I'm getting an error at the last line of:

*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Error updating tree format'

Anyone have any idea? Right now there isn't much written about the SoundAnalysis Framework, so feeling somewhat out in the woods on this one.


Solution

  • I just got ride of the error by setting AVAudioSession.sharedInstance().setCategory(.playAndRecord)