录制wav格式的音频

项目中有面部认证、声纹认证,服务器端要求上传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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值