项目中有面部认证、声纹认证,服务器端要求上传wav格式的音频,所以写了这样一个小demo。
刚刚开始写博客还不知道怎么上传代码,就复制了,嘻嘻
DotimeManage.h
@class DotimeManage;
@protocol DotimeManageDelegate <NSObject>
- (void)TimerActionValueChange:(int)time; //时间改变
@end
#import <Foundation/Foundation.h>
@interface DotimeManage : NSObject
{
NSTimer *BBtimer;
}
@property (nonatomic)int timeValue;
@property (nonatomic,assign)id<DotimeManageDelegate> delegate;
+ (DotimeManage *)DefaultManage;
//开始计时
- (void)startTime;
//停止计时
- (void)stopTimer;
@end
DotimeManage.m
#import "DotimeManage.h"
@implementation DotimeManage
static DotimeManage *timeManage = nil;
+ (DotimeManage *)DefaultManage{
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
timeManage = [[DotimeManage alloc] init];
});
return timeManage;
}
- (id)init {
self = [super init];
if (self) {
}
return self;
}
//开始计时
- (void)startTime {
//停止上次计时器
[self stopTimer];
if (BBtimer == nil) {
self.timeValue = 0;
BBtimer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(TimerAction) userInfo:nil repeats:YES];
NSRunLoop *main=[NSRunLoop currentRunLoop];
[main addTimer:BBtimer forMode:NSRunLoopCommonModes];
}
}
//停止计时
- (void)stopTimer {
if (BBtimer != nil) {
[BBtimer invalidate];
BBtimer = nil;
}
}
//倒计时
- (void)TimerAction {
self.timeValue ++;
if ([self.delegate respondsToSelector:@selector(TimerActionValueChange:)]) {
[self.delegate TimerActionValueChange:self.timeValue];
}
}
@end
Recorder.h
#import <Foundation/Foundation.h>
#import <AVFoundation/AVFoundation.h>
#import <AudioToolbox/AudioToolbox.h>
#import <UIKit/UIKit.h>
#define DefaultSubPath @"Voice" //默认 二级目录 可以修改自己想要的 例如 "文件夹1/文件夹2/文件夹3"
#define SampleRateKey 44100.0 //采样率8000.0
#define LinearPCMBitDepth 16 //采样位数 默认 16
#define NumberOfChannels 1 //通道的数目
@protocol RecorderDelegate <NSObject>
/**
* 录音进行中
* currentTime 录音时长
**/
-(void)recorderCurrentTime:(NSTimeInterval)currentTime;
/**
* 录音完成
* filePath