Repository navigation
code to create mp3 convertor #30
Copy link
Copy link
Open
Description
wendyjuly
opened on Apr 17, 2017
Issue body actions
No description provided.
Reactions are currently unavailable
Activity
Anyone?
- Hi Wendy, Hope this might be of some help http://stackoverflow.com/questions/14085199/mp3-to-wav-conversion-in-java…On Apr 17, 2017 7:17 AM, "wendyjuly" ***@***.***> wrote: Anyone? — You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub <#30 (comment)>, or mute the thread <https://github.com/notifications/unsubscribe-auth/AIyEyxfQCZEauvO9VMeMt4FzE7dZRxAvks5rwsS5gaJpZM4M-zCl> .Reacted by tmduc7
thanks for share.
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); } }}
Reacted by Krishnendu das- 这是来自QQ邮箱的假期自动回复邮件。您好,我最近正在休假中,无法亲自回复您的邮件。我将在假期结束后,尽快给您回复。
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");// Set audio attributes for MP3 AudioAttributes audio = new AudioAttributes(); audio.setCodec("libmp3lame"); audio.setBitRate(128000); audio.setChannels(2); audio.setSamplingRate(44100); EncodingAttributes attrs = new EncodingAttributes(); attrs.setFormat("mp3"); attrs.setAudioAttributes(audio); // Encode Encoder encoder = new Encoder(); try { encoder.encode(source, target, attrs); System.out.println("Conversion completed!"); } catch (EncoderException e) { e.printStackTrace(); } }}
check the maven dependancy..
ws.schild jave-core 3.0.0- 这是来自QQ邮箱的假期自动回复邮件。您好,我最近正在休假中,无法亲自回复您的邮件。我将在假期结束后,尽快给您回复。
- 来件已收到,我会尽快回复
- 感谢来信!已收到您的邮件!
Metadata
Metadata
Assignees
Labels
No labels