Comments (5)
from java.
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);
}
}
}
from java.
Anyone?
from java.
thanks for share.
from java.
from java.
Related Issues (17)
- Problem
- JdCoders HOT 2
- Hi HOT 4
- Found a possible security concern HOT 2
- shifting.java bug HOT 2
- Programas HOT 2
- Java HOT 2
- Java Code HOT 2
- how to add interface and enum in this code. HOT 1
- only some css support ? HOT 1
- Any.get() method query HOT 2
- Not Suport ChineseWord HOT 2
- It is not converting html with images into pdf HOT 1
- Java code
- Java code
- Java
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from java.