feat(esp): play audio from bluetooth speaker
All checks were successful
Discord / discord commits (push) Has been skipped

This commit is contained in:
matt1432 2024-09-10 19:10:02 -04:00
parent e65fdd95eb
commit 45e671e2bb
2 changed files with 68 additions and 44 deletions

View file

@ -71,7 +71,7 @@
speaker = [ speaker = [
{ {
dac_type = "external"; dac_type = "external";
i2s_dout_pin = "GPIO22"; i2s_dout_pin = "GPIO21"; # "GPIO22"; turn off speaker
id = "echo_speaker"; id = "echo_speaker";
mode = "mono"; mode = "mono";
platform = "i2s_audio"; platform = "i2s_audio";
@ -308,33 +308,67 @@
vad_threshold = 3; vad_threshold = 3;
volume_multiplier = 2; volume_multiplier = 2;
on_client_connected = [ on_listening = [
{ {
"if" = { "light.turn_on" = {
condition = {"switch.is_on" = "use_wake_word";}; id = "led";
"then" = [ effect = "Slow Pulse";
{"voice_assistant.start_continuous" = {};}
{"script.execute" = "reset_led";} green = "0%";
]; red = "0%";
blue = "100%";
}; };
} }
]; ];
on_client_disconnected = [
on_stt_vad_end = [
{ {
"if" = { "light.turn_on" = {
condition = {"switch.is_on" = "use_wake_word";}; id = "led";
"then" = [ effect = "Fast Pulse";
{"voice_assistant.stop" = {};}
{"light.turn_off" = "led";} red = "0%";
]; green = "0%";
blue = "100%";
}; };
} }
]; ];
on_tts_start = [
{
"light.turn_on" = {
id = "led";
brightness = "100%";
effect = "none";
red = "0%";
green = "0%";
blue = "100%";
};
}
];
# Play audio from bluetooth speaker
on_tts_end = [
{
"homeassistant.service" = {
service = "media_player.play_media";
data = {
entity_id = "media_player.music_player_daemon";
media_content_id = "!lambda \"return x;\"";
media_content_type = "music";
announce = "\"true\"";
};
};
}
];
on_end = [ on_end = [
{delay = "100ms";} {delay = "100ms";}
{wait_until.not."speaker.is_playing" = {};} {wait_until.not."speaker.is_playing" = {};}
{"script.execute" = "reset_led";} {"script.execute" = "reset_led";}
]; ];
on_error = [ on_error = [
{ {
"light.turn_on" = { "light.turn_on" = {
@ -350,30 +384,31 @@
{delay = "1s";} {delay = "1s";}
{"script.execute" = "reset_led";} {"script.execute" = "reset_led";}
]; ];
on_listening = [
{
"light.turn_on" = {
id = "led";
effect = "Slow Pulse";
green = "0%"; on_client_connected = [
red = "0%"; {
blue = "100%"; "if" = {
condition = {"switch.is_on" = "use_wake_word";};
"then" = [
{"voice_assistant.start_continuous" = {};}
{"script.execute" = "reset_led";}
];
}; };
} }
]; ];
on_stt_vad_end = [
{
"light.turn_on" = {
id = "led";
effect = "Fast Pulse";
red = "0%"; on_client_disconnected = [
green = "0%"; {
blue = "100%"; "if" = {
condition = {"switch.is_on" = "use_wake_word";};
"then" = [
{"voice_assistant.stop" = {};}
{"light.turn_off" = "led";}
];
}; };
} }
]; ];
on_timer_finished = [ on_timer_finished = [
{"voice_assistant.stop" = {};} {"voice_assistant.stop" = {};}
{"switch.turn_on" = "timer_ringing";} {"switch.turn_on" = "timer_ringing";}
@ -411,19 +446,6 @@
}; };
} }
]; ];
on_tts_start = [
{
"light.turn_on" = {
id = "led";
brightness = "100%";
effect = "none";
red = "0%";
green = "0%";
blue = "100%";
};
}
];
}; };
}; };
}; };

View file

@ -40,6 +40,8 @@
cp ${format.generate name filteredConfig} $out cp ${format.generate name filteredConfig} $out
sed -i -e "s/'\!\([a-z_]\+\) \(.*\)'/\!\1 \2/;s/^\!\!/\!/;" $out sed -i -e "s/'\!\([a-z_]\+\) \(.*\)'/\!\1 \2/;s/^\!\!/\!/;" $out
sed -i 's/ {}//g' $out sed -i 's/ {}//g' $out
sed -i "s/'\"/\"/g" $out
sed -i "s/\"'/\"/g" $out
''; '';
}; };
in { in {