You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
hi Wendy,
see the my code of converting mp3 convertor
import javazoom.jl.decoder.Bitstream;
import javazoom.jl.decoder.JavaLayerException;
import javazoom.jl.player.advanced.AdvancedPlayer;
import javazoom.jl.player.advanced.PlaybackEvent;
import javazoom.jl.player.advanced.PlaybackListener;
import javax.sound.sampled.*;
public class MP3Converter {
public static void main(String[] args) {
convertMP3ToWAV("input.mp3", "output.wav");
}
public static void convertMP3ToWAV(String mp3FilePath, String wavFilePath) {
try {
AudioInputStream mp3Stream = getMP3Stream(mp3FilePath);
AudioFormat mp3Format = mp3Stream.getFormat();
AudioFormat pcmFormat = new AudioFormat(
AudioFormat.Encoding.PCM_SIGNED,
mp3Format.getSampleRate(),
16,
mp3Format.getChannels(),
mp3Format.getChannels() * 2,
mp3Format.getSampleRate(),
false
);
AudioInputStream pcmStream = AudioSystem.getAudioInputStream(pcmFormat, mp3Stream);
AudioSystem.write(pcmStream, AudioFileFormat.Type.WAVE, new java.io.File(wavFilePath));
mp3Stream.close();
pcmStream.close();
} catch (Exception e) {
e.printStackTrace();
}
}
private static AudioInputStream getMP3Stream(String mp3FilePath) throws JavaLayerException {
FileInputStream fileInputStream = null;
try {
fileInputStream = new FileInputStream(mp3FilePath);
Bitstream bitstream = new Bitstream(fileInputStream);
int channels = bitstream.readFrame().readStereo() ? 2 : 1;
fileInputStream.close(); // Close and reopen to reset file pointer
fileInputStream = new FileInputStream(mp3FilePath);
return new AudioInputStream(new BufferedInputStream(fileInputStream),
new AudioFormat(AudioFormat.Encoding.PCM_SIGNED,
AudioSystem.NOT_SPECIFIED,
16,
channels,
channels * 2,
AudioSystem.NOT_SPECIFIED,
false),
AudioSystem.NOT_SPECIFIED);
} catch (Exception e) {
throw new JavaLayerException("Error creating MP3 AudioInputStream", e);
}
}
Activity
wendyjuly commentedon Apr 17, 2017
Anyone?
sanjeeth-07 commentedon Apr 17, 2017
fwx412269 commentedon Aug 29, 2019
thanks for share.
sanjeet28 commentedon Dec 12, 2023
hi Wendy,
see the my code of converting mp3 convertor
import javazoom.jl.decoder.Bitstream;
import javazoom.jl.decoder.JavaLayerException;
import javazoom.jl.player.advanced.AdvancedPlayer;
import javazoom.jl.player.advanced.PlaybackEvent;
import javazoom.jl.player.advanced.PlaybackListener;
import javax.sound.sampled.*;
public class MP3Converter {
}
fwx412269 commentedon Dec 12, 2023
reachvangala commentedon Aug 1, 2025
Hi,
Please check the below code..
import ws.schild.jave.*;
import java.io.File;
public class AudioConverter {
public static void main(String[] args) {
File source = new File("input.wav");
File target = new File("output.mp3");
}
check the maven dependancy..
ws.schild jave-core 3.0.0fwx412269 commentedon Aug 1, 2025
huangfuyixiao commentedon Aug 1, 2025
SiweiZhong commentedon Aug 1, 2025