【问题标题】:Record sound when speaking to mic对着麦克风讲话时录制声音
【发布时间】:2012-08-06 08:35:52
【问题描述】:

我想编写处理录音的控制器。当麦克风中有声音时,它应该录制声音。

按下按钮时,我有录制声音的工作代码。

-(IBAction) startRecording
{
    NSLog(@"startRecording");
    audioRecorder = nil;

    // Init audio with record capability
    AVAudioSession *audioSession = [AVAudioSession sharedInstance];
    [audioSession setCategory:AVAudioSessionCategoryRecord error:nil];

    NSMutableDictionary *recordSettings = [[NSMutableDictionary alloc] initWithCapacity:10];
   // if(recordEncoding == ENC_PCM)
    //{

        [recordSettings setObject:[NSNumber numberWithInt: kAudioFormatLinearPCM] forKey: AVFormatIDKey];
        [recordSettings setObject:[NSNumber numberWithFloat:500.0] forKey: AVSampleRateKey];//44100.0
        [recordSettings setObject:[NSNumber numberWithInt:2] forKey:AVNumberOfChannelsKey];
        [recordSettings setObject:[NSNumber numberWithInt:16] forKey:AVLinearPCMBitDepthKey];
        [recordSettings setObject:[NSNumber numberWithBool:NO] forKey:AVLinearPCMIsBigEndianKey];
        [recordSettings setObject:[NSNumber numberWithBool:NO] forKey:AVLinearPCMIsFloatKey];

   // NSURL *url = [NSURL fileURLWithPath:[NSString stringWithFormat:@"%@/recordTest.caf", [[NSBundle mainBundle] resourcePath]]];

    NSURL *url = [NSURL URLWithString:[self copyFile:@"recordTest.caf"]];



    NSError *error = nil;
    audioRecorder = [[ AVAudioRecorder alloc] initWithURL:url settings:recordSettings error:&error];
    [audioRecorder setDelegate:self];

    if ([audioRecorder prepareToRecord] == YES){
        [audioRecorder record];
        NSLog(@"recording");
    }else {
        int errorCode = CFSwapInt32HostToBig ([error code]);
        NSLog(@"Error: %@ [%4.4s])" , [error localizedDescription], (char*)&errorCode);

    }

}

那么是否可以录制或监控来自麦克风输入的声音并在声音高于例如 1000 Hz 时开始录制?

我也很欣赏这方面的文献。

谢谢。

【问题讨论】:

    标签: objective-c ios ios5


    【解决方案1】:

    希望对你有帮助Download the link l

    【讨论】:

    • 我以这个为例,但很难阅读。我想要更简单的例子
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-10-16
    • 2023-03-21
    • 2014-03-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多