javajrubyprocessbuilderjavax.sound.sampled

java AudioInputStream AudioSystem.write to pipe length error


Trying to pipe an AudioInputStream I got from a libary to this process:

oggenc - -o wtf.ogg

via

AudioSystem.write(audio, AudioFileFormat::Type::WAVE, process.getOutputStream());

gives me the error:

IOException
stream length not specified

file: com.sun.media.sound.WaveFileWriter.write(WaveFileWriter.java)
line: 129

So it seems audio stream length needs to be specified. This is a 44.8 kHz stereo PCM format audio with no length specified. I got this from a library so I can't modify their code. I tried creating another AudioInputStream from this stream, but I couldn't find a proper length. So how can I specify the length ?


Solution

  • So, I found that you are reading audio from somewhere unknown, and then trying to write it into WAV format. But WAV format requires to write header, which should contain file length. Anyway WaveFileWriter throws exception if feeded by stream without knowing length.

    I guess your direction is Java -> oggenc.

    So, you are to learn oggenc and know if it accepts headless WAV stream. If so, then just pass your audio to output stream, without processing with AudioSystem.write() which is for headed WAVs

    According to here http://www.linuxcommand.org/man_pages/oggenc1.html you are able to accept RAW with oggenc.