Convert raw bytes to sound

In my application, I inherit the javastreamingaudio class from the freeTTS package, then bypass the write method, which sends an array of bytes to the SourceDataLine to process the sound. Instead of writing to a data string, I write this and subsequent byte arrays to a buffer, which I then inject into my class and try to process the sound. My application processes sound like arrays of floats, so I convert to float and try to process, but always return a static sound.

I'm sure this is the way to go, but I missed something. I know that sound is processed as frames, and each frame is a group of bytes, so in my application I have to somehow handle bytes in frames. Am I looking at this correctly? Thanx in advance for any help.

+5
source share
1 answer

First you want to convert the byte array to an InputStream. Then you create an AudioInputStream from this input stream using your AudioSystem. After you have an audio stream, you have a sound, and you can write it to a file or do anything.

ByteArrayInputStream oInstream = new ByteArrayInputStream(ayAudioData);
AudioInputStream oAIS = AudioSystem.getAudioInputStream(oInstream);
+12
source

All Articles