title: Using the default audio ouput for AVAudioEngine in iOS
body: <p>I'm trying to create a basic iOS application that let me record audio and then play it back in different speeds and pitches.</p>
  
  <p>I'm using <code>AVAudioPlayer</code> to play the recorded audio either slower or faster and it works as expected. The sound is played back in my headphones.</p>
  
  <p>I'm using <code>AVAudioEngine</code> to play the recorded audio in a different pitch and it works except that the audio is played back on my Thunderbolt display speakers, not my headphones.</p>
  
  <p>I've been going through the documentation in order to understand this behavior but come up short. In my view controller in the method, <code>viewDidLoad</code>, I've setup the audio session as follows:</p>
  
  <pre><code> let session = AVAudioSession.sharedInstance()
   session.setCategory(AVAudioSessionCategoryPlayback, error: &amp;error)
   session.setActive(true, error: &amp;error)
  </code></pre>
  
  <p>and further down, I've defined a function that triggers the sound that utilizes the audio engine as follows:</p>
  
  <pre><code>let playerNode = AVAudioPlayerNode()
  audioEngine.attachNode(playerNode)
  
  let changePitchNode = AVAudioUnitTimePitch()
  changePitchNode.pitch = 1000
  audioEngine.attachNode(changePitchNode)
  
  audioEngine.connect(playerNode, to: changePitchNode, format: audioFile.processingFormat)
  audioEngine.connect(changePitchNode, to: audioEngine.outputNode, format: audioFile.processingFormat)
  
  playerNode.scheduleFile(audioFile, atTime: nil, completionHandler: nil)
  audioEngine.startAndReturnError(nil)
  playerNode.play()
  </code></pre>
  
  <p><code>audioEngine</code> and <code>audioFile</code> are globally declared in the class. The whole project can be found at <a href="https://github.com/KevinSjoberg/pitch-perfect" rel="nofollow">https://github.com/KevinSjoberg/pitch-perfect</a>.</p>
  
  <p>Can anyone shed some light to why it persists on playing the sound on my monitor speaker instead of my headphones?</p>