Class: AVAudioRecorder

Inherits:
NSObject show all

Overview

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

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Methods inherited from NSObject

#!, #!=, #!~, #, #==, #===, #=~, #Rational, #__callee__, #__method__, #__send__, #__type__, `, alloc, allocWithZone:, #autoContentAccessingProxy, autoload, autoload?, autorelease_pool, #awakeAfterUsingCoder:, binding, block_given?, caller, cancelPreviousPerformRequestsWithTarget:, cancelPreviousPerformRequestsWithTarget:selector:object:, catch, class, classFallbacksForKeyedArchiver, #classForCoder, #classForKeyedArchiver, classForKeyedUnarchiver, #clone, conformsToProtocol:, #copy, copyWithZone:, #dealloc, #define_singleton_method, description, display, #doesNotRecognizeSelector:, #dup, #enum_for, #eql?, #equal?, #extend, fail, #finalize, format, #forwardInvocation:, #forwardingTargetForSelector:, framework, #freeze, #frozen?, getpass, gets, global_variables, #init, initialize, #initialize_clone, #initialize_copy, #initialize_dup, #inspect, instanceMethodForSelector:, instanceMethodSignatureForSelector:, #instance_eval, #instance_exec, #instance_of?, #instance_variable_defined?, #instance_variable_get, #instance_variable_set, #instance_variables, instancesRespondToSelector:, isSubclassOfClass:, #is_a?, iterator?, #kind_of?, lambda, load, load_bridge_support_file, load_plist, local_variables, loop, #method, #methodForSelector:, #methodSignatureForSelector:, #methods, #mutableCopy, mutableCopyWithZone:, new, #nil?, open, p, #performSelector:onThread:withObject:waitUntilDone:, #performSelector:onThread:withObject:waitUntilDone:modes:, #performSelector:withObject:afterDelay:, #performSelector:withObject:afterDelay:inModes:, #performSelectorInBackground:withObject:, #performSelectorOnMainThread:withObject:waitUntilDone:, #performSelectorOnMainThread:withObject:waitUntilDone:modes:, print, printf, #private_methods, proc, #protected_methods, #public_method, #public_methods, #public_send, putc, puts, raise, rand, readline, readlines, #replacementObjectForCoder:, #replacementObjectForKeyedArchiver:, require, resolveClassMethod:, resolveInstanceMethod:, #respond_to?, #respond_to_missing?, select, #send, setVersion:, #singleton_methods, sprintf, srand, superclass, #taint, #tainted?, #tap, test, throw, #to_plist, #to_s, trace_var, trap, #trust, #untaint, untrace_var, #untrust, #untrusted?, version

Constructor Details

This class inherits a constructor from NSObject

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class NSObject

Instance Attribute Details

- (Array) channelAssignments

An array of AVAudioSessionChannelDescription objects associated with the recorder. The default value of this property is nil. When non-nil, this array must have the same number of elements as designated by the AVNumberOfChannelsKey in the settings property. You can use this property to help record specific channels.

Returns:

- (NSTimeInterval) currentTime (readonly)

The time, in seconds, since the beginning of the recording. (read-only) When the audio recorder is stopped, calling this method returns a value of 0.

Returns:

  • (NSTimeInterval)

- (Object) delegate

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

Returns:

- (NSTimeInterval) deviceCurrentTime (readonly)

The time, in seconds, of the host device where the audio recorder is located. (read-only) The value of this property is never 0. The value of this property is provided as a convenience to allow for time-relative scheduling of audio recording using the recordAtTime: and recordAtTime:forDuration: methods.

Returns:

  • (NSTimeInterval)

- (Boolean) meteringEnabled

A Boolean value that indicates whether audio-level metering is enabled (YES), or not (NO). 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.

Returns:

  • (Boolean)

- (Boolean) recording (readonly)

A Boolean value that indicates whether the audio recorder is recording (YES), or not (NO). (read-only)

Returns:

  • (Boolean)

- (Hash) settings (readonly)

The audio settings for the audio recorder. (read-only) 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.

Returns:

- (NSURL) url (readonly)

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

Returns:

Instance Method Details

- (Float) averagePowerForChannel(channelNumber)

Returns the average power for a given channel, in decibels, for the sound being recorded. To obtain a current average power value, you must call the updateMeters method before calling this method.

Parameters:

  • channelNumber (Integer)

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

Returns:

  • (Float)

    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).

- (Boolean) deleteRecording

Deletes a recorded audio file. The audio recorder must be stopped before you call this method.

Returns:

  • (Boolean)

    Returns YES on success, or NO on failure.

- (Object) initWithURL(url, settings:settings, error:outError)

Initializes and returns an audio recorder.

Parameters:

  • url (NSURL)

    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 (Hash)

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

  • outError (Pointer)

    Pass in the address of a nil-initialized NSError object. If an error occurs, upon return the NSError object describes the error. If you do not want error information, pass in NULL.

Returns:

  • (Object)

    On success, an initialized AVAudioRecorder object. If nil, the outError parameter contains a code that describes the problem.

- (Object) pause

Pauses a recording. Call record to resume recording.

Returns:

- (Float) peakPowerForChannel(channelNumber)

Returns the peak power for a given channel, in decibels, for the sound being recorded. To obtain a current peak power value, call the updateMeters method immediately before calling this method.

Parameters:

  • channelNumber (Integer)

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

Returns:

  • (Float)

    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).

- (Boolean) prepareToRecord

Creates an audio file and prepares the system for recording. 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.

Returns:

  • (Boolean)

    Returns YES on success, or NO on failure.

- (Boolean) record

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

Returns:

  • (Boolean)

    Returns YES on success, or NO on failure.

- (Boolean) recordAtTime(time)

Starts recording at a specific time. Calling this method implicitly calls prepareToRecord, which creates (or erases) an audio file and prepares the system for recording. You can use this method to produce synchronized audio recordings. This method can also be used for exactly periodic recordings or recordings that happen with exact offsets relative to each other.

Parameters:

  • time (NSTimeInterval)

    The number of seconds to delay the recording. For example, to start recording three seconds into the future from when you call this method, use code like this:NSTimeInterval recordDelay = 3.0; //must be ≥ 0[myAudioRecorder recordAtTime:(myAudioRecorder.deviceCurrentTime + recordDelay)];Important: The value that you provide for the time parameter must be greater than or equal to the audio recorder’s deviceCurrentTime property.

Returns:

  • (Boolean)

    YES if the recording succeeds; otherwise NO.

- (Boolean) recordAtTime(time, forDuration:duration)

Starts recording at a specified time for a specified duration of time. Calling this method implicitly calls prepareToRecord, which creates (or erases) an audio file and prepares the system for recording. You can use this method to produce synchronized audio recordings of a specific length. The recorder will stop when the duration of recorded audio reaches the value in the duration parameter.

Parameters:

  • time (NSTimeInterval)

    The number of seconds to delay the recording, relative to the deviceCurrentTime property.Important: The value that you provide for the time parameter must be greater than or equal to the audio recorder’s deviceCurrentTime property.

  • duration (NSTimeInterval)

    The maximum duration, in seconds, for the recording.

Returns:

  • (Boolean)

    YES if the recording succeeds; otherwise NO.

- (Boolean) recordForDuration(duration)

Records for a specified duration of time. 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.

Parameters:

  • duration (NSTimeInterval)

    The maximum duration, in seconds, for the recording.

Returns:

  • (Boolean)

    Returns YES on success, or NO on failure.

- (Object) stop

Stops recording and closes the audio file.

Returns:

- (Object) updateMeters

Refreshes the average and peak power values for all channels of an audio recorder. To obtain current audio power values, you must call this method before you call averagePowerForChannel: or peakPowerForChannel:.

Returns: