Class

AVAudioRecorder

An instance of the AVAudioRecorder class, called an audio recorder, provides audio recording capability in your application. Using an audio recorder you can:

Overview

  • Record until the user stops the recording

  • Record for a specified duration

  • Pause and resume a recording

  • Obtain input audio-level data that you can use to provide level metering

In iOS, the audio being recorded comes from the device connected by the user—built-in microphone or headset microphone, for example. In macOS, the audio comes from the system’s default audio input device as set by a user in System Preferences.

You can implement a delegate object for an audio recorder to respond to audio interruptions and audio decoding errors, and to the completion of a recording.

To configure a recording, including options such as bit depth, bit rate, and sample rate conversion quality, configure the audio recorder’s settings dictionary. Use the settings keys described in AV Foundation Audio Settings Constants.

To configure an appropriate audio session for recording, refer to AVAudioSession and AVAudioSessionDelegate.

The AVAudioRecorder class is intended to allow you to make audio recordings with very little programming overhead. Other classes that can be used for recording audio in iOS and macOS include AVCaptureAudioDataOutput and the Audio Queue services described in the Audio Queue Services Programming Guide.

In macOS, you can also use the AVCaptureAudioFileOutput class to record audio.

Symbols

Initializing an AVAudioRecorder Object

init(url: URL, settings: [String : Any])

Initializes and returns an audio recorder.

Configuring and Controlling Recording

func prepareToRecord()

Creates an audio file and prepares the system for recording.

func record()

Starts or resumes recording.

func record(atTime: TimeInterval)

Starts recording at a specific time.

func record(forDuration: TimeInterval)

Records for a specified duration of time.

func record(atTime: TimeInterval, forDuration: TimeInterval)

Starts recording at a specified time for a specified duration of time.

func pause()

Pauses a recording.

func stop()

Stops recording and closes the audio file.

var delegate: AVAudioRecorderDelegate?

The delegate object for the audio recorder.

func deleteRecording()

Deletes a recorded audio file.

Managing Information About a Recording

var isRecording: Bool

A Boolean value that indicates whether the audio recorder is recording.

var url: URL

The URL for the audio file associated with the audio recorder.

var channelAssignments: [NSNumber]?

An array of AVAudioSessionChannelDescription objects associated with the recorder.

var currentTime: TimeInterval

The time, in seconds, since the beginning of the recording.

var deviceCurrentTime: TimeInterval

The time, in seconds, of the host device where the audio recorder is located.

var settings: [String : Any]

The audio settings for the audio recorder.

Using Audio Level Metering

var isMeteringEnabled: Bool

A Boolean value that indicates whether audio-level metering is enabled.

func updateMeters()

Refreshes the average and peak power values for all channels of an audio recorder.

func peakPower(forChannel: Int)

Returns the peak power for a given channel, in decibels, for the sound being recorded.

func averagePower(forChannel: Int)

Returns the average power for a given channel, in decibels, for the sound being recorded.

Instance Properties

Relationships

Inherits From

Conforms To