WAV 压缩帮助
如何以编程方式将 WAV 文件压缩为另一种格式(PCM、11,025 KHz 采样率等)?
How do you programmatically compress a WAV file to another format (PCM, 11,025 KHz sampling rate, etc.)?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
我会研究 audacity...我很确定他们没有可以做到这一点的命令行实用程序,但他们可能有一个库...
更新:
看起来他们使用 libsndfile,根据 LGPL 发布。 我就是其中之一,可能会尝试使用它。
I'd look into audacity... I'm pretty sure they don't have a command line utility that can do it, but they may have a library...
Update:
It looks like they use libsndfile, which is released under the LGPL. I for one, would probably just try using that.
在 Linux 中使用 sox (Sound eXchange:通用声音样本转换器):
SoX 是一个命令行程序,可以将最流行的音频文件转换为大多数其他流行的音频文件格式。 它可以选择性地
在此转换过程中更改音频样本数据类型并向文件应用一种或多种音效。
Use sox (Sound eXchange : universal sound sample translator) in Linux:
SoX is a command line program that can convert most popular audio files to most other popular audio file formats. It can optionally
change the audio sample data type and apply one or more sound effects to the file during this translation.
如果您的意思是如何将 PCM 数据压缩为不同的音频格式,那么您可以使用多种库来执行此操作,具体取决于您想要支持的平台。 如果您只想更改 PCM 数据的采样率,那么您需要采样率转换算法,这是一个完全不同的问题。 您的要求可以更具体一些吗?
If you mean how do you compress the PCM data to a different audio format then there are a variety of libraries you can use to do this, depending on the platform(s) that you want to support. If you just want to change the sample rate of the PCM data then you need a sample rate conversion algorithm instead, which is a completely different problem. Can you be more specific in your requirements?
您询问的是重新采样,更具体地说是下采样,而不是压缩。 虽然这两个过程都是有损的(意味着您将丢失信息),但下采样适用于原始样本而不是频域。
如果您对压缩感兴趣,那么您应该研究 lame 或 OGG vorbis 库; 您无疑熟悉 MP3 和 OGG 技术,尽管从您的问题中我感觉到您有兴趣以较低的采样率取回 PCM 文件。
在这种情况下,您需要一个重采样库,其中有一些可能性。 最广为人知的是 libsamplerate,老实说我不会推荐它,不仅因为质量问题不仅影响生成的音频文件,还影响库本身使用的代码的稳定性。 另一种非商业可能性是 sox,正如其他一些人提到的那样。 根据程序的性质,您可以将 sox 作为单独的进程执行,也可以将其用作库,从您自己的代码中调用它。 我个人还没有尝试过这种方法,但我现在正在开发一个产品,我们使用 sox(实际上是用于上采样),并且我们对结果非常满意。
另一种选择是编写您自己的采样率转换库,这可能是一项艰巨的任务,但是,如果您只想使用整数因子进行转换(即从 44.1kHz 到 22kHz,或者从 44.1kHz 到 11kHz),那么这实际上非常简单,因为你只需要去掉每个 N 个样本。
You're asking about resampling, and more specifically downsampling, not compression. While both processes are lossy (meaning that you will suffer loss of information), downsampling works on raw samples instead of in the frequency domain.
If you are interested in doing compression, then you should look into lame or OGG vorbis libraries; you are no doubt familiar with MP3 and OGG technology, though I have a feeling from your question that you are interested in getting back a PCM file with a lower sampling rate.
In that case, you need a resampling library, of which there are a few possibilites. The most widely known is libsamplerate, which I honestly would not recommend due to quality issues not only within the generated audio files, but also of the stability of the code used in the library itself. The other non-commercial possibility is sox, as a few others have mentioned. Depending on the nature of your program, you can either exec sox as a separate process, or you can call it from your own code by using it as a library. I personally have not tried this approach, but I'm working on a product now where we use sox (for upsampling, actually), and we're quite happy with the results.
The other option is to write your own sample rate conversion library, which can be a significant undertaking, but, if you only are interested in converting with an integer factor (ie, from 44.1kHz to 22kHz, or from 44.1kHz to 11kHz), then it is actually very easy, since you only need to strip out every Nth sample.
在 Windows 中,您可以使用音频压缩管理器在文件之间进行转换(acm... 函数)。 您还需要了解 WAVEFORMAT 结构和 WAV 文件格式。 不幸的是,自己编写所有这些内容需要一些时间,这就是为什么研究其他人建议的一些开源选项可能是个好主意。
我编写了一个自己的开源 .NET 音频库,名为 NAudio ,它可以从一种格式转换 WAV 文件另一个方法是使用计算机上安装的 ACM 编解码器。 我知道您已经用 C++ 标记了这个问题,但如果 .NET 可以接受,那么这可能会节省您一些时间。 查看 NAudioDemo 项目以获取转换文件的示例。
In Windows, you can make use of the Audio Compression Manager to convert between files (the acm... functions). You will also need a working knowledge of the WAVEFORMAT structure, and WAV file formats. Unfortunately, to write all this yourself will take some time, which is why it may be a good idea to investigate some of the open source options suggested by others.
I have written a my own open source .NET audio library called NAudio that can convert WAV files from one format to another, making use of the ACM codecs that are installed on your machine. I know you have tagged this question with C++, but if .NET is acceptable then this may save you some time. Have a look at the NAudioDemo project for an example of converting files.