Downsampling audio from 44.1kHz to 16kHz in Java

徘徊边缘 提交于 2019-12-07 04:47:09

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!