Creating a WAV file from raw PCM data using the Android SDK

南楼画角 提交于 2019-11-27 12:26:15

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

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!

Check the MediaRecorder.setOutputFormat(), you can set different container formats for your recording; there is MediaRecorder.OutputFormat.MPEG_4 and MediaRecorder.OutputFormat.THREE_GPP; the only allowed format along RAW is setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);

Sorry but MP3 is not avail. You really need mp3 for recording? WAV on the opposite of MP3 is a container, not a format; WAV can be any kind of encoding format.

You are always free to prepend some WAV RIFF header in front of your raw pcm data (as long as you exactly know the format). Check here for how it has to look like: http://www-mmsp.ece.mcgill.ca/Documents/AudioFormats/WAVE/WAVE.html

You may want to use mediarecord class

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!