Help: RPi4 + ReSpeaker2michat+picovoice not working

I am stuck for couple days now, need help to proceed. Followed the guides on ReSpeaker2micHat for RPi4, all setup and demos worked succesfully, turning LEDs on and off, wake words. Now I’m trying to configure picovoice to start building custom voice commands in python. I can initialize picovoice correctly, i can record and play sounds in terminal using aplay and arecord, but I cannot get this part to work:

try:
while True:
audio_frame = next(get_next_audio_frame())
keyword_index = porcupine.process(audio_frame)

    if keyword_index >= 0:
        print("Wake word detected")
        pass

I think the problem is at get_next_audio_frame() which i cant get to work with the seeed hat, my code for that part right now is:

import pyaudio

def get_next_audio_frame():
RESPEAKER_RATE = 16000
RESPEAKER_CHANNELS = 1
RESPEAKER_WIDTH = 2
RESPEAKER_INDEX = 3

CHUNK = 512

p = pyaudio.PyAudio()

stream = p.open(
    rate=RESPEAKER_RATE,
    format=p.get_format_from_width(RESPEAKER_WIDTH),
    channels=RESPEAKER_CHANNELS,
    input=True,
    input_device_index=RESPEAKER_INDEX,
)

try:
    while True:
        data = stream.read(CHUNK)
        yield data
except KeyboardInterrupt:
    pass
finally:
    stream.stop_stream()
    stream.close()
    p.terminate()

I need help integrating seeed2michat with picovoice, using python

Hi,Leonardo_Rosa:
Are you stuck doing the ‘Custom Voice Commands’ step?I didn’t find wrong with the presentation.Can you tell me more about your problem?thank