title: Swift + AVAudioRecorder records very quietly
body: <p>I have built an iOS App in Swift that records audio clips, these clips are then sent up to the server. Every recording I make is very quiet.</p>
  
  <p>Initially I thought my problems were similar to this question on Stack Overflow - but after trying this solution, my recordings are still very quiet.</p>
  
  <p>Routing the audio through the speaker does not make the recordings any louder, as is suggested here:</p>
  
  <p><a href="https://stackoverflow.com/a/5662478/1037617">https://stackoverflow.com/a/5662478/1037617</a></p>
  
  <p>Note that its not playback on the device that is an issue. The issue is that the recordings are too quiet. I have tested the Microphone itself, and it is fine.</p>
  
  <p>This is the best waveform I can produce, and this is almost shouting into the Microphone. As you can see, the waveform recorded is very quiet:</p>
  
  <p><img src="https://i.stack.imgur.com/AxiJn.png" alt="This is the best waveform I can produce, and this is almost shouting into the Microphone. As you can see, the waveform recorded is very quiet."></p>
  
  <p>Is there any way of getting my iOS App to record at a louder volume?</p>
  
  <p>This is the code I am using to record the audio clips:</p>
  
  <pre><code>let recorderSettings=[
      AVFormatIDKey            : kAudioFormatLinearPCM,
      AVEncoderAudioQualityKey : AVAudioQuality.Max.rawValue,
      AVEncoderBitRateKey      : 128000,
      AVNumberOfChannelsKey    : 1,
      AVSampleRateKey          : 44100.0
  ]
  
  let session: AVAudioSession = AVAudioSession.sharedInstance()
  var error: NSError?
  if session.respondsToSelector("requestRecordPermission:") {
      AVAudioSession.sharedInstance().requestRecordPermission( { (granted:Bool) -&gt; Void in
          if !granted {
              println("permission not granted")
          }else{
              println("permission granted")
  
              if !session.setCategory(AVAudioSessionCategoryRecord, error: &amp;error) { // also tried PlaybackAndRecord
                  println("could not set sesssion category")
                  if let e = error {
                      println(e.localizedDescription)
                  }
              }
  
              if !session.overrideOutputAudioPort(AVAudioSessionPortOverride.Speaker, error: &amp;error) {
                  println("could not override output audio")
                  if let e = error {
                      println(e.localizedDescription)
                  }
              }
  
              if !session.setActive(true, error: &amp;error) {
                  println("could not make active")
                  if let e = error {
                      println(e.localizedDescription)
                  }
              }
  
              self.currentFilename = "xxxx.wav"
              let dirPaths = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true)
              let docsDir: AnyObject=dirPaths[0]
              self.recordedFilePath = docsDir.stringByAppendingPathComponent(self.currentFilename)
              self.recordedFileURL = NSURL(fileURLWithPath: self.recordedFilePath)
  
              self.recorder = AVAudioRecorder(URL:self.recordedFileURL, settings: self.recorderSettings, error: &amp;error)
  
              if let e = error {
                  println(e)
                  println(e.localizedDescription)
                  var err = NSError(domain: NSOSStatusErrorDomain, code: e.code, userInfo: nil)
                  println(err.description)
              }else{
  
                  self.recorder?.delegate = self
                  self.recorder?.meteringEnabled = true
                  self.recorder?.prepareToRecord()
  
                  self.recorder?.record()
  
                  self.meterTimer = NSTimer.scheduledTimerWithTimeInterval(0.1,
                      target: self,
                      selector: "updateRecordAudioMeter:",
                      userInfo: nil,
                      repeats: true)
  
              }
          }
      })
  }
  </code></pre>