• 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;

        }

    }

  • 相关阅读:
    POJ 3280 Cheapest Palindrome (区间DP)
    UVaLive 4731 Cellular Network (期望DP)
    UVa 11404 Palindromic Subsequence (LCS)
    UVa 11552 Fewest Flops (DP)
    UVa 10534 Wavio Sequence (LIS+暴力)
    UVaLive 4256 Salesmen (简单DP)
    UVaLive 4094 WonderTeam (贪心)
    UVaLive 3266 Tian Ji -- The Horse Racing (贪心)
    POJ 3723 Conscription (最小生成树)
    NodeJS学习笔记 进阶 (4)基于express+muter的文件上传(ok)
  • 原文地址:https://www.cnblogs.com/HuiLove/p/3909862.html
Copyright © 2020-2023  润新知