将音频文件录制为 mp3 或 wav

发布于 2025-01-06 09:24:50 字数 1398 浏览 7 评论 0原文

我正在尝试录制并保存 mp3 文件,因此我使用以下代码

NSString* d = @" ar/mobile/Applications/86F15C5E-66EC-4071-95EB-96CDE64B5948/Library/Application Support/P/5720/5720/Report/Report0.mp3"

NSURL *soundFileURL = [NSURL fileURLWithPath:d];

 NSDictionary *recordSettings = [NSDictionary 
                                 dictionaryWithObjectsAndKeys:
                                 [NSNumber numberWithInt:AVAudioQualityMin],
                                 AVEncoderAudioQualityKey,
                                 [NSNumber numberWithInt:16], 
                                 AVEncoderBitRateKey,
                                 [NSNumber numberWithInt: 2], 
                                 AVNumberOfChannelsKey,
                                 [NSNumber numberWithFloat:44100.0], 
                                 AVSampleRateKey,
                                 nil];

 NSError *error = nil;

 audioRecorder = [[AVAudioRecorder alloc]
                  initWithURL:soundFileURL
                  settings:recordSettings
                  error:&error];

 if (error)
 {
     NSLog(@"error: %@", [error localizedDescription]);

 } else {
     [audioRecorder prepareToRecord];
 }

并开始录制我

[audioRecorder record];

用于 mp3 的文件,但出现错误 错误:操作无法完成。 (OSStatus错误1718449215。)

如果我将其保存为wav,则不会记录任何内容,并且文件为0字节,

我是否丢失了某些内容,知道如何解决这个问题

I am trying to record and saave mp3 file so I use the following code

NSString* d = @" ar/mobile/Applications/86F15C5E-66EC-4071-95EB-96CDE64B5948/Library/Application Support/P/5720/5720/Report/Report0.mp3"

NSURL *soundFileURL = [NSURL fileURLWithPath:d];

 NSDictionary *recordSettings = [NSDictionary 
                                 dictionaryWithObjectsAndKeys:
                                 [NSNumber numberWithInt:AVAudioQualityMin],
                                 AVEncoderAudioQualityKey,
                                 [NSNumber numberWithInt:16], 
                                 AVEncoderBitRateKey,
                                 [NSNumber numberWithInt: 2], 
                                 AVNumberOfChannelsKey,
                                 [NSNumber numberWithFloat:44100.0], 
                                 AVSampleRateKey,
                                 nil];

 NSError *error = nil;

 audioRecorder = [[AVAudioRecorder alloc]
                  initWithURL:soundFileURL
                  settings:recordSettings
                  error:&error];

 if (error)
 {
     NSLog(@"error: %@", [error localizedDescription]);

 } else {
     [audioRecorder prepareToRecord];
 }

and to start record I use

[audioRecorder record];

for mp3 I got error
error: The operation couldn’t be completed. (OSStatus error 1718449215.)

and if I saved it as wav nothing be recorded , and the file be 0 byte

am I missing something , any idea how to solve that

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

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

发布评论

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

评论(2

〃安静 2025-01-13 09:24:50

你没有展示 Dpath 的定义方式......

NSString * filePath = [NSHomeDirectory()stringByAppendingPathComponent: [NSString stringWithFormat:@"Documents/%@.mp3",songTitle]];

// more code    

recorder = [[AVAudioRecorder alloc] initWithURL: [NSURL fileURLWithPath:filePath settings: recordSettings error: nil];

you're not showing the way Dpath is defined...

NSString * filePath = [NSHomeDirectory()stringByAppendingPathComponent: [NSString stringWithFormat:@"Documents/%@.mp3",songTitle]];

// more code    

recorder = [[AVAudioRecorder alloc] initWithURL: [NSURL fileURLWithPath:filePath settings: recordSettings error: nil];
笑,眼淚并存 2025-01-13 09:24:50

也许将其保存到文档文件夹中?这不是正确的合法途径吗?

perhaps save it to the documents folder? Isn't that the correct legal path?

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