---
title: "overrideOutputAudioPort(_:)"
framework: avfaudio
role: symbol
role_heading: Instance Method
path: "avfaudio/avaudiosession/overrideoutputaudioport(_:)"
---

# overrideOutputAudioPort(_:)

Temporarily changes the current audio route.

## Declaration

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

## Parameters

- `portOverride`: The override option for audio output. For a list of constants, see doc://com.apple.avfaudio/documentation/AVFAudio/AVAudioSession/PortOverride.

## Discussion

Discussion If your app uses the playAndRecord category, calling this method with the 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 option. If you’d prefer to permanently enable this behavior, you should instead set the category’s 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 Media Player framework’s MPVolumeView class.

## Topics

### Data Types

- [AVAudioSession.PortOverride](avfaudio/avaudiosession/portoverride.md)

## See Also

### Configuring outputs

- [outputDataSources](avfaudio/avaudiosession/outputdatasources.md)
- [outputDataSource](avfaudio/avaudiosession/outputdatasource.md)
- [setOutputDataSource(_:)](avfaudio/avaudiosession/setoutputdatasource(_:).md)
- [AVAudioSessionDataSourceDescription](avfaudio/avaudiosessiondatasourcedescription.md)
