android - Out of memory exception converting raw file to wav in AudioRecorder -


i using audiorecord record audio in android. after recording finished converting raw file wav file. app crashed due out of memory if size of file more 70 mb.

below code have used convert raw file wav.

private void rawtowave(final file rawfile, final file wavefile) throws ioexception {      byte[] rawdata = new byte[(int) rawfile.length()];     datainputstream input = null;     try {         input = new datainputstream(new fileinputstream(rawfile));         input.read(rawdata);     } {         if (input != null) {             input.close();         }     }      dataoutputstream output = null;     try {         output = new dataoutputstream(new fileoutputstream(wavefile));         // wave header         writestring(output, "riff"); // chunk id         writeint(output, 36 + rawdata.length); // chunk size         writestring(output, "wave"); // format         writestring(output, "fmt "); // subchunk 1 id         writeint(output, 16); // subchunk 1 size         writeshort(output, (short) 1); // audio format (1 = pcm)         writeshort(output, (short) 1); // number of channels         writeint(output, sample_rate); // sample rate         writeint(output, sample_rate * 2); // byte rate         writeshort(output, (short) 2); // block align         writeshort(output, (short) 16); // bits per sample         writestring(output, "data"); // subchunk 2 id         writeint(output, rawdata.length); // subchunk 2 size         // audio data (conversion big endian -> little endian)         short[] shorts = new short[rawdata.length / 2];         bytebuffer.wrap(rawdata).order(byteorder.little_endian).asshortbuffer().get(shorts);         bytebuffer bytes = bytebuffer.allocate(shorts.length * 2);         (short s : shorts) {             bytes.putshort(s);         }         output.write(bytes.array());     } {         if (output != null) {             output.close();         }     } }  private void writeint(final dataoutputstream output, final int value) throws ioexception {     output.write(value >> 0);     output.write(value >> 8);     output.write(value >> 16);     output.write(value >> 24); }  private void writeshort(final dataoutputstream output, final short value) throws ioexception {     output.write(value >> 0);     output.write(value >> 8); }  private void writestring(final dataoutputstream output, final string value) throws ioexception {     (int = 0; < value.length(); i++) {         output.write(value.charat(i));     } } 

can let me know there other way convert large raw file wav file. or can directly record audio wav file using audiorecord?

thanks

try setting

android:largeheap="true" 

in application manifest request larger heap..

android docs


Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - .htaccess mod_rewrite for dynamic url which has domain names -

Website Login Issue developed in magento -