Skip to content

Commit f677e6e

Browse files
authored
Merge pull request #16 from wizmo2/add-tts-speak-support
Support for Assist tts.speak service
2 parents 7798a6a + 1255d4a commit f677e6e

File tree

5 files changed

+36
-11
lines changed

5 files changed

+36
-11
lines changed

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ notify:
3939
4040
Please note that the `tts_service` parameter, must match the `service_name` defined in the TTS integration.
4141

42+
You can use the Assist `tts.speak` service, but it is required to specify the tts engine entity_id. For example, `entity_id: tts.piper`
43+
4244
### CONFIGURATION VARIABLES & SERVICE OPTIONS
4345
___
4446

@@ -55,6 +57,9 @@ The entity_id of a LMS media_player (single or list for service queue)
5557
Specify which entity_id to track. Messages are not played when state != `home`
5658
Can be any entities/groups when it has a `home` state
5759

60+
#### **entity_id**: `string` | (optional) | CONFIG
61+
The entity_id of the TTS engine (for TTS service "tts.speak" only)
62+
5863
#### **volume**: `float` (optional) | CONFIG & SERVICE QUEUE & SERVICE NOTIFY
5964
Default volume to play the alert_sound and message
6065

custom_components/lms_tts_notify/__init__.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,7 @@ def __init__(self, hass, config):
394394
self._volume = config.get(CONF_VOLUME)
395395
self._pause = config.get(CONF_PAUSE)
396396
self._media_player = config[CONF_MEDIA_PLAYER]
397+
self._tts_engine = config.get(ATTR_ENTITY_ID)
397398
self._config = config
398399
self._sync_group = []
399400
_, self._tts_service = split_entity_id(config[CONF_TTS_SERVICE])
@@ -516,7 +517,18 @@ def audio_alert(self):
516517

517518
# Play message
518519
if self._message:
519-
service_data = {'entity_id': self._media_player, 'message': self._message}
520+
if 'speak' in self._tts_service:
521+
service_data = {
522+
'entity_id': self._tts_engine,
523+
'media_player_entity_id': self._media_player,
524+
'message': self._message,
525+
}
526+
else:
527+
service_data = {
528+
ATTR_ENTITY_ID: self._media_player,
529+
'message': self._message,
530+
}
531+
520532
self._hass.services.call('tts', self._tts_service, service_data)
521533
time.sleep(self._pause)
522534
self.wait_on_idle()

custom_components/lms_tts_notify/manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@
77
"issue_tracker": "https://github.com/floris-b/lms_tts_notify/issues",
88
"after_dependencies": ["media_player", "squuezebox"],
99
"iot_class": "local_push",
10-
"version": "0.3.14"
10+
"version": "0.3.15"
1111
}

custom_components/lms_tts_notify/notify.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,18 @@
1313
from homeassistant.const import ATTR_ENTITY_ID
1414
from homeassistant.components.notify import ATTR_MESSAGE
1515

16-
DOMAIN = "lms_tts_notify"
17-
ATTR_LANGUAGE = "language"
16+
from . import (
17+
DOMAIN,
18+
CONF_MEDIA_PLAYER,
19+
CONF_TTS_SERVICE,
20+
CONF_REPEAT,
21+
CONF_VOLUME,
22+
CONF_ALERT_SOUND,
23+
CONF_DEVICE_GROUP,
24+
CONF_PAUSE,
25+
)
1826

19-
CONF_MEDIA_PLAYER = "media_player"
20-
CONF_TTS_SERVICE = "tts_service"
21-
CONF_REPEAT = "repeat"
22-
CONF_VOLUME = "volume"
23-
CONF_ALERT_SOUND = "alert_sound"
24-
CONF_DEVICE_GROUP = "device_group"
25-
CONF_PAUSE = "pause"
27+
ATTR_LANGUAGE = "language"
2628

2729
_LOGGER = logging.getLogger(__name__)
2830

@@ -32,6 +34,7 @@
3234
vol.Required(CONF_TTS_SERVICE): cv.entity_id,
3335
vol.Required(CONF_MEDIA_PLAYER): cv.entity_id,
3436
vol.Required(CONF_DEVICE_GROUP): cv.entity_id,
37+
vol.Optional(ATTR_ENTITY_ID): cv.entity_id,
3538
vol.Optional(ATTR_LANGUAGE): cv.string,
3639
vol.Optional(CONF_REPEAT, default=1): cv.positive_int,
3740
vol.Optional(CONF_ALERT_SOUND, default=""): cv.string,

info.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ notify:
3939
4040
Please note that the `tts_service` parameter, must match the `service_name` defined in the TTS integration.
4141

42+
You can use the Assist `tts.speak` service, but it is required to specify the tts engine entity_id. For example, `entity_id: tts.piper`
43+
4244
### CONFIGURATION VARIABLES & SERVICE OPTIONS
4345
___
4446

@@ -55,6 +57,9 @@ The entity_id of a LMS media_player (single or list for service queue)
5557
Specify which entity_id to track. Messages are not played when state != `home`
5658
Can be any entities/groups when it has a `home` state
5759

60+
#### **entity_id**: `string` | (optional) | CONFIG
61+
The entity_id of the TTS engine (for TTS service "tts.speak" only)
62+
5863
#### **volume**: `float` (optional) | CONFIG & SERVICE QUEUE & SERVICE NOTIFY
5964
Default volume to play the alert_sound and message
6065

0 commit comments

Comments
 (0)