     recorder.meteringEnabled = metering
   }
 
-  public func record() {
+  public func record() throws {
     if recorder == nil {
-      prepare()
+      try prepare()
     }
 
-    session.setCategory(AVAudioSessionCategoryRecord, error: nil)
+    try session.setCategory(AVAudioSessionCategoryPlayAndRecord)
+    try session.overrideOutputAudioPort(AVAudioSessionPortOverride.Speaker)
 
     recorder.record()
 

  private func stopMetering() {
    link?.invalidate()
  }

}

    recorder.stop()
  }

  public func play() throws {
    try session.setCategory(AVAudioSessionCategoryPlayback)

    player = try AVAudioPlayer(contentsOfURL: url)
    player.play()
  }

  public func updateMeter() {
    recorder.updateMeters()

    let dB = recorder.averagePowerForChannel(0)

    delegate.audioMeterDidUpdate?(dB)
  }
