Convert sound file into wav with specific bitrate

2019-06-13 20:42发布

问题:

I have some sound file(basically mp3 but it can be of any bitrate). I need to method to extract specified part of input file(not more than 40 seconds) into 8 bit mono wav output . I would appreciate any help or advice in choosing java library to do that.

回答1:

You can use JavaLayer to decode mp3 into wav. Cutting a 40-second clip from a wav shouldn't be a problem.

You can find some hints about mixing stereo to mono here: http://www.jsresources.org/examples/SingleChannelStereoConverter.html

Converting 16-bit audio to 8-bit is simply removing higher 8 bits: Convert 16 bit pcm to 8 bit

EDIT: More about extracting 40-second parts:

Output of the decoder are pcm samples. if your input is 16-bit stereo 44100Hz, then each frame is 16 bit*2 channels = 4 bytes, each second is 44100 * 4 bytes. Skip as many output bytes as you need until start of the desired part, then dump 44100 * 4 * 40 bytes for 40 your seconds. You can even do mixing to mono and then cutting to 8-bit as you go.



回答2:

I have seen a lot of links for converting in opposite sense that you are asking about, I mean what you usually get is information to convert WAV to MP3 using java, but maybe you can get some idea trying The Java Media Framework API (JMF)

http://www.oracle.com/technetwork/java/javase/tech/index-jsp-140239.html.

They have announced new support to MP3

http://www.oracle.com/technetwork/java/javase/download-137625.html

, maybe you can find an alternative to convert MP3 to WAV.

sorry i can't help with something concrete

Emecas



标签: java mp3 wav