将pcm / wav音频从22khz降至8khz

时间:2013-02-18 04:25:55

标签: android pcm downsampling

我的Android应用程序需要将PCM(22khz)转换为AMR,但API AmrInputStream仅支持 pcm为8khz

我如何下采样 pcm从22 khz到8 khz?

2 个答案:

答案 0 :(得分:1)

采样率在AmrInputStream.java中进行了硬编码。

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

所以你必须先将PCM转换为AMR。

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();

对于下采样,您可以尝试the Mary API

答案 1 :(得分:0)

我找到了一个java缩减示例库:https://github.com/hutm/JSSRC 还有一个c版本可以被jni使用