'Error updating tree format' when using iOS SoundAnalysis Framework

Viewed 459

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.

4 Answers

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

I've got the same error, it seam to be around let inputFormat = audioEngine.inputNode.inputFormat(forBus: 0), but no more info for now.

I had the exact same error, pretty obvious for my case this was because I was testing on simulator with no built-in microphone input. I got rid of this once I switched to real device.

I experienced this same exception with very similar init code running on the simulator. For me the problem disappeared after I simply restarted the simulator (Device > Restart).

Related