在 iPhone 上将音频文件与 NSData 正确组合为一个

发布于 2024-08-08 16:28:43 字数 397 浏览 2 评论 0原文

我使用 AVAudioRecorder 每 15 秒保存一个音频文件,方法是停止录制,使用 NSMutableData 对象并使用appendData 方法将该数据附加到先前的录音机文件中。

然后我用同样的方法再次录制,这样录制是“连续的”。问题是,一旦您执行 [录音机停止],它就会保存/关闭指定 url 处的音频文件。这很好,因为我可以用它填充 NSData 对象并将其附加到我的 NSMutableObject,然后写入相同的文件 url。

问题是标题信息一定有问题,因为它只播放音频的第一部分。

我的问题是如何正确组合文件,甚至像组合两个音频文件并让 AVAudioPlayer 将其视为一个文件一样简单。我认为当我将第二个录音附加到第一个录音时,文件长度/持续时间的标头信息可能会弄乱事情。

有什么想法吗?

I am using AVAudioRecorder to save an audio file every 15 seconds by stopping the recording appending that data to the previously recorder file using a NSMutableData object and using the appendData method.

I then record again in the same method so the recording is "continuous". The problem is as soon as you do [recorder stop] it saves/closes out the audio file at the url specified. This is fine because I can fill an NSData object with it and append it to my NSMutableObject and then write to the same file url.

The problem is something must be wrong with the header info because its only playing the first part of the audio.

My question is how do I properly combine files, even as simple as combining two audio files and having the AVAudioPlayer see it as one file. I am thinking the header information for maybe the file length/duration is messing things up when I append the second recording to the first recording.

Any ideas?

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

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

发布评论

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

评论(2

陌路黄昏 2024-08-15 16:28:43

音频文件有一个标头,它指定文件中有多少样本以及数据块应该有多长。附加到现有文件的任何数据都将被忽略。这就是为什么您只能听到第一个录音。

您不能像原始数据一样附加或连接音频文件。您必须从每个文件中提取样本数据块,仅连接数据,然后编写一个新的文件头,其中正确填写数据长度和样本数量的字段,最后写入连接的声音数据块本身。

An audio file has a header which specifies how many samples are in the file and how long the data chunk should be. Any data appended to an existing file will be ignored. This is why you only hear the first recording.

You can't just append or concat audio files as if they were raw data. You have to extract the sample data chunk from each file, concat just the data, and then write a new file header with the fields for the data length and number of samples filled out correctly, and finally the concatenated sound data chunk itself.

·深蓝 2024-08-15 16:28:43

iPhone 音频 API 允许您创建非常大/长的音频文件,而无需执行任何过于复杂的操作。请参阅示例代码 SpeakHere,它创建一个随时间增长的声音文件,可能会达到非常大的大小。

The iPhone Audio API allows you to create a very large/long audio file without having to do anything too complicated. See the sample code SpeakHere, it creates a sound file that just grows with time, likely up to some very large size.

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