Flex - Java 字节到 mp3 [英] Flex - Java byte to mp3
问题描述
我在将字节转换为 .mp3 声音文件时遇到问题.在我的情况下,我使用 FileOutputStream 使用它的 write(bytes) 方法来完成它,但它只是创建了一个带有 mp3 扩展名的数据文件,但我无法在我的 PC 上的任何播放器中播放它.
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 sound api 支持的 Wave 格式.它为我创建了带有录制声音但带有噪音的声音 - 问题出在哪里?
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?
这是我的 wave 代码:
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 ?!
紧急帮助!任何帮助将不胜感激!
Urgent help! Any help will be highly appreciated!
推荐答案
仅将原始字节写入扩展名为 .mp3 的文件并不会神奇地将数据转换为 MP3 格式.您需要使用编码器对其进行压缩.
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 这是流行的 LAME MP3 编码器.
A quick google search found LAMEOnJ which is a Java API for the popular LAME MP3 encoder.
这篇关于Flex - Java 字节到 mp3的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!