Java中的音频格式 [英] Audio Format in java

查看:431
本文介绍了Java中的音频格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个问题,因为我的语音识别工具套件需要使用16Khz mono .wav格式的声音才能正常工作.但我的麦克风是
44.100 KHz和立体声格式.而且麦克风设置中没有16khz单声道格式.
我尝试使用Java转换此wave文件.但是当我转换声音时

I have a problem because my Speech recognition tool kit need to use sound in 16Khz mono .wav format to work. but my microphone is
44.100 KHz and stereo format. and it''s don''t have 16khz mono format in microphone setting.
I try to use java to convert this wave file. but when i convert sound

//My Input wave File 
AudioFormat audioFormat = new AudioFormat(AudioFormat.Encoding.PCM_SIGNED,44100. 0F, 16, 2, 4, 44100.0F, false);

encoding - PCM_Signed 
sampleRate - 44.1 KHz 
sampleSizeInBits - 16 
channels - Stereo 
frameSize - 4 
frameRate - 44100 
bigEndian - false 






to

// Wave file format that i want 
samplerate : 16 Khz
channels : mono 




它有这样的错误代码





It have an error code like this


Exception in thread "Thread-5" java.lang.IllegalArgumentException: Unsupported conversion: PCM_SIGNED 16000.0 Hz, 16 bit, mono, 2 bytes/frame, little-endian from PCM_SIGNED 44100.0 Hz, 16 bit, stereo, 4 bytes/frame, little-endian

at javax.sound.sampled.AudioSystem.getAudioInputStrea m(Unknown Source)

at Recorder.run(Recorder.java:73)



我尝试像这样在Java中使用代码



I try to use code in java like this

//My Source code

File inputfile = new File("test.wav");

AudioFormat xx = new AudioFormat(AudioFormat.Encoding.PCM_SIGNED,16000. 0F, 16, 1, 2, 16000.0F, false);
m2_audioInputStream = AudioSystem.getAudioInputStream(xx, m_audioInputStream);



却不能用

我尝试在Internet上找到许多解决方案,但似乎无法解决我的问题.因此,如果您告诉我如何转换此wave文件,将非常好.
通过使用Java.

非常感谢您.



but It can''t work

I try to find a lot of solutions in Internet but it seem can''t solve my problem . So It will be very kindness if you tell me how can I convert this wave file.
by using java.

Than you a lot for your help.

推荐答案

很好奇-为什么它必须是16khz/mono?

Java中的声音非常复杂,最近几年几乎没有开发Java Sound API.

我会以44Khz录制,然后进行转换:

http://www.jsresources.org/faq_audio.html#convert_sample_rate [
Just curious - why does it need to be 16khz/mono ?

Sound in Java is very complicated, the Java Sound API is hardly not developed in the last couple of years.

I would record in 44Khz and convert it afterwards:

http://www.jsresources.org/faq_audio.html#convert_sample_rate[^]

these libs are able to do so.


这篇关于Java中的音频格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆