从22kHz的到8kHz的下采样PCM / WAV音频(Downsampling pcm/wav a

2019-10-30 04:19发布

我的Android应用程序需要转换PCM(22kHz)环绕到AMR,但API AmrInputStream只为8kHz的PCM支持。

我怎样才能 下采样 为22kHzPCM 8 kHz的?

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

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



Answer 2:

我发现一个java下采样LIB: https://github.com/hutm/JSSRC也有可能通过JNI使用AC版本



文章来源: Downsampling pcm/wav audio from 22khz to 8khz