title: How can I specify the format of AVAudioEngine Mic-Input?
body: <p>I'd like to record the some audio using <code>AVAudioEngine</code> and the users Microphone. I already have a working sample, but just can't figure out how to specify the format of the output that I want...</p>
  
  <p>My requirement would be that I need the <code>AVAudioPCMBuffer</code> as I speak which it currently does...</p>
  
  <p>Would I need to add a seperate node that does some transcoding? I can't find much documentation/samples on that problem...</p>
  
  <p>And I am also a noob when it comes to Audio-Stuff. I know that I want <code>NSData</code> containing PCM-16bit with a max sample-rate of 16000 (8000 would be better)</p>
  
  <p>Here's my working sample:</p>
  
  <pre><code>private var audioEngine = AVAudioEngine()
  
  func startRecording() {
  
    let format = audioEngine.inputNode!.inputFormatForBus(bus)
  
    audioEngine.inputNode!.installTapOnBus(bus, bufferSize: 1024, format: format) { (buffer: AVAudioPCMBuffer, time:AVAudioTime) -&gt; Void in
  
       let audioFormat = PCMBuffer.format
       print("\(audioFormat)")
    }
  
    audioEngine.prepare()
    do {
       try audioEngine.start()
    } catch { /* Imagine some super awesome error handling here */ }
  }
  </code></pre>
  
  <p>If I changed the format to let' say</p>
  
  <pre><code>let format = AVAudioFormat(commonFormat: AVAudioCommonFormat.PCMFormatInt16, sampleRate: 8000.0, channels: 1, interleaved: false)
  </code></pre>
  
  <p>then if will produce an error saying that the sample rate needs to be the same as the hwInput... </p>
  
  <p>Any help is very much appreciated!!!</p>
  
  <p><strong>EDIT:</strong> I just found <code>AVAudioConverter</code> but I need to be compatible with iOS8 as well...</p>