Mac Developer Library

Developer

AVFoundation Framework Reference AVAudioRecorder Class Reference

Options
Deployment Target:

On This Page
Language:

AVAudioRecorder

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

Inheritance


Conforms To


Import Statement


import AVFoundation @import AVFoundation;

Availability


Available in OS X v10.7 and later.
  • Initializes and returns an audio recorder.

    Declaration

    Swift

    init!(URL url: NSURL!, settings settings: [NSObject : AnyObject]!, error outError: NSErrorPointer)

    Objective-C

    - (instancetype)initWithURL:(NSURL *)url settings:(NSDictionary *)settings error:(NSError **)outError

    Parameters

    url

    The file system location to record to. The file type to record to is inferred from the file extension included in this parameter’s value.

    settings

    Settings for the recording session. For information on the settings available for an audio recorder, see AV Foundation Audio Settings Constants.

    outError

    Returns, by-reference, a description of the error, if an error occurs. Pass nil to ignore the error.

    Return Value

    On success, an initialized AVAudioRecorder object. If nil, the outError parameter contains an NSError in NSError Class Reference describing the failure.

    Import Statement

    import AVFoundation

    Availability

    Available in OS X v10.7 and later.

  • Creates an audio file and prepares the system for recording.

    Declaration

    Swift

    func prepareToRecord() -> Bool

    Objective-C

    - (BOOL)prepareToRecord

    Return Value

    YEStrue if successful, otherwise NOfalse.

    Discussion

    Creates an audio file at the location specified by the url parameter in the initWithURL:settings:error: method. If a file already exists at that location, this method overwrites it.

    The preparation invoked by this method takes place automatically when you call record. Use prepareToRecord when you want recording to start as quickly as possible upon calling record.

    Import Statement

    import AVFoundation

    Availability

    Available in OS X v10.7 and later.

  • Starts or resumes recording.

    Declaration

    Swift

    func record() -> Bool

    Objective-C

    - (BOOL)record

    Return Value

    YEStrue if successful, otherwise NOfalse.

    Discussion

    Calling this method implicitly calls prepareToRecord, which creates (or erases) an audio file and prepares the system for recording.

    Import Statement

    import AVFoundation

    Availability

    Available in OS X v10.7 and later.

  • Records for a specified duration of time.

    Declaration

    Swift

    func recordForDuration(_ duration: NSTimeInterval) -> Bool

    Objective-C

    - (BOOL)recordForDuration:(NSTimeInterval)duration

    Parameters

    duration

    The maximum duration, in seconds, for the recording.

    Return Value

    YEStrue if successful, otherwise NOfalse.

    Discussion

    The recorder stops when the duration of recorded audio reaches the value in the duration parameter.

    Calling this method implicitly calls prepareToRecord, which creates (or erases) an audio file and prepares the system for recording.

    Import Statement

    import AVFoundation

    Availability

    Available in OS X v10.7 and later.

  • Pauses a recording.

    Declaration

    Swift

    func pause()

    Objective-C

    - (void)pause

    Discussion

    Invoke the record method to resume recording.

    Import Statement

    import AVFoundation

    Availability

    Available in OS X v10.7 and later.

  • Stops recording and closes the audio file.

    Declaration

    Swift

    func stop()

    Objective-C

    - (void)stop

    Import Statement

    import AVFoundation

    Availability

    Available in OS X v10.7 and later.

  • delegate delegate Property

    The delegate object for the audio recorder.

    Declaration

    Swift

    unowned(unsafe) var delegate: AVAudioRecorderDelegate!

    Objective-C

    @property(assign) id< AVAudioRecorderDelegate > delegate

    Discussion

    For a description of the audio recorder delegate, see AVAudioRecorderDelegate Protocol Reference.

    Import Statement

    import AVFoundation

    Availability

    Available in OS X v10.7 and later.

  • Deletes a recorded audio file.

    Declaration

    Swift

    func deleteRecording() -> Bool

    Objective-C

    - (BOOL)deleteRecording

    Return Value

    Returns YEStrue on success; otherwise NOfalse.

    Discussion

    The audio recorder must be stopped before you call this method.

    Import Statement

    import AVFoundation

    Availability

    Available in OS X v10.7 and later.

  • recording recording Property

    A Boolean value that indicates whether the audio recorder is recording. (read-only)

    Declaration

    Swift

    var recording: Bool { get }

    Objective-C

    @property(readonly, getter=isRecording) BOOL recording

    Import Statement

    import AVFoundation

    Availability

    Available in OS X v10.7 and later.

  • url url Property

    The URL for the audio file associated with the audio recorder. (read-only)

    Declaration

    Swift

    var url: NSURL! { get }

    Objective-C

    @property(readonly) NSURL *url

    Import Statement

    import AVFoundation

    Availability

    Available in OS X v10.7 and later.

  • The time, in seconds, since the beginning of the recording. (read-only)

    Declaration

    Swift

    var currentTime: NSTimeInterval { get }

    Objective-C

    @property(readonly) NSTimeInterval currentTime

    Discussion

    When the audio recorder is stopped, calling this method returns a value of 0.

    Import Statement

    import AVFoundation

    Availability

    Available in OS X v10.7 and later.

  • settings settings Property

    The audio settings for the audio recorder. (read-only)

    Declaration

    Swift

    var settings: [NSObject : AnyObject]! { get }

    Objective-C

    @property(readonly) NSDictionary *settings

    Discussion

    Audio recorder settings are in effect only after you explicitly call the prepareToRecord method, or after you call it implicitly by starting recording. The audio settings keys are described in AV Foundation Audio Settings Constants.

    Import Statement

    import AVFoundation

    Availability

    Available in OS X v10.7 and later.

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

    Declaration

    Swift

    var meteringEnabled: Bool

    Objective-C

    @property(getter=isMeteringEnabled) BOOL meteringEnabled

    Discussion

    By default, audio level metering is off for an audio recorder. Because metering uses computing resources, turn it on only if you intend to use it.

    Import Statement

    import AVFoundation

    Availability

    Available in OS X v10.7 and later.

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

    Declaration

    Swift

    func updateMeters()

    Objective-C

    - (void)updateMeters

    Discussion

    To obtain current audio power values, you must call this method before you call averagePowerForChannel: or peakPowerForChannel:.

    Import Statement

    import AVFoundation

    Availability

    Available in OS X v10.7 and later.

    See Also

    meteringEnabled

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

    Declaration

    Swift

    func peakPowerForChannel(_ channelNumber: Int) -> Float

    Objective-C

    - (float)peakPowerForChannel:(NSUInteger)channelNumber

    Parameters

    channelNumber

    The number of the channel that you want the peak power value for.

    Return Value

    The current peak power, in decibels, for the sound being recorded. A return value of 0 dB indicates full scale, or maximum power; a return value of -160 dB indicates minimum power (that is, near silence).

    If the signal provided to the audio recorder exceeds ±full scale, then the return value may exceed 0 (that is, it may enter the positive range).

    Discussion

    To obtain a current peak power value, call the updateMeters method immediately before calling this method.

    Import Statement

    import AVFoundation

    Availability

    Available in OS X v10.7 and later.

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

    Declaration

    Swift

    func averagePowerForChannel(_ channelNumber: Int) -> Float

    Objective-C

    - (float)averagePowerForChannel:(NSUInteger)channelNumber

    Parameters

    channelNumber

    The number of the channel that you want the average power value for.

    Return Value

    The current average power, in decibels, for the sound being recorded. A return value of 0 dB indicates full scale, or maximum power; a return value of -160 dB indicates minimum power (that is, near silence).

    If the signal provided to the audio recorder exceeds ±full scale, then the return value may exceed 0 (that is, it may enter the positive range).

    Discussion

    To obtain a current average power value, you must call the updateMeters method before calling this method.

    Import Statement

    import AVFoundation

    Availability

    Available in OS X v10.7 and later.