将多个音频文件合并为一个
我试图允许选择单词(mp3 音频样本)并添加到一个句子中,按下播放键后会按顺序播放所有单词,并可选择保存该组合文件。
I'm trying to allow selection of words (mp3 audio samples) and add to a sentence which upon pressing play plays them all in sequence and optionally save that one combined file.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
MP3 是一种流格式,这意味着它在文件的前端或末尾没有一堆元数据。虽然这有很多缺点,但优点之一是您可以将 MP3 文件连接到一个文件中并可以播放。
这几乎就是您通过连接到 NSMutableData 所做的事情,其缺点是您可能会耗尽内存。另一种选择是使用 NSFileHandle 在磁盘上构建文件。
这不适用于大多数文件格式(aac/m4a、aif、caf 等)。 MP3 实际上只是转储到磁盘的流,元数据位于帧头中(或者在 ID3 中,隐藏在帧之间),因此这就是它的工作原理。
MP3 is a stream format, meaning it doesn't have a bunch of metadata at the front or end of the file. While this has a lot of downsides, one of the upsides is that you can concatenate MP3 files together into a single file and it'll play.
This is pretty much what you're doing by concatenating into an NSMutableData, the downside of which is that you might run out of memory. Another option would be to build up the file on disk with NSFileHandle.
This doesn't work for most file formats (aac/m4a, aif, caf, etc.). MP3 is literally just a stream dumped to disk, with metadata in frame headers (or, in ID3, tucked between frames), so that's why it works.