Repeaker 2mic Pi Hat AEC Problems python3

Hello All.



I need help trying to build a voip or cloud dorbell app with Raspberry Pi3B and Respeaker 2Mic Pi-Hat.

I built an application that send compressed data of live recorded sound from microphone over wifi, from Pi to Phone and vice versa.

I encountered echo while testing and went research. I’ve been researching on the matter for 5 months but still can’t find a solution.

Thus I decided to ask for help.

I’ve tried using the EC Voice Engine made by voicen for AEC and used speexdsp but this still causes echo or noice.

I tried doing live recording with both EC Voice Engine and speexdsp.



EC Voice Engine is software given by voicen, which this site http://wiki.seeedstudio.com/ReSpeaker_2_Mics_Pi_HAT points out to use for AEC, but I just can’t get it right.

Speexdsp is a python library.



Tried this code in terminal on Pi, each line on a new terminal and I tried to run all at the same time to hear live sound, but I get an echo.
</s><i> </i>./ec -i plughw:1 -o plughw:1 -d 100 arecord -f cd -r 16000 i.raw aplay-f cd -r 16000 i.raw <e>

This is a class from my project to cancel out echo, but get noice or echo.
[code]
import wave
import sys
from speexdsp import EchoCanceller
import Thread
import pyaudio
import time
import Shell
import Thread

class AudioStream:
def init(self, Rate, frame_size, buf):
self.rate = Rate
self.frame_size = frame_size
self.buf = buf

    print(self.rate)
    
    self.kill = False

    #self.shell = Shell.Shell("/home/pi/ec/ec -i plughw:1 -o plughw:1 -d 200 -s")
    #self.shell.start()
    #self.out = open("/tmp/ec.output", "rb")
    
    self.p = pyaudio.PyAudio()
    self.writeS = self.p.open(format=pyaudio.paInt16,
                channels=1,
                rate=self.rate,
                output=True,frames_per_buffer=buf )
    self.readS = self.p.open(format=pyaudio.paInt16,
                channels=1,
                rate=self.rate,input=True,frames_per_buffer=buf )
    

    self.echo_canceller = EchoCanceller.create(frame_size, buf, self.rate)
    self.writeBytes = b''
    self.rec = b''

    thread = Thread.Thread(2, "Audio Thread", self.audioSync)
    self.playing = False
    thread.start()

def write(self, data):
    self.writeBytes = data
    self.playing = True
    self.writeS.write(data, self.buf)
    self.playing = False

def read_audio(self):
        #return self.out.read(8192)
    return self.readS.read(self.buf, exception_on_overflow=False)

def audioSync(self):
    while not self.kill:
        while self.playing:
            pass
        #self.rec = self.read_audio()
        self.rec = self.echo_canceller.process(self.read_audio(), self.writeBytes)
        #audioStream.write(self.read_audio())

def aec(self):
    return self.rec

audioStream = AudioStream(44100, 256, 1024*2)
while True:
audioStream.write(audioStream.aec())

[/code]

Thanks for taking the time to read, it’s very much appreciated.

Thank you to those who have answered and read.