Esphome makes use of mqtt to ship and play audio
Hello, everyone!
I need to use mqtt to ship audio and play it on one other esp32, however the acquired audio may be very noisy and the tone turns into child sounds.
ship code:
microphone:
- platform: i2s_audio
id: external_mic
adc_type: exterior
pdm: false
i2s_audio_id: i2s_in
i2s_din_pin: GPIO33 #SD
bits_per_sample: 32bit
use_apll: false
sample_rate: 16000
channel: proper
on_data:
- lambda: |-
for (uint16_t byte : x) {
id(audio_buffer).push_back(byte);
}
if(id(audio_buffer).measurement() >= 256){
id(mqtt_client).publish_json("name/message", [=](JsonObject root) {
root["key"] = "audio";
JsonArray audio_data = root.createNestedArray("information");
for (size_t i = 0; i < id(audio_buffer).measurement(); i++) {
uint8_t worth = static_cast<uint8_t>(id(audio_buffer)[i] >>8);
audio_data.add(worth);
}
});
id(audio_buffer).clear();
}
obtain code:
speaker:
- platform: i2s_audio
i2s_audio_id: i2s_out
dac_type: exterior
i2s_dout_pin: GPIO13
mode: mono
id: speaker_audio
mqtt:
dealer: 192.168.6.8
discovery: False
reboot_timeout: 0s
id: mqtt_client
on_json_message:
subject: name/message
then:
- lambda: |-
if (x.containsKey("key") && x["key"] == "audio" && x.containsKey("information")) {
std::vector<uint8_t> speaker_buffer;
for (size_t i = 0; i < x["data"].measurement(); i++) {
uint8_t worth = x["data"][i];
speaker_buffer.push_back(worth);
}
id(speaker_audio).play(speaker_buffer.information(),speaker_buffer.measurement());
speaker_buffer.clear();
}
1 put up – 1 participant
HI-FI News
through Home Assistant Community – Latest subjects https://ift.tt/taNxM20
July 29, 2024 at 05:27AM
-
Product on sale
Audiophile Vinyl Records Cleaning BundleOriginal price was: €69.90.€59.90Current price is: €59.90. incl. VAT -
Product on sale
Easy Start Vinyl Records Cleaning KitOriginal price was: €69.90.€59.90Current price is: €59.90. incl. VAT -
Vinyl Records Cleaner Easy Groove Concentrate€34.95 incl. VAT -
Easy Groove Super Set€199.00 incl. VAT -
Easy Groove Enzycaster – vinyl records prewash cleaner€34.95 incl. VAT -
Easy Groove Extreme MK. II- vinyl records prewash cleaner€45.00 incl. VAT -
Vinyl Records Cleaner – Easy Groove Virgin Concentrate€35.00 incl. VAT -
Easy Groove Spray&Wipe vinyl records cleaner€34.95 incl. VAT








