esphome / feature-requests

ESPHome Feature Request Tracker
https://esphome.io/
415 stars 26 forks source link

Would like to be able to configure sample rate in i2s_audio_microphone in the YAML #2289

Open ripnetuk opened 1 year ago

ripnetuk commented 1 year ago

Describe the problem you have/What new integration you would like I would like an option to be able to specify the sample rate for the I2S microphone component in the YAML in the same fashion as has recently been introduced for bits_per_sample.

This would involve adding a new config to the python file, and using that instead of the hard coded 16000 on line 56 of i2s_audio_microphone.cpp.

It would [if feasible] largely be a copy/paste job for the recent commit for bits_per_sample.

Please describe your use case for this integration and alternatives you've tried: I am doing FFTs on the audio to drive a WLED type light show on neopixels. At the moment, it works up to 8000Hz, which is correct for the hard coded sample rate of 16000.

Additional context Questions:

  1. Is the ESP32 powerful to sample at CD quality (about 44000)? thats a big jump from 16000? would it leave enough spare CPU cycles to do other useful stuff like driving a display and/or a IR receiver? if it uses 100% of the CPU its a bit pointless doing this in ESPHome and I might as well just use WLED.
  2. If so, we need to know the permitted frequencies. I propose making it an enum like the bits_per_sample nearby in the code
  3. Im still unsure how the timing on this works - it DOES work, and im not losing any samples, but how is it that every time loop() is called, we magically have 128 samples. Does the timeout in the I2S read mean that the loop method in I2SAudioMicrophone is actually holding up the execution until it has 512 bytes of data available? maybe thats so quick that it makes no odds. This might have implications if we triple the sample rate.

Thank you for reading.

Unfocused commented 7 months ago

Fixed in 2024.2.0:

You can now specify sample_rate, which defaults to 16000: