Class

AVAudioRecorder

A class that provides audio recording capability in your application.

Declaration

@interface AVAudioRecorder : NSObject

Overview

Using an audio recorder, you can:

  • 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 Settings.

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.

Topics

Initializing an AVAudioRecorder Object

- initWithURL:settings:error:

Initializes and returns an audio recorder.

- initWithURL:format:error:

Initializes and returns an audio recorder.

Configuring and Controlling Recording

- prepareToRecord

Creates an audio file and prepares the system for recording.

- record

Starts or resumes recording.

- recordAtTime:

Starts recording at a specific time.

- recordForDuration:

Records for a specified duration of time.

- recordAtTime:forDuration:

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

- pause

Pauses a recording.

- stop

Stops recording and closes the audio file.

delegate

The delegate object for the audio recorder.

AVAudioRecorderDelegate

The delegate of an audio recorder object.

- deleteRecording

Deletes a recorded audio file.

Managing Information About a Recording

recording

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

url

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

channelAssignments

An array of AVAudioSessionChannelDescription objects associated with the recorder.

currentTime

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

deviceCurrentTime

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

settings

The audio settings for the audio recorder.

format

The format of the audio in the buffer.

Using Audio Level Metering

meteringEnabled

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

- updateMeters

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

- peakPowerForChannel:

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

- averagePowerForChannel:

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

Settings

General Audio Format Settings

Audio settings that apply to all audio formats handled by the AVAudioPlayer and AVAudioRecorder classes.

Encoder Settings

Audio encoder settings for the AVAudioRecorder class.

AVEncoderBitRateStrategyKey Values

These constants are the supported values for the AVEncoderBitRateStrategyKey encoder setting.

AVSampleRateConverterAlgorithmKey Values

These constants are the supported values for the AVEncoderBitRateStrategyKey encoder setting.

Relationships

Inherits From

See Also

Single Track Playback and Recording

AVAudioPlayer

An audio player that provides playback of audio data from a file or memory.

AVMIDIPlayer

A player for music file formats such as MIDI and iMelody.