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

查看:360
本文介绍了创建使用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 can'y使用,因为它不支持任何WAV或MP3格式。

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

推荐答案

好了,我得到这个想通了。这篇文章是在帮助我重要的: <一href="http://computermusicblog.com/blog/2008/08/29/reading-and-writing-wav-files-in-java">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数据。然后我可以使用这些数据结合的采样率,比特率和立体声/单声道设置,以创建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天全站免登陆