Skip to content

Commit 167cafe

Browse files
authored
Merge pull request #19 from svxa/chime_tts
Add support for ChimeTTS
2 parents f677e6e + 4a4e497 commit 167cafe

File tree

4 files changed

+260
-3
lines changed

4 files changed

+260
-3
lines changed

README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,24 @@ Default value to repeat the message
7575
#### **force_play**: `boolean` | SERVICE QUEUE & SERVICE NOTIFY
7676
Skip check `device_group` state is `home`
7777

78+
#### **chimetts_chime_path**: `string` | CONFIG & SERVICE QUEUE & SERVICE NOTIFY
79+
A preset or custom audio file to be played before TTS audio. [ChimeTTS](https://github.com/nimroddolev/chime_tts) option.
80+
81+
#### **chimetts_end_chime_path**: `string` | CONFIG & SERVICE QUEUE & SERVICE NOTIFY
82+
A preset or custom audio file to be played after TTS audio. [ChimeTTS](https://github.com/nimroddolev/chime_tts) option.
83+
84+
#### **chimetts_offset**: `float` | CONFIG & SERVICE QUEUE & SERVICE NOTIFY
85+
Delay between audio segments when value > 0, or overlays audio segments when value < 0. [ChimeTTS](https://github.com/nimroddolev/chime_tts) option.
86+
87+
#### **chimetts_final_delay**: `float` | CONFIG & SERVICE QUEUE & SERVICE NOTIFY
88+
Delay (in milliseconds) added to the end of the audio. [ChimeTTS](https://github.com/nimroddolev/chime_tts) option.
89+
90+
#### **chimetts_tts_speed**: `float` | CONFIG & SERVICE QUEUE & SERVICE NOTIFY
91+
Speed of the TTS audio. [ChimeTTS](https://github.com/nimroddolev/chime_tts) option.
92+
93+
#### **chimetts_tts_pitch**: `float` | CONFIG & SERVICE QUEUE & SERVICE NOTIFY
94+
TTS pitch in semitones. [ChimeTTS](https://github.com/nimroddolev/chime_tts) option.
95+
7896
### SERVICE QUEUE
7997
---
8098
A service `lms_tts_notify.queue` is also added (besides the notify service for each player) for easy use with the automations gui

custom_components/lms_tts_notify/__init__.py

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,14 @@
2525
CONF_DEVICE_GROUP = 'device_group'
2626
CONF_PAUSE = 'pause'
2727

28+
# ChimeTTS options
29+
CONF_CHIMETTS_OPTION_CHIME_PATH = 'chimetts_chime_path'
30+
CONF_CHIMETTS_OPTION_END_CHIME_PATH = 'chimetts_end_chime_path'
31+
CONF_CHIMETTS_OPTION_OFFSET = 'chimetts_offset'
32+
CONF_CHIMETTS_FINAL_DELAY = 'chimetts_final_delay'
33+
CONF_CHIMETTS_TTS_SPEED = 'chimetts_tts_speed'
34+
CONF_CHIMETTS_TTS_PITCH = 'chimetts_tts_pitch'
35+
2836
ATTR_SYNC_GROUP = 'sync_group'
2937
ATTR_VOLUME = 'volume_level'
3038
ATTR_POSITION = 'media_position'
@@ -41,6 +49,12 @@
4149
vol.Optional(CONF_FORCE_PLAY): cv.boolean,
4250
vol.Optional(CONF_DEVICE_GROUP): cv.entity_id,
4351
vol.Optional(CONF_PAUSE): cv.positive_float,
52+
vol.Optional(CONF_CHIMETTS_OPTION_CHIME_PATH): cv.string,
53+
vol.Optional(CONF_CHIMETTS_OPTION_END_CHIME_PATH): cv.string,
54+
vol.Optional(CONF_CHIMETTS_OPTION_OFFSET): vol.All(vol.Coerce(int), vol.Range(min=-10000, max=10000)),
55+
vol.Optional(CONF_CHIMETTS_FINAL_DELAY): cv.positive_int,
56+
vol.Optional(CONF_CHIMETTS_TTS_SPEED): vol.All(vol.Coerce(int), vol.Range(min=1, max=500)),
57+
vol.Optional(CONF_CHIMETTS_TTS_PITCH): vol.All(vol.Coerce(int), vol.Range(min=-100, max=100)),
4458
}
4559
)
4660

@@ -397,14 +411,21 @@ def __init__(self, hass, config):
397411
self._tts_engine = config.get(ATTR_ENTITY_ID)
398412
self._config = config
399413
self._sync_group = []
400-
_, self._tts_service = split_entity_id(config[CONF_TTS_SERVICE])
414+
self._tts_group, self._tts_service = split_entity_id(config[CONF_TTS_SERVICE])
401415
_, name = split_entity_id(self._media_player)
402416
self._name = name + '_queue'
403417
self.skip_save = False
404418
self.force_play = False
405419
self.status = 'idle'
406420
self._message = ''
407421
self._device_group = ''
422+
self._chimetts_option_chime_path = config.get(CONF_CHIMETTS_OPTION_CHIME_PATH)
423+
self._chimetts_option_end_chime_path = config.get(CONF_CHIMETTS_OPTION_END_CHIME_PATH)
424+
self._chimetts_option_offset = config.get(CONF_CHIMETTS_OPTION_OFFSET)
425+
self._chimetts_final_delay = config.get(CONF_CHIMETTS_FINAL_DELAY)
426+
self._chimetts_tts_speed = config.get(CONF_CHIMETTS_TTS_SPEED)
427+
self._chimetts_tts_pitch = config.get(CONF_CHIMETTS_TTS_PITCH)
428+
408429

409430
def run(self):
410431
'''Listen to queue events, and play them to mediaplayer'''
@@ -425,6 +446,15 @@ def run(self):
425446
)
426447
self.force_play = event.get(CONF_FORCE_PLAY, False)
427448

449+
self._chimetts_options = {
450+
'chime_path': event.get(CONF_CHIMETTS_OPTION_CHIME_PATH, self._chimetts_option_chime_path),
451+
'end_chime_path': event.get(CONF_CHIMETTS_OPTION_END_CHIME_PATH, self._chimetts_option_end_chime_path),
452+
'offset': event.get(CONF_CHIMETTS_OPTION_OFFSET, self._chimetts_option_offset),
453+
'final_delay': event.get(CONF_CHIMETTS_FINAL_DELAY, self._chimetts_final_delay),
454+
'tts_speed': event.get(CONF_CHIMETTS_TTS_SPEED, self._chimetts_tts_speed),
455+
'tts_pitch': event.get(CONF_CHIMETTS_TTS_PITCH, self._chimetts_tts_pitch),
456+
}
457+
428458
home = self._hass.states.get(self._device_group)
429459
if not home or home.state == 'home' or self.force_play:
430460
self.audio_alert()
@@ -523,12 +553,24 @@ def audio_alert(self):
523553
'media_player_entity_id': self._media_player,
524554
'message': self._message,
525555
}
556+
elif 'chime_tts' in self._tts_group:
557+
558+
_chimetts_options = {k: v for k, v in self._chimetts_options.items() if v is not None}
559+
_LOGGER.debug('ChimeTTS options: %s', _chimetts_options)
560+
561+
service_data = {
562+
'tts_platform': self._tts_engine,
563+
'entity_id': self._media_player,
564+
'message': self._message,
565+
**_chimetts_options,
566+
}
526567
else:
527568
service_data = {
528569
ATTR_ENTITY_ID: self._media_player,
529570
'message': self._message,
530571
}
531572

532-
self._hass.services.call('tts', self._tts_service, service_data)
573+
_LOGGER.debug('Playing message on %s.%s', self._tts_group, self._tts_service)
574+
self._hass.services.call(self._tts_group, self._tts_service, service_data)
533575
time.sleep(self._pause)
534576
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.15"
10+
"version": "0.3.16"
1111
}

custom_components/lms_tts_notify/services.yaml

Lines changed: 197 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,200 @@ queue:
4949
description: Specify which group/enity to track and only play when home
5050
selector:
5151
entity:
52+
53+
chimetts_chime_path:
54+
name: "Chime TTS: Chime Path"
55+
description: "A preset or custom audio file to be played before TTS audio"
56+
example: "custom_components/chime_tts/mp3s/bells.mp3"
57+
required: false
58+
selector:
59+
select:
60+
translation_key: "chime_paths"
61+
multiple: false
62+
custom_value: true
63+
mode: dropdown
64+
options:
65+
- label: "Ba-Dum Tss!"
66+
value: "ba_dum_tss"
67+
- label: "Bells"
68+
value: "bells"
69+
- label: "Bells 2"
70+
value: "bells_2"
71+
- label: "Bright"
72+
value: "bright"
73+
- label: "Chirp"
74+
value: "chirp"
75+
- label: "Choir"
76+
value: "choir"
77+
- label: "Chord"
78+
value: "chord"
79+
- label: "Classical"
80+
value: "classical"
81+
- label: "Crickets"
82+
value: "crickets"
83+
- label: "Ding Dong"
84+
value: "ding_dong"
85+
- label: "Drum Roll"
86+
value: "drumroll"
87+
- label: "Dun dun DUUUN!"
88+
value: "dun_dun_dun"
89+
- label: "Error"
90+
value: "error"
91+
- label: "Fanfare"
92+
value: "fanfare"
93+
- label: "Glockenspiel"
94+
value: "glockenspiel"
95+
- label: "Hail"
96+
value: "hail"
97+
- label: "Knock"
98+
value: "knock"
99+
- label: "Marimba"
100+
value: "marimba"
101+
- label: "Mario Coin"
102+
value: "mario_coin"
103+
- label: "Microphone Tap"
104+
value: "microphone_tap"
105+
- label: "Ta-da!"
106+
value: "tada"
107+
- label: "Toast"
108+
value: "toast"
109+
- label: "Twenty Four"
110+
value: "twenty_four"
111+
- label: "Sad Trombone"
112+
value: "sad_trombone"
113+
- label: "Soft"
114+
value: "soft"
115+
- label: "Whistle"
116+
value: "whistle"
117+
- label: "Custom 1"
118+
value: "custom_chime_path_1"
119+
- label: "Custom 2"
120+
value: "custom_chime_path_2"
121+
- label: "Custom 3"
122+
value: "custom_chime_path_3"
123+
- label: "Custom 4"
124+
value: "custom_chime_path_4"
125+
- label: "Custom 5"
126+
value: "custom_chime_path_5"
127+
chimetts_end_chime_path:
128+
name: "Chime TTS: End Chime Path"
129+
description: "A preset or custom audio file to be played after TTS audio"
130+
example: "custom_components/chime_tts/mp3s/tada.mp3"
131+
required: false
132+
selector:
133+
select:
134+
translation_key: "chime_paths"
135+
multiple: false
136+
custom_value: true
137+
mode: dropdown
138+
options:
139+
- label: "Ba-Dum Tss!"
140+
value: "ba_dum_tss"
141+
- label: "Bells"
142+
value: "bells"
143+
- label: "Bells 2"
144+
value: "bells_2"
145+
- label: "Bright"
146+
value: "bright"
147+
- label: "Chirp"
148+
value: "chirp"
149+
- label: "Choir"
150+
value: "choir"
151+
- label: "Chord"
152+
value: "chord"
153+
- label: "Classical"
154+
value: "classical"
155+
- label: "Crickets"
156+
value: "crickets"
157+
- label: "Ding Dong"
158+
value: "ding_dong"
159+
- label: "Drum Roll"
160+
value: "drumroll"
161+
- label: "Dun dun DUUUN!"
162+
value: "dun_dun_dun"
163+
- label: "Error"
164+
value: "error"
165+
- label: "Fanfare"
166+
value: "fanfare"
167+
- label: "Glockenspiel"
168+
value: "glockenspiel"
169+
- label: "Hail"
170+
value: "hail"
171+
- label: "Knock"
172+
value: "knock"
173+
- label: "Marimba"
174+
value: "marimba"
175+
- label: "Mario Coin"
176+
value: "mario_coin"
177+
- label: "Microphone Tap"
178+
value: "microphone_tap"
179+
- label: "Ta-da!"
180+
value: "tada"
181+
- label: "Toast"
182+
value: "toast"
183+
- label: "Twenty Four"
184+
value: "twenty_four"
185+
- label: "Sad Trombone"
186+
value: "sad_trombone"
187+
- label: "Soft"
188+
value: "soft"
189+
- label: "Whistle"
190+
value: "whistle"
191+
- label: "Custom 1"
192+
value: "custom_chime_path_1"
193+
- label: "Custom 2"
194+
value: "custom_chime_path_2"
195+
- label: "Custom 3"
196+
value: "custom_chime_path_3"
197+
- label: "Custom 4"
198+
value: "custom_chime_path_4"
199+
- label: "Custom 5"
200+
value: "custom_chime_path_5"
201+
chimetts_offset:
202+
name: "Chime TTS: Offset"
203+
description: "Adds a delay between audio segments when value > 0, or overlays audio segments when value < 0."
204+
example: 450
205+
required: false
206+
selector:
207+
number:
208+
mode: box
209+
min: -10000
210+
max: 10000
211+
step: 10
212+
unit_of_measurement: ms
213+
chimetts_final_delay:
214+
name: "Chime TTS: Final Delay"
215+
description: "Final delay (in milliseconds) added to the end of the audio"
216+
example: 100
217+
required: false
218+
selector:
219+
number:
220+
mode: box
221+
min: 0
222+
max: 10000
223+
step: 1
224+
unit_of_measurement: ms
225+
chimetts_tts_speed:
226+
name: "Chime TTS: TTS Speed"
227+
description: "Set the speed of the TTS audio to between 1% and 500% of the original"
228+
example: 125
229+
required: false
230+
selector:
231+
number:
232+
mode: slider
233+
min: 1
234+
max: 500
235+
step: 5
236+
unit_of_measurement: '%'
237+
chimetts_tts_pitch:
238+
name: "Chime TTS: TTS Pitch"
239+
description: "Change the the TTS pitch in semitones. Negative values for lower, positive for higher"
240+
example: 3
241+
required: false
242+
selector:
243+
number:
244+
mode: slider
245+
min: -100
246+
max: 100
247+
step: 1
248+
unit_of_measurement: 'semitones'

0 commit comments

Comments
 (0)