从22kHz的到8kHz的下采样PCM

从22kHz的到8kHz的下采样PCM

本文介绍了从22kHz的到8kHz的下采样PCM / WAV音频的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的Andr​​oid应用程序需要PCM(22kHz)环绕转换为AMR,但是API AmrInputStream 只支持 8kHz的PCM的

My android application needs to convert PCM(22khz) to AMR , but the API AmrInputStream only supports with pcm of 8khz.

我怎么能 downsample的 PCM 22 kHz到8千?

推荐答案

采样率是AmrInputStream.java硬codeD。

The sample rate is hard coded in AmrInputStream.java.

// frame is 20 msec at 8.000 khz
private final static int SAMPLES_PER_FRAME = 8000 * 20 / 1000;

所以,你必须到PCM首先转换为AMR。

So you have to convert the PCM to AMR first.

InputStream inStream;
inStream = new FileInputStream(wavFilename);
AmrInputStream aStream = new AmrInputStream(inStream);

File file = new File(amrFilename);
file.createNewFile();
OutputStream out = new FileOutputStream(file);

//adding tag #!AMR\n
out.write(0x23);
out.write(0x21);
out.write(0x41);
out.write(0x4D);
out.write(0x52);
out.write(0x0A);

byte[] x = new byte[1024];
int len;
while ((len=aStream.read(x)) > 0) {
    out.write(x,0,len);
}

out.close();

有关下采样,您可以尝试玛丽API 。

For Downsampling, You can try the Mary API.

这篇关于从22kHz的到8kHz的下采样PCM / WAV音频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-14 00:55