使用Java将音频从44.1kHz下采样到16kHz [英] Downsampling audio from 44.1kHz to 16kHz in Java

查看:273
本文介绍了使用Java将音频从44.1kHz下采样到16kHz的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个应用程序,它记录来自用户麦克风的语音样本并将其上传到服务器,然后服务器对其进行处理。看来我必须使用以下参数进行记录,以避免 IllegalArgumentException

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;

但是我需要记录16khz而不是44.1,(sampleRate和framerate都是,我假设)它必须是单声道(1声道)。 PCM签名也是强制性的,所以这很好。 (服务器非常挑剔,我不能对它进行任何更改。)如何使用Java转换它?

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?

我通过HttpClient作为Filebody提交音频文件到一个servlet,将它保存在服务器上,然后处理它。

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

推荐答案

这里有一些很好的链接可以开始使用你自己的:

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

这篇关于使用Java将音频从44.1kHz下采样到16kHz的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆