Speaker Script
This is an example of a script which can be used to deliver custom responses.
- It uses the speaker closest to the user
- It switches from cloud-based voice to local voice if the internet is down
tts_response:
sequence:
- if:
- condition: state
entity_id: input_boolean.use_cloud_service
state: 'off'
then:
- action: tts.speak
metadata: {}
data:
cache: true
media_player_entity_id: '{{ states(''sensor.speaker'') }}'
message: '{{ tts_sentence }}'
target:
entity_id: tts.piper
else:
- action: tts.speak
metadata: {}
data:
cache: true
media_player_entity_id: '{{ states(''sensor.speaker'') }}'
message: '{{ tts_sentence }}'
options:
voice: XYZ123
target:
entity_id: tts.elevenlabs
enabled: true
alias: TTS response
fields:
tts_sentence:
selector:
text: {}
name: TTS_sentence
Notes
input_boolean.use_cloud_service
is an input_boolean flag - an automation turns it on when the internet is available, off when it isn't. It is also turned off if Elevenlabs credit has run out.
sensor.speaker
is a template sensor holding the entity ID of the speaker nearest the user.
There are several ways to figure out where the user is - motion sensors are quite effective, or you can use a tracking integration like Bermuda.
tts_sentence
is the sentence generated by an intent
voice: XYZ
is the code for the voice being used (so that Elevenlabs can charge you for it).