Saving audio input of Android Stock speech recognition engine

我的梦境 提交于 2019-11-28 03:56:19
Malcolm Smith

You haven't included your code for actually writing out the PCM data, so its hard to diagnose, but if you are hearing strange noises then it looks most likely you have the wrong endian when you are writing the data, or the wrong number of channels. Getting the sample rate wrong will only result in the audio sounding slower or faster, but if it sounds completely garbled it is probably either a mistake in specifying the number of channels or endianess of your byte stream.

To know for sure, just stream your bytes directly to a file without any header (raw PCM data). This way you can rule out any errors when writing your file header. Then use Audacity to import the raw data, experimenting with the different options (bit depth, endian, channels) until you get an audio file that sounds correct (only one will be right). You do this from File->Import->Raw Data...

Once you have identified your byte format this way you only have to worry about whether you are setting the headers correctly. You might want to refer to this reference http://www-mmsp.ece.mcgill.ca/Documents/AudioFormats/WAVE/WAVE.html for the file format. Or see the following links on existing Java solutions on writing audio files, Java - reading, manipulating and writing WAV files , or FMJ. Although I guess these might not be usable on Android.

If you are having to roll your own WAV/RIFF writer remember Java's data types are big-endian so any multi-byte primitives you write to your file must be written in reverse byte order to match RIFF's little-endianess.

chandru

8000, little endian, 16 bit PCM, mono channel did the trick

Nikolay Shmyrev

In latest version onBufferReceived does not work, you can use record/save audio from voice recognition intent instead.

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