@@ -64,11 +64,6 @@ psram:
6464 mode : octal
6565 speed : 80MHz
6666
67- external_components :
68- - source : github://jesserockz/esphome-components
69- components : [file]
70- refresh : 0s
71-
7267api :
7368 on_client_connected :
7469 - script.execute : draw_display
@@ -150,7 +145,7 @@ audio_dac:
150145 - platform : es8311
151146 id : es8311_dac
152147 bits_per_sample : 16bit
153- sample_rate : 16000
148+ sample_rate : 48000
154149
155150microphone :
156151 - platform : i2s_audio
@@ -165,11 +160,35 @@ speaker:
165160 id : box_speaker
166161 i2s_dout_pin : GPIO15
167162 dac_type : external
168- sample_rate : 16000
163+ sample_rate : 48000
169164 bits_per_sample : 16bit
170165 channel : left
171166 audio_dac : es8311_dac
172- buffer_duration : 1000ms # The timer finished audio needs to fit entirely in the buffer
167+ buffer_duration : 100ms
168+
169+ media_player :
170+ - platform : speaker
171+ name : Media Player
172+ id : speaker_media_player
173+ announcement_pipeline :
174+ speaker : box_speaker
175+ format : FLAC
176+ sample_rate : 48000
177+ num_channels : 1 # S3 Box only has one output channel
178+ files :
179+ - id : timer_finished_sound
180+ file : https://github.com/esphome/home-assistant-voice-pe/raw/dev/sounds/timer_finished.flac
181+ on_announcement :
182+ - if :
183+ condition :
184+ lambda : return id(voice_assistant_phase) == ${voice_assist_idle_phase_id};
185+ then :
186+ - script.execute : stop_voice_assistant
187+ - lambda : id(voice_assistant_phase) = ${voice_assist_muted_phase_id};
188+ - script.execute : draw_display
189+ on_idle :
190+ - script.execute : start_voice_assistant
191+ - script.execute : draw_display
173192
174193micro_wake_word :
175194 models :
@@ -181,7 +200,7 @@ micro_wake_word:
181200voice_assistant :
182201 id : va
183202 microphone : box_mic
184- speaker : box_speaker
203+ media_player : speaker_media_player
185204 noise_suppression_level : 2
186205 auto_gain : 31dBFS
187206 volume_multiplier : 2.0
@@ -206,10 +225,12 @@ voice_assistant:
206225 - text_sensor.template.publish :
207226 id : text_response
208227 state : !lambda return x;
209- on_tts_stream_start :
210228 - lambda : id(voice_assistant_phase) = ${voice_assist_replying_phase_id};
211229 - script.execute : draw_display
212- on_tts_stream_end :
230+ on_end :
231+ - wait_until :
232+ not :
233+ media_player.is_announcing :
213234 - if :
214235 condition :
215236 switch.is_off : mute
@@ -218,10 +239,6 @@ voice_assistant:
218239 else :
219240 - lambda : id(voice_assistant_phase) = ${voice_assist_muted_phase_id};
220241 - script.execute : draw_display
221- on_end :
222- - wait_until :
223- not :
224- voice_assistant.is_running :
225242 - if :
226243 condition :
227244 and :
@@ -252,6 +269,7 @@ voice_assistant:
252269 - script.execute : draw_display
253270 on_client_disconnected :
254271 - script.execute : stop_voice_assistant
272+ - lambda : id(voice_assistant_phase) = ${voice_assist_not_ready_phase_id};
255273 - script.execute : draw_display
256274 on_timer_started :
257275 - script.execute : draw_display
@@ -262,29 +280,10 @@ voice_assistant:
262280 on_timer_tick :
263281 - script.execute : draw_display
264282 on_timer_finished :
265- - script.execute : stop_voice_assistant
266- - lambda : id(voice_assistant_phase) = ${voice_assist_timer_finished_phase_id};
267283 - switch.turn_on : timer_ringing
268- - script.execute : draw_display
269- - wait_until :
270- not :
271- microphone.is_capturing :
272- - while :
273- condition :
274- switch.is_on : timer_ringing
275- then :
276- # Ensure the speaker starts before trying to send the timer finished audio
277- - lambda : id(box_speaker).start();
278- - wait_until :
279- condition :
280- speaker.is_playing :
281- - lambda : id(box_speaker).play(id(timer_finished_wave_file), sizeof(id(timer_finished_wave_file)));
282- - delay : 1s
283284 - wait_until :
284- not :
285- speaker.is_playing :
286- - switch.turn_off : timer_ringing
287- - script.execute : start_voice_assistant
285+ media_player.is_announcing :
286+ - lambda : id(voice_assistant_phase) = ${voice_assist_timer_finished_phase_id};
288287 - script.execute : draw_display
289288
290289script :
@@ -472,7 +471,6 @@ script:
472471 then :
473472 - voice_assistant.stop :
474473 - micro_wake_word.stop :
475- - lambda : id(voice_assistant_phase) = ${voice_assist_not_ready_phase_id};
476474
477475switch :
478476 - platform : gpio
@@ -528,7 +526,30 @@ switch:
528526 optimistic : true
529527 internal : true
530528 restore_mode : ALWAYS_OFF
529+ on_turn_off :
530+ # Turn off the repeat mode and disable the pause between playlist items
531+ - lambda : |-
532+ id(speaker_media_player)
533+ ->make_call()
534+ .set_command(media_player::MediaPlayerCommand::MEDIA_PLAYER_COMMAND_REPEAT_OFF)
535+ .set_announcement(true)
536+ .perform();
537+ id(speaker_media_player)->set_playlist_delay_ms(speaker::AudioPipelineType::ANNOUNCEMENT, 0);
538+ # Stop playing the alarm
539+ - media_player.stop :
540+ announcement : true
531541 on_turn_on :
542+ # Turn on the repeat mode and pause for 1000 ms between playlist items/repeats
543+ - lambda : |-
544+ id(speaker_media_player)
545+ ->make_call()
546+ .set_command(media_player::MediaPlayerCommand::MEDIA_PLAYER_COMMAND_REPEAT_ONE)
547+ .set_announcement(true)
548+ .perform();
549+ id(speaker_media_player)->set_playlist_delay_ms(speaker::AudioPipelineType::ANNOUNCEMENT, 1000);
550+ - media_player.speaker.play_on_device_media_file :
551+ media_file : timer_finished_sound
552+ announcement : true
532553 - delay : 15min
533554 - switch.turn_off : timer_ringing
534555
@@ -705,10 +726,6 @@ color:
705726 - id : paused_timer_color
706727 hex : " 3b89e3"
707728
708- file :
709- - id : timer_finished_wave_file
710- file : https://github.com/esphome/wake-word-voice-assistants/raw/main/sounds/timer_finished.wav
711-
712729spi :
713730 - id : spi_bus
714731 clk_pin : 7
0 commit comments