我在我的Android应用程序中使用speex lib来完成两部手机可以互相通话。 这是我的客户端代码。当我删除这一行时它很好用: short [] result = SpeexEchoCanceller.getInstance()。process(recordBuff,toShortArray(receiveBuff)); 添加此线路时,另一部手机只会听到很多噪音,听不到我的声音。
private static final int buffSize = 1000; private byte [] receiveBuff = new byte [buffSize];
private short[] recordBuff = new short[buffSize];
private void startTalk(){
new Thread(new Runnable() {
@Override
public void run() {
try {
// start AudioRecord and init speex
SpeexEchoCanceller.getInstance().open(8000,160,100);
//.....some code......
isRecording = true;
while(isRecording){
int len = 0;
if(((len = mServerInputStream.read(receiveBuff)) != -1) && mAudioTrack != null){
mAudioTrack.write(receiveBuff,0,len);
mAudioTrack.flush();
}
mAudioRecord.read(recordBuff, 0, buffSize);
//process echo
short[] result = SpeexEchoCanceller.getInstance().process(recordBuff,toShortArray(receiveBuff));
byte[] resultByte = toByteArray(result);
mServerOutStream.write(resultByte,0,buffSize);
mServerOutStream.flush();
}
} catch (Exception e) {
e.printStackTrace();
}
}
}).start();
}
我在这里找到一个老话题:Android Speex echo cancellation problems 它引用缓冲帧并实现自己的缓冲。但我真的不知道如何实现自己的缓冲,以使我的代码运行良好。