Skip to content

Commit 3c05479

Browse files
author
Kevin Ahrendt
committed
use one pipeline media player
1 parent 2d7eef7 commit 3c05479

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
@@ -66,11 +66,6 @@ psram:
6666
mode: octal
6767
speed: 80MHz
6868

69-
external_components:
70-
- source: github://jesserockz/esphome-components
71-
components: [file]
72-
refresh: 0s
73-
7469
api:
7570
on_client_connected:
7671
- script.execute: draw_display
@@ -152,7 +147,7 @@ audio_dac:
152147
- platform: es8311
153148
id: es8311_dac
154149
bits_per_sample: 16bit
155-
sample_rate: 16000
150+
sample_rate: 48000
156151

157152
microphone:
158153
- platform: i2s_audio
@@ -167,11 +162,35 @@ speaker:
167162
id: box_speaker
168163
i2s_dout_pin: GPIO15
169164
dac_type: external
170-
sample_rate: 16000
165+
sample_rate: 48000
171166
bits_per_sample: 16bit
172167
channel: left
173168
audio_dac: es8311_dac
174-
buffer_duration: 1000ms # The timer finished audio needs to fit entirely in the buffer
169+
buffer_duration: 100ms
170+
171+
media_player:
172+
- platform: speaker
173+
name: None
174+
id: speaker_media_player
175+
announcement_pipeline:
176+
speaker: box_speaker
177+
format: FLAC
178+
sample_rate: 48000
179+
num_channels: 1 # S3 Box only has one output channel
180+
files:
181+
- id: timer_finished_sound
182+
file: https://github.com/esphome/home-assistant-voice-pe/raw/dev/sounds/timer_finished.flac
183+
on_announcement:
184+
- if:
185+
condition:
186+
lambda: return id(voice_assistant_phase) == ${voice_assist_idle_phase_id};
187+
then:
188+
- script.execute: stop_voice_assistant
189+
- lambda: id(voice_assistant_phase) = ${voice_assist_muted_phase_id};
190+
- script.execute: draw_display
191+
on_idle:
192+
- script.execute: start_voice_assistant
193+
- script.execute: draw_display
175194

176195
micro_wake_word:
177196
models:
@@ -183,7 +202,7 @@ micro_wake_word:
183202
voice_assistant:
184203
id: va
185204
microphone: box_mic
186-
speaker: box_speaker
205+
media_player: speaker_media_player
187206
noise_suppression_level: 2
188207
auto_gain: 31dBFS
189208
volume_multiplier: 2.0
@@ -223,7 +242,7 @@ voice_assistant:
223242
on_end:
224243
- wait_until:
225244
not:
226-
voice_assistant.is_running:
245+
media_player.is_announcing:
227246
- if:
228247
condition:
229248
and:
@@ -253,6 +272,7 @@ voice_assistant:
253272
- script.execute: draw_display
254273
on_client_disconnected:
255274
- script.execute: stop_voice_assistant
275+
- lambda: id(voice_assistant_phase) = ${voice_assist_not_ready_phase_id};
256276
- script.execute: draw_display
257277
on_timer_started:
258278
- script.execute: draw_display
@@ -263,24 +283,10 @@ voice_assistant:
263283
on_timer_tick:
264284
- script.execute: draw_display
265285
on_timer_finished:
266-
- script.execute: stop_voice_assistant
267-
- lambda: id(voice_assistant_phase) = ${voice_assist_timer_finished_phase_id};
268286
- switch.turn_on: timer_ringing
269-
- script.execute: draw_display
270287
- wait_until:
271-
not:
272-
microphone.is_capturing:
273-
- while:
274-
condition:
275-
switch.is_on: timer_ringing
276-
then:
277-
- lambda: id(box_speaker).play(id(timer_finished_wave_file), sizeof(id(timer_finished_wave_file)));
278-
- delay: 1s
279-
- wait_until:
280-
not:
281-
speaker.is_playing:
282-
- switch.turn_off: timer_ringing
283-
- script.execute: start_voice_assistant
288+
media_player.is_announcing:
289+
- lambda: id(voice_assistant_phase) = ${voice_assist_timer_finished_phase_id};
284290
- script.execute: draw_display
285291

286292
script:
@@ -468,7 +474,6 @@ script:
468474
then:
469475
- voice_assistant.stop:
470476
- micro_wake_word.stop:
471-
- lambda: id(voice_assistant_phase) = ${voice_assist_not_ready_phase_id};
472477

473478
switch:
474479
- platform: gpio
@@ -524,10 +529,34 @@ switch:
524529
optimistic: true
525530
internal: true
526531
restore_mode: ALWAYS_OFF
532+
on_turn_off:
533+
# Turn off the repeat mode and disable the pause between playlist items
534+
- lambda: |-
535+
id(speaker_media_player)
536+
->make_call()
537+
.set_command(media_player::MediaPlayerCommand::MEDIA_PLAYER_COMMAND_REPEAT_OFF)
538+
.set_announcement(true)
539+
.perform();
540+
id(speaker_media_player)->set_playlist_delay_ms(speaker::AudioPipelineType::ANNOUNCEMENT, 0);
541+
# Stop playing the alarm
542+
- media_player.stop:
543+
announcement: true
527544
on_turn_on:
545+
# Turn on the repeat mode and pause for 1000 ms between playlist items/repeats
546+
- lambda: |-
547+
id(speaker_media_player)
548+
->make_call()
549+
.set_command(media_player::MediaPlayerCommand::MEDIA_PLAYER_COMMAND_REPEAT_ONE)
550+
.set_announcement(true)
551+
.perform();
552+
id(speaker_media_player)->set_playlist_delay_ms(speaker::AudioPipelineType::ANNOUNCEMENT, 1000);
553+
- media_player.speaker.play_on_device_media_file:
554+
media_file: timer_finished_sound
555+
announcement: true
528556
- delay: 15min
529557
- switch.turn_off: timer_ringing
530558

559+
531560
select:
532561
- platform: template
533562
entity_category: config
@@ -701,10 +730,6 @@ color:
701730
- id: paused_timer_color
702731
hex: "3b89e3"
703732

704-
file:
705-
- id: timer_finished_wave_file
706-
file: https://github.com/esphome/wake-word-voice-assistants/raw/main/sounds/timer_finished.wav
707-
708733
spi:
709734
- id: spi_bus
710735
clk_pin: 7

0 commit comments

Comments
 (0)