简体   繁体   中英

How to play GSM 6.10 compressed files in Java

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

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 .

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM