I have come across the
Tritonus Java Sound libraries, specifically interested in the
GSM format for a speech recording application, though these haven't been updated for years. I've seen [Ramiro's thread|http://forums.sun.com/thread.jspa?messageID=10678607] in this forum, but havne't been able to fill in the gaps. Hoping someone here can help either with Tritonus' GSM implementation, or can point me at another, more recently supported.
I have been able to store and retrieve using the JRE's PCM encoding just fine.
So, from Ramiro's thread, I've implemented:
// From the PCM 16 bits mono AudioInputStream , obtains (FINALLY!!) a GSM AudioInputStream, to store it in the final OutputStream for later creating >an audio fil, storing it in a database blob (my case), send it to the speakers, or whatever you want to do with it.
AudioInputStream gsmAIS = AudioSystem.getAudioInputStream(gsmEncoding, pcm16BitsMonoAIS);
// In my case, i store the GSM AudioInputStream in a definitive OutputStream which later will feed a database blob.
bytesRead = -1;
tempBuffer = new byte[1024 * gsmAIS.getFormat().getFrameSize()];
while((bytesRead = gsmAIS.read(tempBuffer)) != -1){
gsmOutputStream.write(tempBuffer, 0, bytesRead);
}
I then save this to the database by:
preparedStatement.setBinaryStream(n, new ByteArrayInputStream(gsmOutputStream.toByteArray()), gsmOutputStream.size());
Which I assume is all working well (this is equivalent to what I did with PCM stream prior to using GSM).
My problem is in retrieving the stream. I got all the AudioFormat properties from the audioformat generated by
AudioSystem.getAudioInputStream(gsmEncoding, pcm16BitsMonoAIS);
above, and tried:
float sampleRate = 50f;
int sampleSizeInBits = -1; //unknown
int channels = 1;
int frameSize = 33;
float frameRate = 8000f;
AudioInputStream gsmAIS = new AudioInputStream(new ByteArrayInputStream(recording),
new AudioFormat(Encodings.getEncoding("GSM0610"), sampleRate, sampleSizeInBits, channels, frameSize, frameRate, false), recording.length);
return AudioSystem.getAudioInputStream(Encoding.PCM_SIGNED, gsmAIS);
(where recording is my byte[] back out from database)
But this gives me 'conversion not supported' exceptions.
Help appreciated as always
Many thanks
Brad