nurettin nurettin - 1 month ago 9x
Java Question

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


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

gives me the error:

stream length not specified

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 ?


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 you are able to accept RAW with oggenc.