我想录制声音并同时通过我的应用程序播放相同的声音。
已录制声音:-
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];
}
现在通过这个..我录制声音,当我单击某种方法时,录音停止并开始播放..我应该做什么..它在我开始录制的同时播放声音..
最佳答案
我通过使用 SC_listner 得到了解决方案。
[[SCListener sharedListener] listen];
if ([SCListener sharedListener] != nil)
{
Float32 percentage = [[SCListener sharedListener] peakPower];
}
通过这样做..我得到了实时检测音调
关于iphone - 录制声音并在 iPhone 中同时播放相同的声音,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15430878/