1

Can you please tell me how these lines of code can be modified to be able to play some GSM files.

File audioFile = new File(audioFilePath);
AudioInputStream audioStream = AudioSystem.getAudioInputStream(audioFile);
AudioFormat format = audioStream.getFormat();
AudioFormat format = audioStream.getFormat();
DataLine.Info info = new DataLine.Info(Clip.class, format);
Clip audioClip = (Clip) AudioSystem.getLine(info);
audioClip.open(audioStream);
audioClip.start();
audioClip.close();
audioStream.close();

Thanks

QGA
  • 3,114
  • 7
  • 39
  • 62

1 Answers1

2

You need to install a java sound service provider for GSM. FFSampledSP would work (via FFmpeg).

Install it and then, to get to a PCM stream, you might need to convert the GSM stream like this:

    AudioInputStream gsmStream = AudioSystem.getAudioInputStream(new File("audio.gsm"));
    AudioInputStream pcmStream = AudioSystem.getAudioInputStream(AudioFormat.Encoding.PCM_SIGNED, gsmStream);

Limitation: FFSampledSP uses native libraries and is only available for Windows and OS X. Any other platform probably requires quite a bit of work.

Alternatively, you might want to try the GSM 6.10 tritons plugin.

Hendrik
  • 5,085
  • 24
  • 56
  • Thanks a lot, some days ago I posted this question referring on how to use the tritons plugin. However, nobody replied for days therefore I edited the question again removing that bit. Do you know how to use the tritons library FOR PLAYING AUDIO BACK? (I found only source code to encode the audio) Thanks – QGA Sep 26 '14 at 12:37
  • I haven't used tritons myself, but my guess is that it simply needs to be present in your classpath along with the other tritons jars. Then you should be at least able to open the GSM stream. Transform it to a PCM stream (as shown above) and then you should be able to play it. – Hendrik Sep 26 '14 at 12:40
  • This is what I was talking about [Tritons Encoder](http://www.jsresources.org/examples/GSMEncoder.java.html) How can I adapt it to my needs – QGA Sep 26 '14 at 12:41
  • You need to put the right jars in your classpath. Just follow the directions given on http://www.tritonus.org/plugins.html for the GSM plugin. Then the code you posted in your question should work—with the exception that you might have to transform stuff the way I indicated in my answer. – Hendrik Sep 26 '14 at 12:46
  • 1
    If the simple `AudioFormat.Encoding.PCM_SIGNED` does not work, you may need something like this: `AudioInputStream pcmStream = AudioSystem.getAudioInputStream(new AudioFormat(AudioFormat.Encoding.PCM_SIGNED, 44100f, 16, 1, 2, 44100f, true), gsmStream);` - a little bit more verbose... – Hendrik Sep 26 '14 at 13:18