3

後でストリーミングできるバッファを作成する iOS で仮想楽器を録音したいと考えています。しかし、このためには、記録バッファを作成する必要があります。ボタンをクリックするとmp3ファイルを再生する仮想ピアノがあります。しかし、ユーザーが演奏する曲を内部的に記録するという考えはまったくありません。これにはマイク録音を使用しましたが、非常にノイズが多く、きれいな録音にはなりません。ガレージ バンドのようなアプリには、このような機能があります。だから私はそれが不可能だとは思わない。誰でもこのクエリを案内できますか?

Audio Engineを試してみましたが、サンプル コードが何らかの理由で機能しません。コードは実行されますが、再生ボタンを押しても何も起こりません。オーディオは再生されません。

4

1 に答える 1

0

追加

#import <AVFoundation/AVFoundation.h>
#import <MediaPlayer/MediaPlayer.h>

あなたのプロジェクトに

デリゲートAVAudioRecorderDelegate.hファイルに追加します

@property (nonatomic, strong) AVAudioRecorder *Audiorecorder;

.mファイル(ここ)self.audioFileNameNSString

これはコードのスニペットです:

NSMutableDictionary* recordSetting = [[NSMutableDictionary alloc] init];        
        [recordSetting setValue :[NSNumber numberWithInt:kAudioFormatMPEG4AAC] forKey:AVFormatIDKey];
        [recordSetting setValue:[NSNumber numberWithFloat:16000.0] forKey:AVSampleRateKey];
        [recordSetting setValue:[NSNumber numberWithInt: 1] forKey:AVNumberOfChannelsKey];

        //Now that we have our settings we are going to instanciate an instance of our recorder instance.
        NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
        [formatter setDateFormat:@"dd_MM_yyyy_HH_mm_ss"];
        self.audioFileName = [NSString stringWithFormat:@"%@.caf", [formatter stringFromDate:[NSDate date]]];
        NSString *path = [documentsDirectory stringByAppendingPathComponent:self.audioFileName ];
        NSLog(@"%@",path);
        NSURL *recordedTmpFile = [[NSURL alloc] initFileURLWithPath:path];
        NSLog(@"%@",recordedTmpFile);

        //Setup the recorder to use this file and record to it.
        if(self.Audiorecorder != nil)
        {
            [self.Audiorecorder stop];
            self.Audiorecorder = nil;
        }

        NSError * error;
        self.Audiorecorder = [[ AVAudioRecorder alloc] initWithURL:recordedTmpFile settings:recordSetting error:&error];
        //NSLog(@"Error : %@",error);
        [self.Audiorecorder setDelegate:self];
        [self.Audiorecorder prepareToRecord];       

        //Start the actual Recording
        [self.Audiorecorder peakPowerForChannel:8];
        [self.Audiorecorder updateMeters];
        self.Audiorecorder.meteringEnabled = YES;
        [self.Audiorecorder record];
于 2013-08-16T13:11:47.370 に答える