5

I have an application that records a speech sample from the user's microphone and uploads it to a server which then does some stuff with it. It seems I must record with the following parameters to avoid an IllegalArgumentException:

Encoding encoding = AudioFormat.Encoding.PCM_SIGNED;
float sampleRate = 44100.0F;
int sampleSizeInBits = 16;
int channels = 2;
int frameSize = 4;
float frameRate = 44100.0F;
boolean bigEndian = false;

But I need to have it recorded at 16khz, not 44.1, (sampleRate and framerate both, I assume) and it must be in mono (1 channel). The PCM signed is also mandatory, so thats good. (The server is VERY picky and I cannot make any changes to it.) How can I convert this using Java?

I am submitting the audio file via HttpClient as a Filebody to a servlet, saving it on the server, and then processing it.

icedwater
  • 4,701
  • 3
  • 35
  • 50
Woobie
  • 85
  • 2
  • 5

1 Answers1

3

Here are a few good links to get started on your own:

Alternatively (for quick use) this FREE library here is what you'd want:

David Kroukamp
  • 36,155
  • 13
  • 81
  • 138
  • I used the SampleRateConverter.java which did allow me to convert to the 16khz, however, it still throws Exceptions when I try to go to mono from Stereo. Im looking in the Tritonus library but Im not sure wwhat to do. Id rather not convert the file twice although tis looking like that might be what Ill have to do. – Woobie Jul 11 '12 at 15:40
  • Once you are at 16kHz stereo, you could sum the two tracks and divide by two. It is a matter of iterating through the audio file, converting the LittleEndian or BigEndian to ints, doing the averaging math, and converting back to the byte format in a new file. – Phil Freihofner Jul 11 '12 at 19:02