Sound Detection and recording

There’s a few similar postings on here but I haven’t seen anything that is really working. Google search is just filled with references to voice assistant, which is not what I want.

Basically I have a ESP32-S3-N8R2 with a i2s mic (inmp441) attached. I’d like to be able to record the sound when it reaches a certain level. Or when triggered manually. I’d like it to keep recording until the sound drops back below a certain level.

I’ve got the basic config but I don’t know how to get it to write out the files? Or where to write the files? Right now it’s working and I can see the db levels.

I’ve seen this (Record sound from I2S microphone - #3 by SpikeyGG) but it uses the older i2s (which seems to be deprecated?) and not the i2s_audio

And this GitHub - stas-sl/esphome-sound-level-meter but it’s also using i2s

i2s_audio:
 - id: i2s # Microphone
   i2s_lrclk_pin: GPIO6  #WS 
   i2s_bclk_pin: GPIO7 #SCK

microphone:
 - platform: i2s_audio
   id: va_mic
   adc_type: external
   i2s_din_pin: GPIO4 #SD
   channel: left
   pdm: false
   #i2s_audio_id: i2s
   bits_per_sample: 32bit

sensor:
 - platform: sound_level
   passive: False
   peak:
     name: "Peak Loudness"
   rms:
     name: "Average Loudness"

switch:
 - platform: template
   name: "Start Capture "
   id: start_capture
   icon: mdi:account-voice
   optimistic: true
   turn_on_action:
     - logger.log: "microphone.capture: va_mic"
     - microphone.capture: va_mic
   turn_off_action:
     - logger.log: "microphone.stop_capture: va_mic"
     - microphone.stop_capture: va_mic

I don’t have much experience with ESPHome audio but I wouldn’t be surprised if you are in custom component territory with this…