iPhone:录制到 CAF 文件仅产生静态

发布于 2024-08-27 06:32:09 字数 170 浏览 14 评论 0原文

我正在开发一个 iPhone 录音应用程序,它可以创建 caf 格式的音频文件。

当我播放这些文件时,我这里唯一的东西是静态的。此外,文件的大小也很大,例如,10 秒的录音可达 1.7 mb。

我可以用其他格式(例如 mp3)录制吗?有人有一些如何执行此操作的示例代码吗?

谢谢

I am developing an iPhone voice recording application which creates audio files in caf format.

When I play those files back, the only thing I here is static. Also, the sizes of the files are huge e.g. up to 1.7 mb for a 10 sec recording.

Could I record in another format such as mp3. Does anyone have some example code of how to do so?

thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

葮薆情 2024-09-03 06:32:09

您必须使用 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];

给你!

You have to use AVAudioRecorder class to do that.
Here is a link to developer reference:
AVAudioRecorder reference

Then, you can use the following code:

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

Here you are !!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文