Skip to content

Commit 4222a1c

Browse files
author
Kevin Ahrendt
committed
use one pipeline media player
1 parent 15db26d commit 4222a1c

File tree

1 file changed

+56
-31
lines changed

1 file changed

+56
-31
lines changed

esp32-s3-box/esp32-s3-box.yaml

Lines changed: 56 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -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-
7267
api:
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

155150
microphone:
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: None
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

174193
micro_wake_word:
175194
models:
@@ -181,7 +200,7 @@ micro_wake_word:
181200
voice_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
@@ -221,7 +240,7 @@ voice_assistant:
221240
on_end:
222241
- wait_until:
223242
not:
224-
voice_assistant.is_running:
243+
media_player.is_announcing:
225244
- if:
226245
condition:
227246
and:
@@ -251,6 +270,7 @@ voice_assistant:
251270
- script.execute: draw_display
252271
on_client_disconnected:
253272
- script.execute: stop_voice_assistant
273+
- lambda: id(voice_assistant_phase) = ${voice_assist_not_ready_phase_id};
254274
- script.execute: draw_display
255275
on_timer_started:
256276
- script.execute: draw_display
@@ -261,24 +281,10 @@ voice_assistant:
261281
on_timer_tick:
262282
- script.execute: draw_display
263283
on_timer_finished:
264-
- script.execute: stop_voice_assistant
265-
- lambda: id(voice_assistant_phase) = ${voice_assist_timer_finished_phase_id};
266284
- switch.turn_on: timer_ringing
267-
- script.execute: draw_display
268285
- wait_until:
269-
not:
270-
microphone.is_capturing:
271-
- while:
272-
condition:
273-
switch.is_on: timer_ringing
274-
then:
275-
- lambda: id(box_speaker).play(id(timer_finished_wave_file), sizeof(id(timer_finished_wave_file)));
276-
- delay: 1s
277-
- wait_until:
278-
not:
279-
speaker.is_playing:
280-
- switch.turn_off: timer_ringing
281-
- script.execute: start_voice_assistant
286+
media_player.is_announcing:
287+
- lambda: id(voice_assistant_phase) = ${voice_assist_timer_finished_phase_id};
282288
- script.execute: draw_display
283289

284290
script:
@@ -466,7 +472,6 @@ script:
466472
then:
467473
- voice_assistant.stop:
468474
- micro_wake_word.stop:
469-
- lambda: id(voice_assistant_phase) = ${voice_assist_not_ready_phase_id};
470475

471476
switch:
472477
- platform: gpio
@@ -522,10 +527,34 @@ switch:
522527
optimistic: true
523528
internal: true
524529
restore_mode: ALWAYS_OFF
530+
on_turn_off:
531+
# Turn off the repeat mode and disable the pause between playlist items
532+
- lambda: |-
533+
id(speaker_media_player)
534+
->make_call()
535+
.set_command(media_player::MediaPlayerCommand::MEDIA_PLAYER_COMMAND_REPEAT_OFF)
536+
.set_announcement(true)
537+
.perform();
538+
id(speaker_media_player)->set_playlist_delay_ms(speaker::AudioPipelineType::ANNOUNCEMENT, 0);
539+
# Stop playing the alarm
540+
- media_player.stop:
541+
announcement: true
525542
on_turn_on:
543+
# Turn on the repeat mode and pause for 1000 ms between playlist items/repeats
544+
- lambda: |-
545+
id(speaker_media_player)
546+
->make_call()
547+
.set_command(media_player::MediaPlayerCommand::MEDIA_PLAYER_COMMAND_REPEAT_ONE)
548+
.set_announcement(true)
549+
.perform();
550+
id(speaker_media_player)->set_playlist_delay_ms(speaker::AudioPipelineType::ANNOUNCEMENT, 1000);
551+
- media_player.speaker.play_on_device_media_file:
552+
media_file: timer_finished_sound
553+
announcement: true
526554
- delay: 15min
527555
- switch.turn_off: timer_ringing
528556

557+
529558
select:
530559
- platform: template
531560
entity_category: config
@@ -699,10 +728,6 @@ color:
699728
- id: paused_timer_color
700729
hex: "3b89e3"
701730

702-
file:
703-
- id: timer_finished_wave_file
704-
file: https://github.com/esphome/wake-word-voice-assistants/raw/main/sounds/timer_finished.wav
705-
706731
spi:
707732
- id: spi_bus
708733
clk_pin: 7

0 commit comments

Comments
 (0)