java 音频格式,java中的音频格式

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)

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);

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.

解决方案

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.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值