1

I use speex lib in my android app to complete that two phones can talk to each other. This is my client code. It works well when I delete this line: short[] result = SpeexEchoCanceller.getInstance().process(recordBuff,toShortArray(receiveBuff)); When add this line, another phone only hear a lot of noise and can not hear my voice.

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

I find an old topic here:Android Speex echo cancellation problems It references buffer frame and implement own buffering. But I really don't know how to implement my own buffering to make my code work well.

shaotine
  • 249
  • 3
  • 15

0 Answers0