zoukankan      html  css  js  c++  java
  • xcode中用AVAudioRecorder录音到指定的caf文件

    -(void) StartRecord:(NSURL *) recordedFile

    {

    session = [AVAudioSession sharedInstance];

    session.delegate = self;

    NSError *sessionError;

    [session setCategory:AVAudioSessionCategoryPlayAndRecord error:&sessionError];

    if(session == nil)

    NSLog(@"Error creating session: %@", [sessionError description]);

    else

    [session setActive:YES error:nil];

    /*

     NSDictionary *settings = [NSDictionary dictionaryWithObjectsAndKeys:

     [NSNumber numberWithFloat:44100.0], AVSampleRateKey,

     [NSNumber numberWithInt:kAudioFormatMPEG4AAC], AVFormatIDKey,

     [NSNumber numberWithInt:2], AVNumberOfChannelsKey,

     nil];

     */

    //录音设置

    NSMutableDictionary *settings = [[NSMutableDictionary alloc] init];

    //录音格式 无法使用

    [settings setValue :[NSNumber numberWithInt:kAudioFormatLinearPCM] forKey: AVFormatIDKey];

    //采样率

    [settings setValue :[NSNumber numberWithFloat:11025.0] forKey: AVSampleRateKey];//44100.0

    //通道数

    [settings setValue :[NSNumber numberWithInt:2] forKey: AVNumberOfChannelsKey];

    //线性采样位数

    //[recordSettings setValue :[NSNumber numberWithInt:16] forKey: AVLinearPCMBitDepthKey];

    //音频质量,采样质量

    [settings setValue:[NSNumber numberWithInt:AVAudioQualityMin] forKey:AVEncoderAudioQualityKey];

    recorder = [[AVAudioRecorder alloc] initWithURL:recordedFile settings:settings error:nil];

    [recorder prepareToRecord];

    [recorder record];

    }

    -(void) StopRecord

    {

        [recorder stop];

        

        if(recorder)

        {

            recorder = nil;

        }

    }

  • 相关阅读:
    Mysql添加用户和数据库
    Ubuntu Apache vhost不执行php小记
    buff/cache内存占用过多
    yii2 返回json和文件下载
    yii2 activeform 替換 form-gruop
    VSCode+Ionic+Apache Ripple开发环境搭建
    安装ionic出现node-sass无法下载的解决方法
    VS2015 + Cordova Html5开发使用Crosswalk Web引擎
    visual studio 2015 + Cordova 开发环境搭建
    ADSL自动更换IP地址源代码
  • 原文地址:https://www.cnblogs.com/HuiLove/p/3909862.html
Copyright © 2011-2022 走看看