<!--
{
  "availability" : [
    "iOS: 6.0.0 -",
    "iPadOS: 6.0.0 -",
    "macCatalyst: 13.1.0 -",
    "tvOS: 9.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 2.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "AVFAudio",
  "identifier" : "/documentation/AVFAudio/AVAudioSession/overrideOutputAudioPort(_:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "AVFAudio"
    ],
    "preciseIdentifier" : "c:objc(cs)AVAudioSession(im)overrideOutputAudioPort:error:"
  },
  "title" : "overrideOutputAudioPort(_:)"
}
-->

# overrideOutputAudioPort(_:)

Temporarily changes the current audio route.

```
func overrideOutputAudioPort(_ portOverride: AVAudioSession.PortOverride) throws
```

## Parameters

`portOverride`

The override option for audio output. For a list of constants, see [`AVAudioSession.PortOverride`](/documentation/AVFAudio/AVAudioSession/PortOverride).

## Discussion

If your app uses the [`playAndRecord`](/documentation/AVFAudio/AVAudioSession/Category-swift.struct/playAndRecord) category, calling this method with the [`AVAudioSession.PortOverride.speaker`](/documentation/AVFAudio/AVAudioSession/PortOverride/speaker) option causes the system to route audio to the built-in speaker and microphone regardless of other settings. This change remains in effect only until the current route changes or you call this method again with the [`AVAudioSession.PortOverride.none`](/documentation/AVFAudio/AVAudioSession/PortOverride/none) option.

If you’d prefer to permanently enable this behavior, you should instead set the category’s [`defaultToSpeaker`](/documentation/AVFAudio/AVAudioSession/CategoryOptions-swift.struct/defaultToSpeaker) option. Setting this option routes to the speaker rather than the receiver if no other accessory such as headphones are in use.

> Note:
> The preferred method for routing audio to the speaker instead of the receiver for speakerphone functionality is through the use of the <doc://com.apple.documentation/documentation/MediaPlayer> framework’s <doc://com.apple.documentation/documentation/MediaPlayer/MPVolumeView> class.

## Topics

### Data Types

[`AVAudioSession.PortOverride`](/documentation/AVFAudio/AVAudioSession/PortOverride)

Constants for use with the [`overrideOutputAudioPort(_:)`](/documentation/AVFAudio/AVAudioSession/overrideOutputAudioPort(_:)) method.



---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)