Skip to content

Commit

Permalink
Merge pull request #16 from wizmo2/add-tts-speak-support
Browse files Browse the repository at this point in the history
Support for Assist tts.speak service
  • Loading branch information
floris-b authored Jan 20, 2024
2 parents 7798a6a + 1255d4a commit f677e6e
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 11 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ notify:
Please note that the `tts_service` parameter, must match the `service_name` defined in the TTS integration.

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`

### CONFIGURATION VARIABLES & SERVICE OPTIONS
___

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

#### **entity_id**: `string` | (optional) | CONFIG
The entity_id of the TTS engine (for TTS service "tts.speak" only)

#### **volume**: `float` (optional) | CONFIG & SERVICE QUEUE & SERVICE NOTIFY
Default volume to play the alert_sound and message

Expand Down
14 changes: 13 additions & 1 deletion custom_components/lms_tts_notify/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,7 @@ def __init__(self, hass, config):
self._volume = config.get(CONF_VOLUME)
self._pause = config.get(CONF_PAUSE)
self._media_player = config[CONF_MEDIA_PLAYER]
self._tts_engine = config.get(ATTR_ENTITY_ID)
self._config = config
self._sync_group = []
_, self._tts_service = split_entity_id(config[CONF_TTS_SERVICE])
Expand Down Expand Up @@ -516,7 +517,18 @@ def audio_alert(self):

# Play message
if self._message:
service_data = {'entity_id': self._media_player, 'message': self._message}
if 'speak' in self._tts_service:
service_data = {
'entity_id': self._tts_engine,
'media_player_entity_id': self._media_player,
'message': self._message,
}
else:
service_data = {
ATTR_ENTITY_ID: self._media_player,
'message': self._message,
}

self._hass.services.call('tts', self._tts_service, service_data)
time.sleep(self._pause)
self.wait_on_idle()
2 changes: 1 addition & 1 deletion custom_components/lms_tts_notify/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@
"issue_tracker": "https://github.com/floris-b/lms_tts_notify/issues",
"after_dependencies": ["media_player", "squuezebox"],
"iot_class": "local_push",
"version": "0.3.14"
"version": "0.3.15"
}
21 changes: 12 additions & 9 deletions custom_components/lms_tts_notify/notify.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,18 @@
from homeassistant.const import ATTR_ENTITY_ID
from homeassistant.components.notify import ATTR_MESSAGE

DOMAIN = "lms_tts_notify"
ATTR_LANGUAGE = "language"
from . import (
DOMAIN,
CONF_MEDIA_PLAYER,
CONF_TTS_SERVICE,
CONF_REPEAT,
CONF_VOLUME,
CONF_ALERT_SOUND,
CONF_DEVICE_GROUP,
CONF_PAUSE,
)

CONF_MEDIA_PLAYER = "media_player"
CONF_TTS_SERVICE = "tts_service"
CONF_REPEAT = "repeat"
CONF_VOLUME = "volume"
CONF_ALERT_SOUND = "alert_sound"
CONF_DEVICE_GROUP = "device_group"
CONF_PAUSE = "pause"
ATTR_LANGUAGE = "language"

_LOGGER = logging.getLogger(__name__)

Expand All @@ -32,6 +34,7 @@
vol.Required(CONF_TTS_SERVICE): cv.entity_id,
vol.Required(CONF_MEDIA_PLAYER): cv.entity_id,
vol.Required(CONF_DEVICE_GROUP): cv.entity_id,
vol.Optional(ATTR_ENTITY_ID): cv.entity_id,
vol.Optional(ATTR_LANGUAGE): cv.string,
vol.Optional(CONF_REPEAT, default=1): cv.positive_int,
vol.Optional(CONF_ALERT_SOUND, default=""): cv.string,
Expand Down
5 changes: 5 additions & 0 deletions info.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ notify:
Please note that the `tts_service` parameter, must match the `service_name` defined in the TTS integration.

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`

### CONFIGURATION VARIABLES & SERVICE OPTIONS
___

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

#### **entity_id**: `string` | (optional) | CONFIG
The entity_id of the TTS engine (for TTS service "tts.speak" only)

#### **volume**: `float` (optional) | CONFIG & SERVICE QUEUE & SERVICE NOTIFY
Default volume to play the alert_sound and message

Expand Down

0 comments on commit f677e6e

Please sign in to comment.