问题
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.
回答1:
Here are a few good links to get started on your own:
- Using Files and Format Converters
- Java Sound Tutorial
Alternatively (for quick use) this FREE library here is what you'd want:
- SampleRateConverter.java
来源:https://stackoverflow.com/questions/11421874/downsampling-audio-from-44-1khz-to-16khz-in-java