How to play GSM 6.10 compressed files in Java

丶灬走出姿态 提交于 2020-01-06 03:06:13

问题


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


回答1:


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.



来源:https://stackoverflow.com/questions/25932983/how-to-play-gsm-6-10-compressed-files-in-java

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!