gpt4 book ai didi

ios - 视频录制就像会说话的汤姆应用程序

转载 作者:行者123 更新时间:2023-11-29 04:42:49 24 4
gpt4 key购买 nike

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

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

最佳答案

在 AVFoundation 框架中使用 AVAudioRecorder。导入 AVFoundation 框架并符合 AVAudioRecorderDelegate创建 AVAudioRecorder 实例和 NSURL 实例**示例代码

录音:

    [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];

播放:

    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];

这只是一些示例代码......可以帮助您,但否则请阅读文档我不确定如何为嘴巴设置动画,或者是否想改变音调,但这只是录制的开始

关于ios - 视频录制就像会说话的汤姆应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10108365/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com