             return
         }
 
+        // Revert AVAudioSession Category to previous settings
+        #if os(iOS)
+            do {
+                if previousAVAudioSessionCategory != nil {
+                    try AVAudioSession.sharedInstance().setCategory(previousAVAudioSessionCategory!)
+                } else {
+                    try AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategoryAmbient)
+                    print ("AKNodeRecorder Error: previousAVAudioSessionCategory is nil !")
+                    print ("AKNodeRecorder: AVAudioSession Category set to \"Ambient\".")
+                }
+            } catch {
+                assertionFailure("AKAudioFileRecorder Error: AVAudioSession setup error: \(error)")
+            }
+        #endif
+
+
+
+
         recording = false
         if  node != nil {
             node!.avAudioNode.removeTapOnBus(0)

            return
        }

        if  node != nil {
            recording = true

            print ("recording")
            node!.avAudioNode.installTapOnBus(0, bufferSize: bufferSize, format: tape.processingFormat, block: { (buffer: AVAudioPCMBuffer!, time: AVAudioTime!) -> Void in
                do {

    private var bufferSize: AVAudioFrameCount
    private var recording = false


    private let previousAVAudioSessionCategory: String?

    public init(node: AKNode = AudioKit.output!, file: AKAudioFile? = nil, buffer bufferSize: UInt32 = 1024  ) throws {


        // requestRecordPermission...
        var permissionGranted: Bool = false
        #if os(iOS)

            self.previousAVAudioSessionCategory = AVAudioSession.sharedInstance().category

            AVAudioSession.sharedInstance().requestRecordPermission({(granted: Bool)-> Void in
                if granted {
                    permissionGranted = true
                } else {
                    permissionGranted = false
                }
            })

            if !permissionGranted {
                print("AKNodeRecorder Error: Permission to record not granted")
                throw NSError(domain: NSURLErrorDomain, code: NSURLErrorUnknown, userInfo: nil)
            }
        #endif

        // AVAudioSession buffer setup

        self.bufferSize = bufferSize
        if file == nil {
            // We create a record file in temp directory
            do {
