Skip to content

Commit 21c2793

Browse files
author
Stephan van Rooij
committed
fix: Text-to-speech on all speakers
1 parent 9b72824 commit 21c2793

File tree

5 files changed

+34
-16
lines changed

5 files changed

+34
-16
lines changed

docs/control/2-playback.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,4 +237,3 @@ Topic: `sonos/uuid_of_player/control`
237237
"command": "switchtotv"
238238
}
239239
```
240-

docs/control/5-notifications-and-tts.md

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ Payload:
3333
}
3434
```
3535

36+
### Play notification on all speakers
37+
3638
You can also have a notification play on all groups (all devices that coordinate themself), just send the following message to `sonos/cmd/notify`.
3739

3840
```json
@@ -59,7 +61,7 @@ More information about [notifications](https://svrooij.github.io/node-sonos-ts/s
5961

6062
## Text to speech
6163

62-
[![Support me on Github][badge_sponsor]][link_sponsor]
64+
<iframe src="https://github.com/sponsors/svrooij/button" title="Sponsor svrooij" height="35" width="107" style="border: 0;"></iframe>
6365

6466
You can have your sonos speaker prononce some notification text, which is a pretty cool feature. But you'll need some extra work. You'll need a text-to-speech endpoint as described [here](https://svrooij.github.io/node-sonos-ts/sonos-device/notifications-and-tts.html#text-to-speech). You have two options either host your own [server][link_polly_tts] or become a [sponsor][link_sponsor] and get access to my personal hosted TTS server.
6567

@@ -70,7 +72,7 @@ Either way you will have a TTS endpoint at hand. You can set it in the configura
7072
|Default language|`en-US`|`SONOS_TTS_LANG`|`--ttslang`|
7173
|Default endpoint|`http://some-server.domain.com/api/generate`|`SONOS_TTS_ENDPOINT`|`--ttsendpoint`|
7274

73-
Have a speaker speak by sending the following to `sonos/uuid_of_speaker/control`. Endpoint is optional (if set in environment), lang is options if set in config, gender, volume & onlyWhenPlaying are always optional.
75+
Have a speaker speak by sending the following to `sonos/uuid_of_speaker/control`. Endpoint is optional (if set in environment), lang is options if set in config, `gender`, `name`, `volume` & `onlyWhenPlaying` are always optional.
7476

7577
```json
7678
{
@@ -80,13 +82,31 @@ Have a speaker speak by sending the following to `sonos/uuid_of_speaker/control`
8082
"endpoint": "https://your.tts.endpoint/api/generate",
8183
"lang": "en-US",
8284
"gender": "male",
85+
"name": "Salli",
8386
"volume": 50,
8487
"onlyWhenPlaying": false,
8588
"delayMs": 700
8689
}
8790
}
8891
```
8992

93+
### Text to speech on all speakers
94+
95+
Send this payload to `sonos/cmd/speak` to play it on all groups. Same parameters as above.
96+
97+
```json
98+
{
99+
"text": "Someone at the front-door",
100+
"endpoint": "https://your.tts.endpoint/api/generate",
101+
"lang": "en-US",
102+
"gender": "male",
103+
"name": "Salli",
104+
"volume": 50,
105+
"onlyWhenPlaying": false,
106+
"delayMs": 700
107+
}
108+
```
109+
90110
### Text to speech explained
91111

92112
The text-to-speech method executes the following:

package-lock.json

Lines changed: 8 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
"test": "eslint ./src/*.ts"
2222
},
2323
"dependencies": {
24-
"@svrooij/sonos": "^2.0.8",
24+
"@svrooij/sonos": "^2.0.9",
2525
"mqtt": "3.0.0",
2626
"serilogger": "^0.3.1",
2727
"strict-event-emitter-types": "^2.0.0",

src/sonos-to-mqtt.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,9 @@ export class SonosToMqtt {
6363
this.log.debug('Got generic command {command} from mqtt', command)
6464
switch (command) {
6565
case 'notify':
66-
return Promise.all(this.sonosManager.Devices
67-
.filter(d => d.Coordinator.Uuid === d.Uuid)
68-
.map(d => d.PlayNotification(payload))
69-
)
66+
return this.sonosManager.PlayNotification(payload);
67+
case 'speak':
68+
return this.sonosManager.PlayTTS(payload);
7069
case 'pauseall':
7170
return Promise.all(this.sonosManager.Devices.map(d => d.Pause()));
7271
case 'listalarm':

0 commit comments

Comments
 (0)