2

我想同时通过我的应用程序录制声音并播放相同的声音。

录下了声音:-

 NSString *soundFilePath = [docsDir
                               stringByAppendingPathComponent:@"sound.caf"];
    NSURL *soundFileURL = [NSURL fileURLWithPath:soundFilePath];    
    NSDictionary *recordSettings = [NSDictionary
                                    dictionaryWithObjectsAndKeys:
                                    [NSNumber numberWithInt:AVAudioQualityMin],
                                    AVEncoderAudioQualityKey,
                                    [NSNumber numberWithInt:16],
                                    AVEncoderBitRateKey,
                                    [NSNumber numberWithInt: 2],
                                    AVNumberOfChannelsKey,
                                    [NSNumber numberWithFloat:44100.0],
                                    AVSampleRateKey,
                                    nil];

    NSError *error = nil;

    audioRecorder = [[AVAudioRecorder alloc]
                     initWithURL:soundFileURL
                     settings:recordSettings
                     error:&error];

    if (error)
    {
        NSLog(@"error: %@", [error localizedDescription]);
    } else {
        [audioRecorder prepareToRecord];
        [audioRecorder record];
    }

-(void)StopRecord{
[audioRecorder stop];
 NSString *soundFilePath = [docsDir stringByAppendingPathComponent:@"sound.caf"];

    NSURL *soundFileURL = [NSURL fileURLWithPath:soundFilePath];  
    AVAudioPlayer *newPlayer =
    [[AVAudioPlayer alloc] initWithContentsOfURL:soundFileURL error: nil];    
    if([soundFileURL isFileURL]){
        printf("isFileURL\n");
    }   
    [newPlayer prepareToPlay];
    [newPlayer setDelegate: self];
       [newPlayer play];

}

现在通过这个..我录制声音,当我单击某种方法时,录制停止并开始播放..我该怎么办..它在我开始录制的同时播放声音..

4

1 回答 1

2

我通过使用 SC_listner 得到了解决方案。

[[SCListener sharedListener] listen];   

   if ([SCListener sharedListener] != nil)
    {
        Float32 percentage = [[SCListener sharedListener] peakPower];
        }

通过这样做..我可以检测到实时的音高

于 2013-03-15T12:33:38.287 回答