问题描述
我在把字节为.mp3声音文件已经出现问题。在我来说,我用用它写(字节)的方法,但它只是创建了MP3扩展名的数据文件,但我不能发挥它在任何播放器在我的电脑的FileOutputStream做到这一点。
I've a problem in converting byte to .mp3 sound file. In my case I do it using FileOutputStream using its write(bytes) method but it just creates a data file with mp3 extension but I cannot play it in any player on my PC.
注:我是从Flex的Michrophone记录并发送的ByteArray到Java
Note: I'm recording it from Flex Michrophone and send ByteArray to java.
哪个图书馆,我应该用在Java中增加MP3声音文件头等等?
Which libraries should I use to add mp3 sound file headers etc. in java?
更新:我甚至不能将我的原始数据所支持的Java API声音格式的波形。它创造了我的声音与录制的声音,但有噪音 - 哪来的问题
UPDATE: I couldn't even convert my raw data to Wave format that is supported by java sound api.. It creates for me sound with recorded sound but with a noise - where's the problem?
下面是我的$ C $下波:
Here's my code for wave:
AudioFormat format = new AudioFormat(Encoding.PCM_SIGNED, 44100, 16, 2, 2, 44100, true);
ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
AudioInputStream stream = new AudioInputStream(bais, format, bytes.length/format.getFrameSize());
AudioSystem.write(stream, AudioFileFormat.Type.WAVE, new File(path+"zzz.wav"));
有什么毛病我AudioFormat的???哪一个做我的MP3的情况下使用?!
What's wrong with my AudioFormat??? And which one do I have to use in MP3 case ?!
急求助!任何帮助将是非常美联社preciated!
Urgent help! Any help will be highly appreciated!
推荐答案
刚写入原始字节与扩展名为.MP3文件不会奇迹般地将数据转换为MP3格式。您需要使用的连接codeR到COM preSS吧。
Just writing the raw bytes to a file with the name extension .mp3 doesn't magically convert the data to the MP3 format. You need to use an encoder to compress it.
一个快速谷歌搜索发现 LAMEOnJ 这是流行的连接codeR。
A quick google search found LAMEOnJ which is a Java API for the popular LAME MP3 encoder.
这篇关于的Flex - Java字节到MP3的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!