使用 Android SDK 从原始 PCM 数据创建 WAV 文件 [英] Creating a WAV file from raw PCM data using the Android SDK

查看:42
本文介绍了使用 Android SDK 从原始 PCM 数据创建 WAV 文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 AudioRecord 类来录制 WAV 文件.问题是它只提供原始 PCM 数据,如果我将其写入文件,则没有标题信息,因此它不会在任何媒体播放器中播放.如何从这些原始数据创建 WAV 文件?

I'm trying to use the AudioRecord class to record a WAV file. The problem is that it only supplies the raw PCM data, and if I write it to a file, there is no header information, so it will not play in any media player. How can I create a WAV file from this raw data?

或者,有没有其他方法可以将 Android 中的声音录制到 WAV 文件(或者 MP3)中?

Or alternatively, is there any other way to record sound in Android to a WAV file (or, alternatively MP3)?

哦,我知道不能使用 MediaRecorder,因为它不支持 WAV 或 MP3 格式.

Oh, and I know that MediaRecorder can'y be used because it doesn't support either WAV or MP3 formats.

推荐答案

好的,我已经弄清楚了.这篇文章对帮助我至关重要:http://computermusicblog.com/blog/2008/08/29/reading-and-writing-wav-files-in-java

OK, I've got this figured out. This post was crucial in helping me: http://computermusicblog.com/blog/2008/08/29/reading-and-writing-wav-files-in-java

基本上,我使用 ByteArrayOutputStream 从 AudioRecord 写入原始 PCM 数据,然后让我在过程完成后获取字节数组及其大小.然后,我可以将该数据与 SampleRate、BitRate 和 Stereo/Mono 设置结合使用,以按照上面的链接创建 WAV 标头.生成的文件完美运行!

Basically, I used ByteArrayOutputStream to write the raw PCM data from AudioRecord, which then lets me get the byte array and its size when the process is done. I can then use that data in conjunction with the SampleRate, BitRate, and Stereo/Mono settings to create the WAV header as per the link above. The resulting file works perfectly!

这篇关于使用 Android SDK 从原始 PCM 数据创建 WAV 文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆