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 ?
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 WAV
s
According to here http://www.linuxcommand.org/man_pages/oggenc1.html you are able to accept RAW
with oggenc
.
You will be able to solve the issue with length if you reimplement AudioSystem.write method. It doesn't work with stream and WAVE format because of data length in the header. You should write audio data to some array and then prepare correct WAVE Header. Example: How to record audio to byte array
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.