导入录音头文件(注意添加framework:AVFoundation.framework
、AudioToolbox.framework
)
#import <AVFoundation/AVFoundation.h>
#import <AudioToolbox/AudioToolbox.h>
@property (nonatomic, strong) AVAudioRecorder *recorder; // 录音
@property (nonatomic, strong) NSTimer *voiceTimer; // 录音音量计时器
开始录音
- (void)recorderStart:(NSString *)filePath
{
if (!filePath || filePath.length <= 0) {
NSLog(@"文件路径无效");
return;
}
// 强转音频格式为xx.caf
BOOL isCaf = [filePath hasSuffix:@".caf"];
if (isCaf) {
self.recorderFilePath = filePath;
}