How to send TTS reply from Voice Assistant to a separate speaker and be able to change it in the UI

Basic rundown of what I’m working with. I have a bunch of ESP32-S3’s with mic’s that I’m putting around the house. I have in ceiling speakers in most rooms and google mini’s in the rooms without them. I’d like to be able to select the speaker (media player) to use in the HA UI instead of hard coding it in the ESP.

Yes I know I can add this to hardcode it like this:

  on_tts_end:
    - homeassistant.service:
        service: media_player.play_media
        data:
          entity_id: media_player.nest_mini
          media_content_id: !lambda 'return x;'
          media_content_type: music
          annouce: "true"

It seems like there should be a way to make a virtual speaker or media_player in the ESPhome config file and have a selector in the UI. Even if I needed to hardcode a list of all of my speakers in the yaml that would be better than maintaining 20 different files - one for each speaker.

Anyone find a way to do this?

hi i use this automation to redirect assist audio out

alias: "ollamaspeak"
description: ""
triggers:
  - trigger: conversation
    command: "{question}"
conditions: []
actions:
  - action: conversation.process
    metadata: {}
    data:
      agent_id: conversation.llama3_2  #change this
      text: "{{trigger.slots.question }}"
    response_variable: rep
  - set_conversation_response: "{{ rep.response.speech.plain.speech }}"
    enabled: true
  - action: tts.speak
    metadata: {}
    data:
      cache: false
       media_player_entity_id: your speaker entity
      #media_player_entity_id: "{{ states('input_select.changeout') }}"
      message: "{{ rep.response.speech.plain.speech }}"
    target:
      entity_id: tts.piper
mode: single

if you have multiple speaker you can create an input-select helper with your media_player entity

comment this line
media_player_entity_id: your speaker entity

uncomment this one
#media_player_entity_id: “{{ states(‘input_select.changeout’) }}”
change “changeout” by the name of the helper you just created

1 Like

And how can you not output sound to the M5Stack Atom Echo speaker?

you can create an automation to cut the sound if an other speaker is selected for exemple

alias: Test select
description: ""
triggers:
  - trigger: state
    entity_id:
      - input_select.changeout
    from: null
    to: null
conditions: []
actions:
  - if:
      - condition: not
        conditions:
          - condition: state
            entity_id: input_select.changeout
            state: media_player.proto_assist_mdp_assist
    then:
      - action: media_player.volume_mute
        metadata: {}
        data:
          is_volume_muted: true
        target:
          entity_id: media_player.proto_assist_mdp_assist
mode: single

or don’t use the speaker part in your esphome assist, the speaker part is optional

1 Like

I didn’t understand “or don’t use a speaker in your echo assistant, a speaker is optional”. In the M5 Atom Echo, the output goes directly to the speaker. Your automation sends the sound to my speaker and then to the M5 Atom Echo’s speaker. media_player.media_stop - can’t solve this problem?

sorry, i wasn’t clear

speaker:
  - platform: i2s_audio
    i2s_audio_id: i2s_out
    #name: mdp2
    id: big_speaker
    dac_type: external
    i2s_dout_pin: GPIO04
    sample_rate: 48000
  - platform: mixer
    id: mixer_speaker_id
    output_speaker: big_speaker
    source_speakers:
      - id: announcement_spk_mixer_input
      - id: media_spk_mixer_input
  - platform: resampler
    id: media_spk_resampling_input
    output_speaker: media_spk_mixer_input
  - platform: resampler
    id: announcement_spk_resampling_input
    output_speaker: announcement_spk_mixer_input

media_player:
  - platform: speaker
    name: mdp_assist
    id: mdp_assist
    media_pipeline:
        speaker: media_spk_resampling_input
        num_channels: 1
    announcement_pipeline:
        speaker: announcement_spk_resampling_input
        num_channels: 1

voice_assistant:
  microphone: mic
  use_wake_word: true
  noise_suppression_level: 2
  auto_gain: 31dBFS
  volume_multiplier: 1.9
  speaker: big_speaker      ################### delete this
  id: assist
  on_listening:
    - light.turn_on:
        id: rgb_light
        blue: 1
        red: 0
        green: 0
        brightness: 100%
        effect: Pulse

in your esphome yaml you don’t use the speaker in voice_assistant: … , the speaker is only used by the media_player entity.

1 Like

I made this automation and everything works the way I wanted it to.

And of course, your automation! That is, everything that the firmware does, two automations do, but you don’t need to reflash anything!

alias: "M5Stack Atom Echo: Stop when starts playing"
description: Automatically stops the M5Stack if it starts playing
triggers:
  - entity_id: media_player.m5stack_atom_echo_fd623c
    to: playing
    trigger: state
actions:
  - data:
      entity_id: media_player.m5stack_atom_echo_fd623c
    action: media_player.media_stop
mode: single

With your automation you will not bé able to use the m5stack media_player with anything but if it’s good for you then perfect. Have fun😁

I am using an Apple HomePod mini. The idea was to disable the sound output in m5stack media_player.