致命错误:AudioKit:无法启动引擎。 AudioKit.start()

时间:2018-02-01 11:02:37

标签: audiokit

import UIKit

import Photos

import AudioKit

import AudioKitUI

class VoicesController: CaptureContentController {
    @IBOutlet weak var nodeOutputPlot: AKNodeOutputPlot!

    @IBOutlet weak var recordButton: UIButton!

    @IBAction func recordButtonAction(_ sender: UIButton, forEvent event: UIEvent) {
        guard let phase = event.allTouches?.first?.phase else {
            return
        }

        if phase == .began {
            try? nodeRecorder.record()
        }

        if phase == .ended {
            nodeRecorder.stop()

            try? audioPlayer.reloadFile()

            let fileName = NSUUID().uuidString + ".wav"
            audioPlayer.audioFile.exportAsynchronously(name: fileName, baseDir: .documents, exportFormat: .wav, callback: { [weak self] (audioFile, error) in
                if let error = error {
                    print(#line, error)

                    return
                }

                //                // FIXME:
                //                if let url = audioFile?.avAsset.url {
                //                    _ = PHAssetChangeRequest.creationRequestForAssetFromVideo(atFileURL: url)!
                //                    // creationRequest.location
                //                }

                if let fileName = audioFile?.avAsset.url.lastPathComponent {
                    let asset = VPFAsset()
                    asset.mediaType = .audio
                    asset.urlString = fileName
                    asset.thumbUrlString = ""

                    self?.captureDelegate?.append(asset)
                }
            })
        }
    }

    var audioPlayer: AKAudioPlayer!

    var nodeRecorder: AKNodeRecorder!

    var micMixer: AKMixer!

    var mainMixer: AKMixer!

    var booster: AKBooster!

    var moogLadder: AKMoogLadder!

    let microphone = AKMicrophone()

    @objc func didBecomeActive(_ notification: Notification) {
        AudioKit.start()
    }



@objc func willResignActive(_ notification: Notification) {
    AudioKit.stop()
}

override func viewDidLoad() {
    super.viewDidLoad()
    // Do any additional setup after loading the view.
    AKAudioFile.cleanTempDirectory()

    AKSettings.bufferLength = .medium

    do {
        try AKSettings.setSession(category: .playAndRecord)
    } catch {
        print(error)
    }

    AKSettings.defaultToSpeaker = true

    nodeOutputPlot.node = microphone
    micMixer = AKMixer(microphone)
    booster = AKBooster(micMixer)

    booster.gain = 0
    nodeRecorder = try? AKNodeRecorder(node: micMixer)
    if let audioFile = nodeRecorder.audioFile {
        audioPlayer = try? AKAudioPlayer(file: audioFile)
        audioPlayer.completionHandler = {
            print(#line)
        }
    }

    moogLadder = AKMoogLadder(audioPlayer)
    mainMixer = AKMixer(moogLadder, booster)
    AudioKit.output = mainMixer

    AudioKit.start()

    NotificationCenter.default
        .addObserver(self, selector: #selector(didBecomeActive), name: .UIApplicationDidBecomeActive, object: nil)

    NotificationCenter.default
        .addObserver(self, selector: #selector(willResignActive), name: .UIApplicationWillResignActive, object: nil)
}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}

deinit {
    print("deinit VoicesController")

    AudioKit.stop()

    NotificationCenter.default
        .removeObserver(self)
}

}

您好,我的英文不好,我是中文,我真的很喜欢AudioKit,因为很方便,但是在最近的系统更新中,我遇到了崩溃,但并不总是崩溃,似乎只会崩溃一次,在没有崩溃之后,我做了截图,因为系统并不总是更新,希望得到帮助,非常感谢,我是新手,请指教

这是截图

线程1:致命错误:AudioKit:无法启动引擎。错误:错误Domain = com.apple.coreaudio.avfaudio Code = -10875“(null)”UserInfo = {failed call = err = AUGraphParser :: InitializeActiveNodesInOutputChain(ThisGraph,kOutputChainOptimizedTraversal,* GetOutputNode(),isOutputChainActive)}。

1 个答案:

答案 0 :(得分:0)

In the latest develop branch (not yet released), you have to wrap AudioKit.start() in a do try catch block

do {
    try AudioKit.start()
} catch {
    AKLog("Something went wrong.")
}

All of the examples included with AudioKit show how to implement this change.