0

オーディオの録音を開始するときにボタン タップ音を再生しようとしています。ライブで録音中にサウンドを再生することはできますか?

要件:

1)録音ボタンをタップすると、録音ボタンのタップ音の完了後に録音を開始したくありません。時間の遅延がかかります。

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);
}
4

1 に答える 1