Click here to Skip to main content
15,888,176 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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

Java
//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
Java
// 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
Java
//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.
Posted
Updated 28-Mar-12 19:29pm
v2

1 solution

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.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900