AVAudioRecorder
A class that provides audio recording capability in your application.
在你应用中,提供音频录音功能的类
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.
概述:
- 录音,直到使用者停止录音
- 为录音设置指定市场
- 暂停和重新开始录音
获取输入的音频数据
在ios中,录制音频来自使用者的内置麦克风或者头戴式麦克风,在macOS中,音频来自系统默认的音频设备,由用户在系统中选择。
你可以为录音设置一个代理,以响应音频的终端和音频编码错误,并完成录音。
To configure a recording, including options such as bit depth, bit rate, and sample rate conversion quality, configure the audio recorder’s settingsdictionary. Use the settings keys described in Settings.
要配置录制,包括诸如比特深度、比特率和采样率转换质量等选项,请配置录音机的settingsdictionary。使用设置中描述的设置键。
初始化方法
- initWithURL:settings:error:
- initWithURL:format:error:
方法
- prepareToRecord //开始录制
- record //开始或者继续录制
- recordAtTime: //在特定时间录制
- recordForDuration: //记录特定时间的录制
- recordAtTime:forDuration: //
- recordAtTime:forDuration: //在指定时间开始记录
- pause //暂停录音
- stop //停止录音,并关闭音频文件
delegate //录音的代理
AVAudioRecorderDelegate //录音对象的代理
- deleteRecording //删除录音文件
关于录音的属性
recording //是否在录音
url //与录音关联的录音文件的地址
channelAssignments //与录音相关联 AVAudioSessionChannelDescription
对象的数组。通道描述提供关于当前设备上的硬件通道的描述信息。
currentTime //时间,以秒为单位,从录音开始算起,录音时长
deviceCurrentTime //输入设备设置的录音时长
settings //录音文件的设置
format //缓冲区音频格式
meteringEnabled //是否启用录音测量,如果启用录音测量可以获得录音分贝等数据信息。
- updateMeters //更新测量数据,注意只有meteringEnabled为YES此方法才可用
- peakPowerForChannel:// 指定通道的测量峰值,注意只有调用完updateMeters才有值
- averagePowerForChannel: //指定通道的测量平均值,注意只有调用完updateMeters才有值
设置一般音频格式设置
适用于AVAudioPlayer和AVAudioRecorder类处理的所有音频格式的音频设置。
编码器设置
AVAudioRecorder类的音频编码器设置。
AVEncoderBitRateStrategyKey值
这些常量是AVEncoderBitRateStrategyKey编码器设置支持的值。
AVSampleRateConverterAlgorithmKey值
这些常量是AVEncoderBitRateStrategyKey编码器设置支持的值。