0

我正在开发像会说话的汤姆这样的应用程序。当我们触摸 Iphone 屏幕时会产生一些带有声音的狗动画。为此,我实现了除了 iPhone 屏幕的视频录制之外的所有内容。我基于这里实现了 iphone 屏幕的视频录制..它记录了没有声音的狗动画。我必须做什么才能在视频文件中包含音频?是否有可用的示例代码?

如果你使用 cocos2D 开发你的应用程序,这里的示例代码会很有用!

4

1 回答 1

1

Use AVAudioRecorder in the AVFoundation framework. Import the AVFoundation framework and Conform to the AVAudioRecorderDelegate Create an AVAudioRecorder instance and a NSURL instance **SAMPLE CODE

Recording:

    [audioSession setCategory:AVAudioSessionCategoryRecord error:nil]; // assign it to recording session
    [audioSession setActive:YES error:nil]; // activate it!
      NSMutableDictionary* recordSetting = [[NSMutableDictionary alloc] init];
       [recordSetting setValue: [NSNumber numberWithInt:kAudioFormatAppleIMA4]    forKey:AVFormatIDKey]; // assign this special hardware component as the function to record
    [recordSetting setValue:[NSNumber numberWithFloat:44100.0]
    forKey:AVSampleRateKey]; //44100 is the sample rate 
   [recordSetting setValue:[NSNumber numberWithInt: 2]
    forKey:AVNumberOfChannelsKey]; // same thing
   tmpFile = [NSURL fileURLWithPath:
      [NSTemporaryDirectory() stringByAppendingPathComponent:
    [NSString stringWithFormat: @"%.0f.%@",
     [NSDate timeIntervalSinceReferenceDate] * 1000.0,
      @"caf"]]]; // how we identify the audio written to the file to play later
      recorder = [[AVAudioRecorder alloc] initWithURL:tmpFile settings:recordSetting
    [recorder setDelegate:self];
   [recorder prepareToRecord];
   [recorder record];

PLAYING:

    AVAudioSession * audioSession = [AVAudioSession sharedInstance];
   [audioSession setCategory:AVAudioSessionCategoryPlayback error:nil];
       [audioSession setActive:YES error:nil];
      AVAudioPlayer * player =
       [[AVAudioPlayer alloc] initWithContentsOfURL:tmpFile error:nil]; // takes recording data from tmpFile where we wrote the recording in
      [player prepareToPlay];
     [player play];

Thats just some sample code.... to help you but otherwise read the documentation Im not sure how you could animate the mouth or if you wanted to change the pitch but this is a start to recording

于 2012-04-11T15:09:08.490 回答