java pcm 转 wav
我有一个 pcm 文件,我想将其转换为 wav 文件。
有没有合适的api或代码?
I have a pcm file, and I want to convert it to a wav file.
Is there any suitable api or code for this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
这是我的代码
编辑:2016-01-11
it's My Code
EDIT: 2016-01-11
这应该很简单,因为 WAV = 元数据 + PCM(按此顺序)。这应该可行:
如何使用
使用起来非常简单。就像这样称呼它:
这一切是如何工作的
如您所见,WAV 标头是 WAV 和 PCM 文件格式之间的唯一区别。假设您正在录制 16 位 PCM MONO 音频(根据您的代码,您是这样)。 rawToWave 函数只是巧妙地将标头添加到 WAV 文件中,以便音乐播放器知道打开文件时会发生什么,然后在标头之后,它只从最后一位开始写入 PCM 数据。
酷提示
如果你想改变你的音调,或者制作一个变声器应用程序,你所要做的就是增加/减少
writeInt(output, 44100);的值。 // 代码中的采样率
。减小它会告诉玩家以不同的速率播放,从而改变输出音调。只是一点额外的“很高兴知道”的事情。 :)This should be quite simple to do because WAV = Metadata + PCM (in that order). This should work:
How to use
It's quite simple to use. Just call it like this:
How all this works
As you can see, the WAV header is the only difference between WAV and PCM file formats. The assumption is that you are recording 16 bit PCM MONO audio (which according to your code, you are). The rawToWave function just neatly adds headers to the WAV file, so that music players know what to expect when your file is opened, and then after the headers, it just writes the PCM data from the last bit onwards.
Cool Tip
If you want to shift the pitch of your voice, or make a voice changer app, all you got to do is increase/decrease the value of
writeInt(output, 44100); // sample rate
in your code. Decreasing it will tell the player to play it at a different rate thereby changing the output pitch. Just a little extra 'good to know' thing. :)我还不能发表评论,但请注意 devflow 答案中的 get16BitPcm 方法[奇怪]缩放输入数据。如果您已经有 16 位 pcm 数据要写入 wav 文件,则该方法应如下所示:
I cannot yet leave comments, but be aware that the
get16BitPcm
method in devflow's answer is [oddly] scaling the input data. If you already have 16 bit pcm data to write to the wav file, the method should look something like this:我知道一个叫做“OperateWav”的东西,我在第一次实习期间在我的第一个项目中用它来开发一个转换器(linux c/c++)。我不确定这个文件本身是否存在以及它是否支持java。实际上wav文件很简单在 pcm 原始数据上添加 wav 格式标头...
I know one called "OperateWav" that I used to develop a convertor(linux c/c++) in my first project during my first internship.I am not sure if this one exists per se and whether it supports java.Actually wav file is simply adding a wav format header on pcm raw data...
此资源,WAVE PCM 声音文件format,帮助我将 PCM 数据解析为 WAVE。我已经基于它构建了一个库,它对我来说工作得很好。
This resource, WAVE PCM soundfile format, helped me to parse PCM data to WAVE. I've built a library based on it and it works fine for me.