2

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.

narner
  • 2,908
  • 3
  • 26
  • 63

4 Answers4

2

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

CedricSoubrie
  • 6,657
  • 2
  • 39
  • 44
  • Yup, that seems to solve that particular issue so marked as correct (though now getting a different error of: *** Terminating app due to uncaught exception 'com.apple.coreaudio.avfaudio', reason: 'required condition is false: inputNode != nullptr || outputNode != nullptr') – narner Nov 04 '19 at 17:03
  • 2
    I also got this error :-) It means your engine doesn't have any input or output when you start it. In my case, I had the error because I was calling `audioEngine.start()` before `audioEngine.inputNode.installTap()` – CedricSoubrie Nov 05 '19 at 12:26
1

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

Thomas Besnehard
  • 2,106
  • 3
  • 25
  • 47
0

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.

Malloc
  • 15,434
  • 34
  • 105
  • 192
0

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).

jengelsma
  • 8,192
  • 4
  • 21
  • 21