java - Saving audio byte[] to a wav file -


been having bit of trouble on last few days trying work. want have application sends raw data on network. read binary data in , want save wav(any audio) file. might @ compression later.

so problematic code:

byte[] allbytes = ... inputstream b_in = new bytearrayinputstream(allbytes);  try {      audioformat format = new audioformat(8000f, 16, 1, true, true);      audioinputstream stream = new audioinputstream(b_in, format, allbytes.length);      //audioinputstream stream = audiosystem.getaudioinputstream(b_in);                 

have tried use above statement exception: javax.sound.sampled.unsupportedaudiofileexception: not audio input stream stream. think happening because stream raw audio data , not have wave header throwing exception?

file newpath = new file(systemconfiguration.getlatest().voicenetworkpathdirectory + currentphonecall.filename); if (!audiosystem.isfiletypesupported(type.wave, stream)) {     logger.error("audio system file type not supported"); }  audiosystem.write(stream, type.wave, newpath); 

the file write static, need create wave header on output using this. when @ outputted wav file in notepad , seem have header starts 'riff'.

do need add fake header input stream? should create own output header , save binary writer?

it's hard know description error is, answer questions, when see 'riff' when open file mean has header. trying build own header possible bit time consuming (and unnecessary since you've got one).

now, when reading, safest format file itself, rather trying specify manually -- less error prone. there sample code here:

http://www.jsresources.org/examples/simpleaudioplayer.java.html

when writing, "the file write static" -- have confirmed other own java code? maybe not understanding correctly, sounds trying record , playback wav files fresh java code, , if that's case, it's hard tell if going wrong recording or playback.

you should start vanilla format (16 bits, stereo, uncompressed, 44,100 khz) can open file in media player or quicktime or , verify recording worked. once works, can try change sr , on. here sample code recording. start that, verify works, , move on more complex:

http://www.jsresources.org/examples/simpleaudiorecorder.java.html


Comments

Popular posts from this blog

django - How can I change user group without delete record -

java - Need to add SOAP security token -

java - EclipseLink JPA Object is not a known entity type -