0
當我開始錄製音頻時,我正在嘗試播放按鈕敲擊聲。是否可以在錄製時播放聲音,直播?如何在錄製音頻時播放按鈕敲擊聲?
要求:
1)如果我有記錄按鈕點擊不想開始記錄按鈕自來水sound.it完成後記錄需要一定的時間延遲。
2)如果我點擊錄製按鈕不想錄制牛肉的聲音錄製的音頻文件。
3)我想播放按鈕輕敲聲音並同時錄製音頻而不重疊。
開始錄音:
-(IBAction)btnRecordTap:(id)sender
{
[self playTapSound:@"press.wav"];
// Set the audio file
NSArray *pathComponents = [NSArray arrayWithObjects:
[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject],
@"MyAudioMemo.m4a",
nil];
NSURL *outputFileURL = [NSURL fileURLWithPathComponents:pathComponents];
// Setup audio session
AVAudioSession *session = [AVAudioSession sharedInstance];
[session setCategory:AVAudioSessionCategoryPlayAndRecord error:nil];
// Define the recorder setting
NSMutableDictionary *recordSetting = [[NSMutableDictionary alloc] init];
[recordSetting setValue:[NSNumber numberWithInt:kAudioFormatMPEG4AAC] forKey:AVFormatIDKey];
[recordSetting setValue:[NSNumber numberWithFloat:44100.0] forKey:AVSampleRateKey];
[recordSetting setValue:[NSNumber numberWithInt: 2] forKey:AVNumberOfChannelsKey];
// Initiate and prepare the recorder
recorder = [[AVAudioRecorder alloc] initWithURL:outputFileURL settings:recordSetting error:NULL];
recorder.delegate = self;
recorder.meteringEnabled = YES;
[recorder prepareToRecord];
}
播放系統聲音
//---------------play button sound--------------------
-(SystemSoundID) playASound: (NSString *) fileName
{
//Get the filename of the sound file:
NSString *path = [NSString stringWithFormat:@"%@/%@",
[[NSBundle mainBundle] resourcePath],
fileName];
//Get a URL for the sound file
NSURL *filePath = [NSURL fileURLWithPath:path isDirectory:NO];
AudioServicesCreateSystemSoundID((__bridge CFURLRef)filePath, &soundFileObject);
//play the file
AudioServicesPlaySystemSound(soundFileObject);
return soundFileObject;
}
-(void)playTapSound:(NSString *)file
{
SystemSoundID id = [self playASound:file];
AudioServicesAddSystemSoundCompletion (id,NULL,NULL,completionCallback,(__bridge_retained void *)self);
}
static void completionCallback (SystemSoundID ssID,void *clientData)
{
AudioServicesRemoveSystemSoundCompletion (ssID);
AudioServicesDisposeSystemSoundID(ssID);
}