but there is only an option to use a microphone input to determine sound level.
My speaker is digital (SPDIF, literally a speaker component).
How do I tell the sound level component to use the audio data being played back through the speaker as a microphone input to measure levels?
This is a prerequisite to build a VU meter (whether internal to the ESP via a MIPI display, or as an output I can push periodically to another device that will do the display), which is my ultimate goal.
That didn’t work at all. The sound level measurements are all over the place even though I’m playing a known -2.5 dB peak -5.5 dB RMS audio file through the player. Interestingly if the input pin is not connected, the sound level measurements correctly indicate -inf dB
Here is the code I’m using:
i2s_audio:
- id: i2s_output
use_legacy: true
- id: i2s_input
use_legacy: true
microphone:
- platform: i2s_audio
id: external_mic
adc_type: external
i2s_din_pin: GPIO4
sample_rate: 48000
bits_per_sample: 16bit
channel: stereo
i2s_audio_id: i2s_input
sensor:
- platform: sound_level
microphone: external_mic
passive: false
peak:
name: "Peak loudness"
rms:
name: "RMS loudness"
speaker:
- platform: i2s_audio
id: i2s_audio_speaker
dac_type: external
i2s_dout_pin: GPIO21
sample_rate: 48000
bits_per_sample: 16bit
buffer_duration: 80ms
# fill_silence: true
channel: stereo
spdif_mode: true
i2s_audio_id: i2s_output
# Virtual speakers to combine the announcement and media streams together into one output
- platform: mixer
id: mixing_speaker
output_speaker: i2s_audio_speaker
num_channels: 2
source_speakers:
- id: announcement_mixing_input
timeout: never
- id: media_mixing_input
timeout: never
- platform: resampler
id: announcement_resampling_speaker
output_speaker: announcement_mixing_input
sample_rate: 48000
bits_per_sample: 16
- platform: resampler
id: media_resampling_speaker
output_speaker: media_mixing_input
sample_rate: 48000
bits_per_sample: 16
media_player:
- platform: speaker
buffer_size: 524288
# task_stack_in_psram: true
name: Media Player
codec_support_enabled: true
internal: false
announcement_pipeline:
speaker: announcement_resampling_speaker
format: FLAC # FLAC is the least processor intensive codec
num_channels: 1 # Stereo audio is unnecessary for announcements
sample_rate: 48000
media_pipeline:
speaker: media_resampling_speaker
format: FLAC # FLAC is the least processor intensive codec
num_channels: 2
sample_rate: 48000