-1

私は、caf形式のオーディオファイルを作成するiPhone音声録音アプリケーションを開発しています。

これらのファイルを再生するとき、ここで私が使用するのは静的なものだけです。また、ファイルのサイズは非常に大きく、たとえば10秒の記録で最大1.7mbになります。

mp3などの別の形式で録音できますか?誰かがそうする方法のいくつかのサンプルコードを持っていますか?

ありがとう

4

1 に答える 1

0

これを行うには、AVAudioRecorderクラスを使用する必要があります。開発者リファレンスへのリンクは次のとおりです 。AVAudioRecorderリファレンス

次に、次のコードを使用できます。

// Init audio with record capability
AVAudioSession *audioSession = [AVAudioSession sharedInstance];
    [audioSession setCategory:AVAudioSessionCategoryPlayAndRecord error:nil];

// Set recording setting
NSMutableDictionary* recordSetting = [[NSMutableDictionary alloc] init];
    [recordSetting setValue :[NSNumber numberWithInt:kAudioFormatMPEGLayer3] forKey:AVFormatIDKey];
    [recordSetting setValue:[NSNumber numberWithFloat:48000] forKey:AVSampleRateKey]; 
    [recordSetting setValue:[NSNumber numberWithInt: 2] forKey:AVNumberOfChannelsKey];
// Create a AVAudioRecorder object
tmpUrl = [NSURL fileURLWithPath:[NSTemporaryDirectory() stringByAppendingPathComponent: [NSString stringWithFormat: @"tmp.mp3"]]];
AVAudioRecorder *recorder = [[AVAudioRecorder alloc] initWithURL:tmpUrl settings:recordSetting error:nil];

// Start the recorder
[recorder record];
// record your voice here
[recorder stop];

// Play recorded sound
AVAudioPlayer *player = [[AVAudioPlayer alloc] initWithContentsOfURL:tmpUrl error:nil];
[player play];

はい、どうぞ !!

于 2010-03-30T13:20:14.500 に答える