iobroker.sayit 2.1.0 → 2.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -1
- package/admin/i18n/de/translations.json +2 -1
- package/admin/i18n/en/translations.json +2 -1
- package/admin/i18n/es/translations.json +2 -1
- package/admin/i18n/fr/translations.json +2 -1
- package/admin/i18n/it/translations.json +2 -1
- package/admin/i18n/nl/translations.json +2 -1
- package/admin/i18n/pl/translations.json +2 -1
- package/admin/i18n/pt/translations.json +2 -1
- package/admin/i18n/ru/translations.json +2 -1
- package/admin/i18n/uk/translations.json +2 -1
- package/admin/i18n/zh-cn/translations.json +2 -1
- package/admin/jsonConfig.json +11 -1
- package/io-package.json +15 -14
- package/lib/speech2device.js +111 -74
- package/lib/text2speech.js +53 -37
- package/main.js +87 -36
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -265,7 +265,10 @@ Following values for engines are possible:
|
|
|
265
265
|
### **WORK IN PROGRESS**
|
|
266
266
|
-->
|
|
267
267
|
## Changelog
|
|
268
|
-
### 2.1.
|
|
268
|
+
### 2.1.2 (2023-03-27)
|
|
269
|
+
* (bluefox) Corrected engines with web-link
|
|
270
|
+
|
|
271
|
+
### 2.1.1 (2023-03-24)
|
|
269
272
|
* (Jey-Cee) Added support for Coqui TTS
|
|
270
273
|
* (bluefox) Renamed all configuration attributes
|
|
271
274
|
|
|
@@ -49,5 +49,6 @@
|
|
|
49
49
|
"Engine": "TTS-Engine",
|
|
50
50
|
"Cache generated files": "Generierte Dateien zwischenspeichern",
|
|
51
51
|
"Google home server": "Google-Heimserver",
|
|
52
|
-
"in % to playing volume": "in % zur Spiellautstärke"
|
|
52
|
+
"in % to playing volume": "in % zur Spiellautstärke",
|
|
53
|
+
"optional - If player does not work": "optional - Wenn der Player nicht funktioniert"
|
|
53
54
|
}
|
|
@@ -49,5 +49,6 @@
|
|
|
49
49
|
"Engine": "TTS Engine",
|
|
50
50
|
"Cache generated files": "Cache generated files",
|
|
51
51
|
"Google home server": "Google home server",
|
|
52
|
-
"in % to playing volume": "in % to playing volume"
|
|
52
|
+
"in % to playing volume": "in % to playing volume",
|
|
53
|
+
"optional - If player does not work": "optional - If player does not work"
|
|
53
54
|
}
|
|
@@ -49,5 +49,6 @@
|
|
|
49
49
|
"Engine": "Motor de TTS",
|
|
50
50
|
"Cache generated files": "Caché de archivos generados",
|
|
51
51
|
"Google home server": "servidor principal de Google",
|
|
52
|
-
"in % to playing volume": "en % al volumen de reproducción"
|
|
52
|
+
"in % to playing volume": "en % al volumen de reproducción",
|
|
53
|
+
"optional - If player does not work": "opcional: si el reproductor no funciona"
|
|
53
54
|
}
|
|
@@ -49,5 +49,6 @@
|
|
|
49
49
|
"Engine": "Moteur TTS",
|
|
50
50
|
"Cache generated files": "Fichiers générés par le cache",
|
|
51
51
|
"Google home server": "Serveur domestique Google",
|
|
52
|
-
"in % to playing volume": "en % du volume de lecture"
|
|
52
|
+
"in % to playing volume": "en % du volume de lecture",
|
|
53
|
+
"optional - If player does not work": "facultatif - Si le lecteur ne fonctionne pas"
|
|
53
54
|
}
|
|
@@ -49,5 +49,6 @@
|
|
|
49
49
|
"Engine": "Motore di sintesi vocale",
|
|
50
50
|
"Cache generated files": "File generati nella cache",
|
|
51
51
|
"Google home server": "Server domestico di Google",
|
|
52
|
-
"in % to playing volume": "in % al volume di riproduzione"
|
|
52
|
+
"in % to playing volume": "in % al volume di riproduzione",
|
|
53
|
+
"optional - If player does not work": "opzionale - Se il lettore non funziona"
|
|
53
54
|
}
|
|
@@ -49,5 +49,6 @@
|
|
|
49
49
|
"Engine": "TTS-motor",
|
|
50
50
|
"Cache generated files": "Cache-gegenereerde bestanden",
|
|
51
51
|
"Google home server": "Google-thuisserver",
|
|
52
|
-
"in % to playing volume": "in % van het speelvolume"
|
|
52
|
+
"in % to playing volume": "in % van het speelvolume",
|
|
53
|
+
"optional - If player does not work": "optioneel - Als de speler niet werkt"
|
|
53
54
|
}
|
|
@@ -49,5 +49,6 @@
|
|
|
49
49
|
"Engine": "Silnik TTS",
|
|
50
50
|
"Cache generated files": "Pliki generowane w pamięci podręcznej",
|
|
51
51
|
"Google home server": "Domowy serwer Google",
|
|
52
|
-
"in % to playing volume": "w % do głośności odtwarzania"
|
|
52
|
+
"in % to playing volume": "w % do głośności odtwarzania",
|
|
53
|
+
"optional - If player does not work": "opcjonalne - Jeśli odtwarzacz nie działa"
|
|
53
54
|
}
|
|
@@ -49,5 +49,6 @@
|
|
|
49
49
|
"Engine": "Motor TTS",
|
|
50
50
|
"Cache generated files": "Arquivos gerados em cache",
|
|
51
51
|
"Google home server": "servidor doméstico do Google",
|
|
52
|
-
"in % to playing volume": "em % para tocar o volume"
|
|
52
|
+
"in % to playing volume": "em % para tocar o volume",
|
|
53
|
+
"optional - If player does not work": "opcional - Se o reprodutor não funcionar"
|
|
53
54
|
}
|
|
@@ -49,5 +49,6 @@
|
|
|
49
49
|
"Engine": "Движок TTS",
|
|
50
50
|
"Cache generated files": "Кэшировать сгенерированные файлы",
|
|
51
51
|
"Google home server": "домашний сервер гугл",
|
|
52
|
-
"in % to playing volume": "в % к громкости воспроизведения"
|
|
52
|
+
"in % to playing volume": "в % к громкости воспроизведения",
|
|
53
|
+
"optional - If player does not work": "необязательно - Если плеер не работает"
|
|
53
54
|
}
|
|
@@ -49,5 +49,6 @@
|
|
|
49
49
|
"Engine": "Двигун TTS",
|
|
50
50
|
"Cache generated files": "Кешувати згенеровані файли",
|
|
51
51
|
"Google home server": "Домашній сервер Google",
|
|
52
|
-
"in % to playing volume": "у % до гучності відтворення"
|
|
52
|
+
"in % to playing volume": "у % до гучності відтворення",
|
|
53
|
+
"optional - If player does not work": "необов'язково - якщо плеєр не працює"
|
|
53
54
|
}
|
package/admin/jsonConfig.json
CHANGED
|
@@ -57,15 +57,16 @@
|
|
|
57
57
|
"lg": 4
|
|
58
58
|
},
|
|
59
59
|
"systemCommand": {
|
|
60
|
+
"newLine": true,
|
|
60
61
|
"type": "text",
|
|
61
62
|
"label": "System command",
|
|
62
63
|
"hidden": "data.type !== 'system'",
|
|
64
|
+
"help": "optional - If player does not work",
|
|
63
65
|
"sm": 6,
|
|
64
66
|
"md": 4,
|
|
65
67
|
"lg": 2
|
|
66
68
|
},
|
|
67
69
|
"systemPlayer": {
|
|
68
|
-
"newLine": true,
|
|
69
70
|
"type": "select",
|
|
70
71
|
"label": "Linux player",
|
|
71
72
|
"hidden": "data.type !== 'system' || data.command",
|
|
@@ -264,6 +265,15 @@
|
|
|
264
265
|
"sm": 6,
|
|
265
266
|
"md": 4,
|
|
266
267
|
"lg": 2
|
|
268
|
+
},
|
|
269
|
+
"_test": {
|
|
270
|
+
"newLine": true,
|
|
271
|
+
"variant": "contained",
|
|
272
|
+
"type": "sendTo",
|
|
273
|
+
"label": "Test",
|
|
274
|
+
"command": "test",
|
|
275
|
+
"jsonData": "${JSON.stringify(data)}",
|
|
276
|
+
"icon": "send"
|
|
267
277
|
}
|
|
268
278
|
}
|
|
269
279
|
},
|
package/io-package.json
CHANGED
|
@@ -1,9 +1,22 @@
|
|
|
1
1
|
{
|
|
2
2
|
"common": {
|
|
3
3
|
"name": "sayit",
|
|
4
|
-
"version": "2.1.
|
|
4
|
+
"version": "2.1.2",
|
|
5
5
|
"news": {
|
|
6
|
-
"2.1.
|
|
6
|
+
"2.1.2": {
|
|
7
|
+
"en": "Corrected engines with web-link",
|
|
8
|
+
"de": "Korrigierte Motoren mit Weblink",
|
|
9
|
+
"ru": "Правильные двигатели с web-ссылка",
|
|
10
|
+
"pt": "Motores corrigidos com web-link",
|
|
11
|
+
"nl": "Vertaling:",
|
|
12
|
+
"fr": "Moteurs corrigés avec web-link",
|
|
13
|
+
"it": "Motori corretti con web-link",
|
|
14
|
+
"es": "Motores corregidos con enlace web",
|
|
15
|
+
"pl": "Poprawione silniki z linkami stron internetowych",
|
|
16
|
+
"uk": "Виправлені двигуни з веб-посиланням",
|
|
17
|
+
"zh-cn": "连接网络的工程师"
|
|
18
|
+
},
|
|
19
|
+
"2.1.1": {
|
|
7
20
|
"en": "Added support for Coqui TTS\nRenamed all configuration attributes",
|
|
8
21
|
"de": "Unterstützung für Coqui TTS\nAlle Konfigurationsattribute umbenannt",
|
|
9
22
|
"ru": "Добавлена поддержка Coqui TTS\nПереименованные все атрибуты конфигурации",
|
|
@@ -77,18 +90,6 @@
|
|
|
77
90
|
"es": "Se corrigieron errores en io-package.json",
|
|
78
91
|
"pl": "Naprawiono błędy w io-package.json",
|
|
79
92
|
"zh-cn": "修复了 io-package.json 中的错误"
|
|
80
|
-
},
|
|
81
|
-
"1.12.3": {
|
|
82
|
-
"en": "corrected the google engine\nAdded new voices: german, korean, brasil, Dutch",
|
|
83
|
-
"de": "die Google-Engine korrigiert\nNeue Stimmen hinzugefügt: Deutsch, Koreanisch, Brasil, Niederländisch",
|
|
84
|
-
"ru": "исправил движок гугл\nДобавлены новые голоса: немецкий, корейский, бразильский, голландский.",
|
|
85
|
-
"pt": "corrigiu o motor do google\nAdicionadas novas vozes: alemão, coreano, brasil, holandês",
|
|
86
|
-
"nl": "de google engine gecorrigeerd correct\nNieuwe stemmen toegevoegd: Duits, Koreaans, Brazilië, Nederlands",
|
|
87
|
-
"fr": "corrigé le moteur google\nAjout de nouvelles voix : allemand, coréen, brésilien, néerlandais",
|
|
88
|
-
"it": "corretto il motore di Google\nAggiunte nuove voci: tedesco, coreano, brasiliano, olandese",
|
|
89
|
-
"es": "corrigió el motor de google\nAñadidas nuevas voces: alemán, coreano, brasil, holandés",
|
|
90
|
-
"pl": "poprawiłem silnik google\nDodano nowe głosy: niemiecki, koreański, brazylijski, holenderski",
|
|
91
|
-
"zh-cn": "更正了谷歌引擎\n添加了新的声音:德语、韩语、巴西语、荷兰语"
|
|
92
93
|
}
|
|
93
94
|
},
|
|
94
95
|
"title": "Text to speech",
|
package/lib/speech2device.js
CHANGED
|
@@ -106,29 +106,49 @@ class Speech2Device {
|
|
|
106
106
|
return false;
|
|
107
107
|
}
|
|
108
108
|
|
|
109
|
-
async sayItBrowser(text, language, volume, duration) {
|
|
109
|
+
async sayItBrowser(text, language, volume, duration, testOptions) {
|
|
110
110
|
const result = await this.uploadToStates(text);
|
|
111
111
|
|
|
112
|
-
|
|
112
|
+
const browserInstance = (testOptions && testOptions.browserInstance) || this.adapter.config.browserInstance;
|
|
113
|
+
|
|
114
|
+
await this.adapter.setForeignStateAsync('vis.0.control.instance', browserInstance);
|
|
113
115
|
await this.adapter.setForeignStateAsync('vis.0.control.data', result.fileInDB);
|
|
114
116
|
await this.adapter.setForeignStateAsync('vis.0.control.command', 'playSound');
|
|
115
117
|
|
|
116
118
|
return duration;
|
|
117
119
|
}
|
|
118
120
|
|
|
119
|
-
async
|
|
121
|
+
async getWebLink(testOptions) {
|
|
122
|
+
if (testOptions) {
|
|
123
|
+
const webServer = (testOptions && testOptions.webServer) || this.adapter.config.webServer;
|
|
124
|
+
const webInstance = (testOptions && testOptions.webInstance) || this.adapter.config.webInstance;
|
|
125
|
+
|
|
126
|
+
if (!this.options.webLink || webServer !== this.adapter.config.webServer || webInstance !== this.adapter.config.webInstance) {
|
|
127
|
+
const obj = await this.adapter.getForeignObjectAsync(`system.adapter.${testOptions.webInstance}`);
|
|
128
|
+
return this.options.getWebLink(obj, webServer, webInstance);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
return this.options.webLink;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
async sayItSonos(text, language, volume, duration, testOptions) {
|
|
120
136
|
volume = volume || this.options.sayLastVolume;
|
|
121
137
|
const result = await this.uploadToStates(text);
|
|
122
138
|
if (volume === 'null') {
|
|
123
139
|
volume = 0;
|
|
124
140
|
}
|
|
125
141
|
|
|
126
|
-
const
|
|
142
|
+
const webLink = await this.getWebLink(testOptions);
|
|
143
|
+
|
|
144
|
+
const fileName = `${volume ? `${volume};` : ''}${webLink}${result.fileInDB}`;
|
|
145
|
+
|
|
146
|
+
const sonosDevice = (testOptions && testOptions.sonosDevice) || this.adapter.config.sonosDevice;
|
|
127
147
|
|
|
128
|
-
if (
|
|
129
|
-
this.adapter.log.info(`Set "${
|
|
130
|
-
await this.adapter.setForeignStateAsync(`${
|
|
131
|
-
} else if (
|
|
148
|
+
if (sonosDevice && webLink) {
|
|
149
|
+
this.adapter.log.info(`Set "${sonosDevice}.tts: ${fileName}`);
|
|
150
|
+
await this.adapter.setForeignStateAsync(`${sonosDevice}.tts`, fileName);
|
|
151
|
+
} else if (webLink) {
|
|
132
152
|
this.adapter.log.info(`Send to sonos ${fileName}`);
|
|
133
153
|
this.adapter.sendTo('sonos', 'send', fileName);
|
|
134
154
|
} else {
|
|
@@ -138,7 +158,7 @@ class Speech2Device {
|
|
|
138
158
|
return duration;
|
|
139
159
|
}
|
|
140
160
|
|
|
141
|
-
async sayItHeos(text, language, volume, duration) {
|
|
161
|
+
async sayItHeos(text, language, volume, duration, testOptions) {
|
|
142
162
|
volume = volume || this.options.sayLastVolume;
|
|
143
163
|
|
|
144
164
|
const result = await this.uploadToStates(text);
|
|
@@ -146,13 +166,15 @@ class Speech2Device {
|
|
|
146
166
|
if (volume === 'null') {
|
|
147
167
|
volume = 0;
|
|
148
168
|
}
|
|
169
|
+
const webLink = await this.getWebLink(testOptions);
|
|
149
170
|
|
|
150
|
-
const fileName = `${volume ? `${volume};` : ''}${
|
|
171
|
+
const fileName = `${volume ? `${volume};` : ''}${webLink}${result.fileInDB}`;
|
|
172
|
+
const heosDevice = (testOptions && testOptions.heosDevice) || this.adapter.config.heosDevice;
|
|
151
173
|
|
|
152
|
-
if (
|
|
153
|
-
this.adapter.log.info(`Set "${
|
|
154
|
-
await this.adapter.setForeignStateAsync(`${
|
|
155
|
-
} else if (
|
|
174
|
+
if (heosDevice && webLink) {
|
|
175
|
+
this.adapter.log.info(`Set "${heosDevice}.tts: ${fileName}`);
|
|
176
|
+
await this.adapter.setForeignStateAsync(`${heosDevice}.tts`, fileName);
|
|
177
|
+
} else if (webLink) {
|
|
156
178
|
this.adapter.log.info(`Send to heos ${fileName}`);
|
|
157
179
|
this.adapter.sendTo('heos', 'send', fileName);
|
|
158
180
|
} else {
|
|
@@ -162,20 +184,22 @@ class Speech2Device {
|
|
|
162
184
|
return duration;
|
|
163
185
|
}
|
|
164
186
|
|
|
165
|
-
async sayItMpd(text, language, volume, duration) {
|
|
187
|
+
async sayItMpd(text, language, volume, duration, testOptions) {
|
|
166
188
|
volume = volume || this.options.sayLastVolume;
|
|
167
189
|
|
|
168
190
|
const result = await this.uploadToStates(text);
|
|
169
191
|
if (volume === 'null' || volume === 'undefined') {
|
|
170
192
|
volume = 0;
|
|
171
193
|
}
|
|
194
|
+
const webLink = await this.getWebLink(testOptions);
|
|
195
|
+
const mpdInstance = (testOptions && testOptions.mpdInstance) || this.adapter.config.mpdInstance;
|
|
172
196
|
|
|
173
|
-
const fileName = `${volume ? `${volume};` : ''}${
|
|
197
|
+
const fileName = `${volume ? `${volume};` : ''}${webLink}${result.fileInDB}`;
|
|
174
198
|
|
|
175
|
-
if (
|
|
176
|
-
this.adapter.log.info(`Set "${
|
|
177
|
-
await this.adapter.setForeignStateAsync(`${
|
|
178
|
-
} else if (
|
|
199
|
+
if (mpdInstance && webLink) {
|
|
200
|
+
this.adapter.log.info(`Set "${mpdInstance}.say: ${fileName}`);
|
|
201
|
+
await this.adapter.setForeignStateAsync(`${mpdInstance}.say`, fileName);
|
|
202
|
+
} else if (webLink) {
|
|
179
203
|
this.adapter.log.info(`Send to MPD ${fileName}`);
|
|
180
204
|
this.adapter.sendTo('mpd', 'say', fileName);
|
|
181
205
|
} else {
|
|
@@ -185,7 +209,7 @@ class Speech2Device {
|
|
|
185
209
|
return duration;
|
|
186
210
|
}
|
|
187
211
|
|
|
188
|
-
async sayItChromecast(text, language, volume, duration) {
|
|
212
|
+
async sayItChromecast(text, language, volume, duration, testOptions) {
|
|
189
213
|
volume = volume || this.options.sayLastVolume;
|
|
190
214
|
|
|
191
215
|
const result = await this.uploadToStates(text);
|
|
@@ -193,18 +217,20 @@ class Speech2Device {
|
|
|
193
217
|
if (volume === 'null') {
|
|
194
218
|
volume = 0;
|
|
195
219
|
}
|
|
220
|
+
const webLink = await this.getWebLink(testOptions);
|
|
221
|
+
const chromecastDevice = (testOptions && testOptions.chromecastDevice) || this.adapter.config.chromecastDevice;
|
|
196
222
|
|
|
197
223
|
//Create announcement JSON
|
|
198
224
|
const announcement = {
|
|
199
|
-
url: `${
|
|
225
|
+
url: `${webLink}${result.fileInDB}`,
|
|
200
226
|
};
|
|
201
227
|
if (volume) {
|
|
202
228
|
announcement.volume = volume;
|
|
203
229
|
}
|
|
204
230
|
const announcementJSON = JSON.stringify(announcement);
|
|
205
231
|
|
|
206
|
-
if (
|
|
207
|
-
const chromecastAnnouncementDev = `${
|
|
232
|
+
if (chromecastDevice && webLink) {
|
|
233
|
+
const chromecastAnnouncementDev = `${chromecastDevice}.player.announcement`;
|
|
208
234
|
this.adapter.log.info(`Set "${chromecastAnnouncementDev} to ${announcementJSON}`);
|
|
209
235
|
await this.adapter.setForeignStateAsync(chromecastAnnouncementDev, announcementJSON);
|
|
210
236
|
// Check every 500 ms if the announcement has finished playing
|
|
@@ -296,7 +322,7 @@ class Speech2Device {
|
|
|
296
322
|
});
|
|
297
323
|
}
|
|
298
324
|
|
|
299
|
-
async sayItGoogleHome(text, language, volume, duration) {
|
|
325
|
+
async sayItGoogleHome(text, language, volume, duration, testOptions) {
|
|
300
326
|
if (!this.GHClient) {
|
|
301
327
|
const {Client, DefaultMediaReceiver} = require('castv2-client');
|
|
302
328
|
this.GHClient = Client;
|
|
@@ -308,12 +334,14 @@ class Speech2Device {
|
|
|
308
334
|
if (volume === 'null' || volume === null) {
|
|
309
335
|
volume = 0;
|
|
310
336
|
}
|
|
337
|
+
const webLink = await this.getWebLink(testOptions);
|
|
338
|
+
const googleHomeServer = (testOptions && testOptions.googleHomeServer) || this.adapter.config.googleHomeServer;
|
|
311
339
|
|
|
312
|
-
if (
|
|
313
|
-
const url = `${
|
|
314
|
-
this.adapter.log.debug(`Send to google home "${
|
|
340
|
+
if (googleHomeServer && webLink) {
|
|
341
|
+
const url = `${webLink}${result.fileInDB}`;
|
|
342
|
+
this.adapter.log.debug(`Send to google home "${googleHomeServer}": ${url}`);
|
|
315
343
|
|
|
316
|
-
await this.sendToGoogleHome(
|
|
344
|
+
await this.sendToGoogleHome(googleHomeServer, url, volume);
|
|
317
345
|
} else {
|
|
318
346
|
throw new Error('Web server is unavailable!');
|
|
319
347
|
}
|
|
@@ -321,34 +349,35 @@ class Speech2Device {
|
|
|
321
349
|
return duration;
|
|
322
350
|
}
|
|
323
351
|
|
|
324
|
-
async sayItMP24(text, language, volume, duration) {
|
|
352
|
+
async sayItMP24(text, language, volume, duration, testOptions) {
|
|
325
353
|
axios = axios || require('axios');
|
|
354
|
+
const mp24Server = (testOptions && testOptions.mp24Server) || this.adapter.config.mp24Server;
|
|
326
355
|
|
|
327
|
-
if (
|
|
356
|
+
if (mp24Server) {
|
|
328
357
|
if (!Speech2Device.isPlayFile(text)) {
|
|
329
358
|
// say
|
|
330
|
-
this.adapter.log.debug(`Request MediaPlayer24 "http://${
|
|
359
|
+
this.adapter.log.debug(`Request MediaPlayer24 "http://${mp24Server}:50000/tts=${encodeURI(text)}"`);
|
|
331
360
|
try {
|
|
332
|
-
const response = await axios.get(`http://${
|
|
333
|
-
this.adapter.log.debug(`Response from MediaPlayer24 "${
|
|
361
|
+
const response = await axios.get(`http://${mp24Server}:50000/tts=${encodeURI(text)}`);
|
|
362
|
+
this.adapter.log.debug(`Response from MediaPlayer24 "${mp24Server}": ${response.data}`);
|
|
334
363
|
} catch (e) {
|
|
335
364
|
if (e.message === 'Parse Error') {
|
|
336
365
|
this.adapter.log.debug('Played successfully');
|
|
337
366
|
} else {
|
|
338
|
-
this.adapter.log.error(`Cannot say text on MediaPlayer24 "${
|
|
367
|
+
this.adapter.log.error(`Cannot say text on MediaPlayer24 "${mp24Server}": ${e.message}`);
|
|
339
368
|
throw e;
|
|
340
369
|
}
|
|
341
370
|
}
|
|
342
371
|
} else {
|
|
343
372
|
// play local file
|
|
344
373
|
try {
|
|
345
|
-
const response = await axios.get(`http://${
|
|
346
|
-
this.adapter.log.debug(`Response from MediaPlayer24 "${
|
|
374
|
+
const response = await axios.get(`http://${mp24Server}:50000/track=${text}`);
|
|
375
|
+
this.adapter.log.debug(`Response from MediaPlayer24 "${mp24Server}": ${response.data}`);
|
|
347
376
|
} catch (e) {
|
|
348
377
|
if (e.message === 'Parse Error') {
|
|
349
378
|
this.adapter.log.debug('Played successfully');
|
|
350
379
|
} else {
|
|
351
|
-
this.adapter.log.error(`Cannot say text on MediaPlayer24 "${
|
|
380
|
+
this.adapter.log.error(`Cannot say text on MediaPlayer24 "${mp24Server}": ${e.message}`);
|
|
352
381
|
throw e;
|
|
353
382
|
}
|
|
354
383
|
}
|
|
@@ -358,19 +387,23 @@ class Speech2Device {
|
|
|
358
387
|
return duration + 2;
|
|
359
388
|
}
|
|
360
389
|
|
|
361
|
-
async sayItMP24ftp(text, language, volume, duration) {
|
|
390
|
+
async sayItMP24ftp(text, language, volume, duration, testOptions) {
|
|
362
391
|
const result = await this.uploadToStates(text);
|
|
392
|
+
const mp24Server = (testOptions && testOptions.mp24Server) || this.adapter.config.mp24Server;
|
|
393
|
+
const ftpPort = (testOptions && testOptions.ftpPort) || this.adapter.config.ftpPort;
|
|
394
|
+
const ftpUser = (testOptions && testOptions.ftpUser) || this.adapter.config.ftpUser;
|
|
395
|
+
const ftpPassword = (testOptions && testOptions.ftpPassword) || this.adapter.config.ftpPassword;
|
|
363
396
|
|
|
364
397
|
// Copy mp3 file to android device to play it later with MediaPlayer
|
|
365
|
-
if (
|
|
398
|
+
if (ftpPort && mp24Server) {
|
|
366
399
|
jsftp = jsftp || require('jsftp');
|
|
367
400
|
axios = axios || require('axios');
|
|
368
401
|
|
|
369
402
|
const ftp = new jsftp({
|
|
370
|
-
host:
|
|
371
|
-
port: parseInt(
|
|
372
|
-
user:
|
|
373
|
-
pass:
|
|
403
|
+
host: mp24Server,
|
|
404
|
+
port: parseInt(ftpPort, 10), // defaults to 21
|
|
405
|
+
user: ftpUser || 'anonymous', // defaults to 'anonymous'
|
|
406
|
+
pass: ftpPassword || 'anonymous', // defaults to 'anonymous'
|
|
374
407
|
});
|
|
375
408
|
|
|
376
409
|
await new Promise((resolve, reject) => {
|
|
@@ -385,15 +418,15 @@ class Speech2Device {
|
|
|
385
418
|
|
|
386
419
|
if (!hadError) {
|
|
387
420
|
try {
|
|
388
|
-
const response = await axios.get(`http://${
|
|
389
|
-
this.adapter.log.debug(`Response from MediaPlayer24 "${
|
|
421
|
+
const response = await axios.get(`http://${mp24Server}:50000/track=${fileNameOnFTP}`);
|
|
422
|
+
this.adapter.log.debug(`Response from MediaPlayer24 "${mp24Server}": ${response.data}`);
|
|
390
423
|
resolve();
|
|
391
424
|
} catch (e) {
|
|
392
425
|
if (e.message === 'Parse Error') {
|
|
393
426
|
this.adapter.log.debug('Played successfully');
|
|
394
427
|
resolve();
|
|
395
428
|
} else {
|
|
396
|
-
this.adapter.log.error(`Cannot say text on MediaPlayer24 "${
|
|
429
|
+
this.adapter.log.error(`Cannot say text on MediaPlayer24 "${mp24Server}": ${e.message}`);
|
|
397
430
|
reject(e);
|
|
398
431
|
}
|
|
399
432
|
}
|
|
@@ -403,7 +436,7 @@ class Speech2Device {
|
|
|
403
436
|
});
|
|
404
437
|
});
|
|
405
438
|
} catch (e) {
|
|
406
|
-
throw new Error(`Cannot upload file to ${
|
|
439
|
+
throw new Error(`Cannot upload file to ${mp24Server}:${ftpPort}`);
|
|
407
440
|
}
|
|
408
441
|
});
|
|
409
442
|
}
|
|
@@ -411,28 +444,30 @@ class Speech2Device {
|
|
|
411
444
|
return duration + 2;
|
|
412
445
|
}
|
|
413
446
|
|
|
414
|
-
async sayItSystem(text, language, volume, duration) {
|
|
447
|
+
async sayItSystem(text, language, volume, duration, testOptions) {
|
|
415
448
|
os = os || require('os');
|
|
416
449
|
cp = cp || require('child_process');
|
|
417
450
|
|
|
418
451
|
const result = await this.uploadToStates(text);
|
|
452
|
+
const systemCommand = (testOptions && testOptions.systemCommand) || this.adapter.config.systemCommand;
|
|
453
|
+
const systemPlayer = (testOptions && testOptions.systemPlayer) || this.adapter.config.systemPlayer;
|
|
419
454
|
|
|
420
455
|
const p = os.platform();
|
|
421
456
|
let cmd;
|
|
422
457
|
|
|
423
458
|
if (volume !== undefined) {
|
|
424
|
-
await this.sayItSystemVolume(volume);
|
|
459
|
+
await this.sayItSystemVolume(volume, testOptions);
|
|
425
460
|
}
|
|
426
461
|
|
|
427
|
-
if (
|
|
462
|
+
if (systemCommand) {
|
|
428
463
|
// custom command
|
|
429
|
-
if (
|
|
430
|
-
cmd =
|
|
464
|
+
if (systemCommand.includes('%s')) {
|
|
465
|
+
cmd = systemCommand.replace('%s', result.fileOnDisk);
|
|
431
466
|
} else {
|
|
432
467
|
if (p.match(/^win/)) {
|
|
433
|
-
cmd = `${
|
|
468
|
+
cmd = `${systemCommand} "${result.fileOnDisk}"`;
|
|
434
469
|
} else {
|
|
435
|
-
cmd = `${
|
|
470
|
+
cmd = `${systemCommand} ${result.fileOnDisk}`;
|
|
436
471
|
}
|
|
437
472
|
}
|
|
438
473
|
try {
|
|
@@ -443,9 +478,9 @@ class Speech2Device {
|
|
|
443
478
|
} else {
|
|
444
479
|
if (p === 'linux') {
|
|
445
480
|
// linux
|
|
446
|
-
if (
|
|
481
|
+
if (systemPlayer === 'omxplayer') {
|
|
447
482
|
cmd = `omxplayer -o local ${result.fileOnDisk}`;
|
|
448
|
-
} else if (
|
|
483
|
+
} else if (systemPlayer === 'mpg321') {
|
|
449
484
|
cmd = `mpg321 -g ${this.options.sayLastVolume} ${result.fileOnDisk}`;
|
|
450
485
|
} else {
|
|
451
486
|
cmd = `mplayer ${result.fileOnDisk} -volume ${this.options.sayLastVolume}`;
|
|
@@ -479,10 +514,10 @@ class Speech2Device {
|
|
|
479
514
|
}
|
|
480
515
|
}
|
|
481
516
|
|
|
482
|
-
async sayItWindows(text, language, volume, duration) {
|
|
517
|
+
async sayItWindows(text, language, volume, duration, testOptions) {
|
|
483
518
|
// If mp3 file
|
|
484
519
|
if (Speech2Device.isPlayFile(text)) {
|
|
485
|
-
return this.sayItSystem(text, language, volume);
|
|
520
|
+
return this.sayItSystem(text, language, volume, duration, testOptions);
|
|
486
521
|
}
|
|
487
522
|
|
|
488
523
|
os = os || require('os');
|
|
@@ -491,7 +526,7 @@ class Speech2Device {
|
|
|
491
526
|
const p = os.platform();
|
|
492
527
|
|
|
493
528
|
if (volume || volume === 0) {
|
|
494
|
-
await this.sayItSystemVolume(volume);
|
|
529
|
+
await this.sayItSystemVolume(volume, testOptions);
|
|
495
530
|
}
|
|
496
531
|
|
|
497
532
|
if (p.match(/^win/)) {
|
|
@@ -508,7 +543,7 @@ class Speech2Device {
|
|
|
508
543
|
return duration + 2;
|
|
509
544
|
}
|
|
510
545
|
|
|
511
|
-
async sayItSystemVolume(level) {
|
|
546
|
+
async sayItSystemVolume(level, testOptions) {
|
|
512
547
|
if ((!level && level !== 0) || level === 'null') {
|
|
513
548
|
return;
|
|
514
549
|
}
|
|
@@ -532,8 +567,9 @@ class Speech2Device {
|
|
|
532
567
|
this.options.sayLastVolume = level;
|
|
533
568
|
|
|
534
569
|
const p = os.platform();
|
|
570
|
+
const systemPlayer = (testOptions && testOptions.systemPlayer) || this.adapter.config.systemPlayer;
|
|
535
571
|
|
|
536
|
-
if (p === 'linux' &&
|
|
572
|
+
if (p === 'linux' && systemPlayer !== 'mpg321') {
|
|
537
573
|
// linux
|
|
538
574
|
try {
|
|
539
575
|
await this.spawn('amixer', ['cset', 'name="Master Playback Volume"', '--', `${level}%`]);
|
|
@@ -545,7 +581,7 @@ class Speech2Device {
|
|
|
545
581
|
// windows volume is from 0 to 65535
|
|
546
582
|
level = Math.round((65535 * level) / 100); // because this level is from 0 to 100
|
|
547
583
|
try {
|
|
548
|
-
await this.spawn(`${__dirname}/../nircmd/nircmdc.exe
|
|
584
|
+
await this.spawn(path.normalize(`${__dirname}/../nircmd/nircmdc.exe`), ['setsysvolume', level], true);
|
|
549
585
|
} catch (err) {
|
|
550
586
|
this.adapter.log.error('nircmd is not available, so you may hear no audio.');
|
|
551
587
|
}
|
|
@@ -559,27 +595,28 @@ class Speech2Device {
|
|
|
559
595
|
}
|
|
560
596
|
};
|
|
561
597
|
|
|
562
|
-
async playFile(type, text, language, volume, duration) {
|
|
598
|
+
async playFile(type, text, language, volume, duration, testOptions) {
|
|
599
|
+
type = testOptions ? testOptions.type || type : type;
|
|
563
600
|
if (type === 'browser') {
|
|
564
|
-
return await this.sayItBrowser(text, language, volume, duration);
|
|
601
|
+
return await this.sayItBrowser(text, language, volume, duration, testOptions);
|
|
565
602
|
} else if (type === 'mp24ftp') {
|
|
566
|
-
return await this.sayItMP24ftp(text, language, volume, duration);
|
|
603
|
+
return await this.sayItMP24ftp(text, language, volume, duration, testOptions);
|
|
567
604
|
} else if (type === 'mp24') {
|
|
568
|
-
return await this.sayItMP24(text, language, volume, duration);
|
|
605
|
+
return await this.sayItMP24(text, language, volume, duration, testOptions);
|
|
569
606
|
} else if (type === 'system') {
|
|
570
|
-
return await this.sayItSystem(text, language, volume, duration);
|
|
607
|
+
return await this.sayItSystem(text, language, volume, duration, testOptions);
|
|
571
608
|
} else if (type === 'windows') {
|
|
572
|
-
return await this.sayItWindows(text, language, volume, duration);
|
|
609
|
+
return await this.sayItWindows(text, language, volume, duration, testOptions);
|
|
573
610
|
} else if (type === 'sonos') {
|
|
574
|
-
return await this.sayItSonos(text, language, volume, duration);
|
|
611
|
+
return await this.sayItSonos(text, language, volume, duration, testOptions);
|
|
575
612
|
} else if (type === 'heos') {
|
|
576
|
-
return await this.sayItHeos(text, language, volume, duration);
|
|
613
|
+
return await this.sayItHeos(text, language, volume, duration, testOptions);
|
|
577
614
|
} else if (type === 'chromecast') {
|
|
578
|
-
return await this.sayItChromecast(text, language, volume, duration);
|
|
615
|
+
return await this.sayItChromecast(text, language, volume, duration, testOptions);
|
|
579
616
|
} else if (type === 'mpd') {
|
|
580
|
-
return await this.sayItMpd(text, language, volume, duration);
|
|
617
|
+
return await this.sayItMpd(text, language, volume, duration, testOptions);
|
|
581
618
|
} else if (type === 'googleHome') {
|
|
582
|
-
return await this.sayItGoogleHome(text, language, volume, duration);
|
|
619
|
+
return await this.sayItGoogleHome(text, language, volume, duration, testOptions);
|
|
583
620
|
} else {
|
|
584
621
|
this.adapter.log.error(`Unknown play type: ${type}`);
|
|
585
622
|
}
|
package/lib/text2speech.js
CHANGED
|
@@ -95,7 +95,7 @@ class Text2Speech {
|
|
|
95
95
|
});
|
|
96
96
|
}
|
|
97
97
|
|
|
98
|
-
async sayItGetSpeechGoogle(text, language, volume) {
|
|
98
|
+
async sayItGetSpeechGoogle(text, language, volume, testOptions) {
|
|
99
99
|
if (!text.length) {
|
|
100
100
|
throw new Error('No text to speak');
|
|
101
101
|
}
|
|
@@ -104,12 +104,12 @@ class Text2Speech {
|
|
|
104
104
|
if (text.length > 70) {
|
|
105
105
|
const parts = Text2Speech.splitText(text);
|
|
106
106
|
for (let t = 1; t < parts.length; t++) {
|
|
107
|
-
this.addToQueue(parts[t], language, volume);
|
|
107
|
+
this.addToQueue(parts[t], language, volume, testOptions);
|
|
108
108
|
}
|
|
109
109
|
text = parts[0];
|
|
110
110
|
}
|
|
111
111
|
|
|
112
|
-
language = language || this.adapter.config.engine;
|
|
112
|
+
language = language || (testOptions && testOptions.engine) || this.adapter.config.engine;
|
|
113
113
|
|
|
114
114
|
// get base64 text
|
|
115
115
|
const data = await googleTTS.getAudioBase64(text, {
|
|
@@ -124,30 +124,34 @@ class Text2Speech {
|
|
|
124
124
|
throw new Error('received file is too short');
|
|
125
125
|
} else
|
|
126
126
|
if (buf.toString().includes('302 Moved')) {
|
|
127
|
-
throw new Error(`
|
|
127
|
+
throw new Error(`https://translate.google.com\nCannot get file: ${buf.toString()}`);
|
|
128
128
|
} else {
|
|
129
129
|
fs.writeFileSync(this.MP3FILE, buf, 'binary');
|
|
130
130
|
}
|
|
131
131
|
}
|
|
132
132
|
|
|
133
|
-
async sayItGetSpeechYandexCloud(text, language) {
|
|
133
|
+
async sayItGetSpeechYandexCloud(text, language, _, testOptions) {
|
|
134
134
|
if (language === 'ru' || language === 'ru_YA' || language === 'ru_YA_CLOUD') {
|
|
135
135
|
language = 'ru-RU';
|
|
136
136
|
}
|
|
137
|
+
axios = axios || require('axios');
|
|
138
|
+
const yandexCloudVoice = (testOptions && testOptions.yandexCloudVoice) || this.adapter.config.yandexCloudVoice || '';
|
|
139
|
+
const yandexKey = (testOptions && testOptions.yandexKey) || this.adapter.config.yandexKey;
|
|
140
|
+
const yandexEmotion = (testOptions && testOptions.yandexEmotion) || this.adapter.config.yandexEmotion;
|
|
141
|
+
const yandexFolderID = (testOptions && testOptions.yandexFolderID) || this.adapter.config.yandexFolderID;
|
|
137
142
|
|
|
138
|
-
const voice = this.adapter.config.yandexCloudVoice || '';
|
|
139
143
|
const params = new URLSearchParams();
|
|
140
144
|
params.append('text', text);
|
|
141
|
-
params.append('voice',
|
|
142
|
-
params.append('folderId',
|
|
143
|
-
if (
|
|
144
|
-
params.append('emotion',
|
|
145
|
+
params.append('voice', yandexCloudVoice.replace(' Premium', ''));
|
|
146
|
+
params.append('folderId', yandexFolderID || '');
|
|
147
|
+
if (yandexEmotion !== 'none' && yandexEmotion) {
|
|
148
|
+
params.append('emotion', yandexEmotion);
|
|
145
149
|
}
|
|
146
150
|
params.append('lang', language);
|
|
147
151
|
|
|
148
152
|
const response = await axios.post(`https://tts.api.cloud.yandex.net/speech/v1/tts:synthesize`, params, {
|
|
149
153
|
headers: {
|
|
150
|
-
'Authorization': `Api-Key ${
|
|
154
|
+
'Authorization': `Api-Key ${yandexKey}`,
|
|
151
155
|
},
|
|
152
156
|
responseType: 'arraybuffer',
|
|
153
157
|
});
|
|
@@ -158,7 +162,7 @@ class Text2Speech {
|
|
|
158
162
|
fs.writeFileSync(this.MP3FILE, response.data, 'binary');
|
|
159
163
|
}
|
|
160
164
|
|
|
161
|
-
async sayItGetSpeechYandex(text, language) {
|
|
165
|
+
async sayItGetSpeechYandex(text, language, _, testOptions) {
|
|
162
166
|
if (language === 'ru' || language === 'ru_YA') {
|
|
163
167
|
language = 'ru-RU';
|
|
164
168
|
}
|
|
@@ -168,22 +172,28 @@ class Text2Speech {
|
|
|
168
172
|
ill: true, false
|
|
169
173
|
robot: true, false
|
|
170
174
|
*/
|
|
175
|
+
const yandexVoice = (testOptions && testOptions.yandexVoice) || this.adapter.config.yandexVoice;
|
|
176
|
+
const yandexKey = (testOptions && testOptions.yandexKey) || this.adapter.config.yandexKey;
|
|
177
|
+
const yandexEmotion = (testOptions && testOptions.yandexEmotion) || this.adapter.config.yandexEmotion;
|
|
178
|
+
const yandexDrunk = (testOptions && testOptions.yandexDrunk !== undefined ? testOptions.yandexDrunk : this.adapter.config.yandexDrunk) || this.adapter.config.yandexDrunk;
|
|
179
|
+
const yandexIll = (testOptions && testOptions.yandexIll !== undefined ? testOptions.yandexIll : this.adapter.config.yandexIll) || this.adapter.config.yandexIll;
|
|
180
|
+
const yandexRobot = (testOptions && testOptions.yandexRobot !== undefined ? testOptions.yandexRobot : this.adapter.config.yandexRobot) || this.adapter.config.yandexRobot;
|
|
171
181
|
|
|
172
|
-
let url = `https://tts.voicetech.yandex.net/generate?lang=${language}&format=mp3&speaker=${
|
|
182
|
+
let url = `https://tts.voicetech.yandex.net/generate?lang=${language}&format=mp3&speaker=${yandexVoice}&key=${yandexKey}&text=${encodeURI(text.trim())}`;
|
|
173
183
|
|
|
174
|
-
if (
|
|
175
|
-
url += `&emotion=${
|
|
184
|
+
if (yandexEmotion && yandexEmotion !== 'none') {
|
|
185
|
+
url += `&emotion=${yandexEmotion}`;
|
|
176
186
|
}
|
|
177
|
-
if (
|
|
187
|
+
if (yandexDrunk === 'true' || yandexDrunk === true) {
|
|
178
188
|
url += '&drunk=true';
|
|
179
189
|
}
|
|
180
|
-
if (
|
|
190
|
+
if (yandexIll === 'true' || yandexIll === true) {
|
|
181
191
|
url += '&ill=true';
|
|
182
192
|
}
|
|
183
|
-
if (
|
|
193
|
+
if (yandexRobot === 'true' || yandexRobot === true) {
|
|
184
194
|
url += '&robot=true';
|
|
185
195
|
}
|
|
186
|
-
|
|
196
|
+
axios = axios || require('axios');
|
|
187
197
|
const response = await axios.get(url, {responseType: 'arraybuffer'});
|
|
188
198
|
if (!response.data || response.data.length < 100) {
|
|
189
199
|
throw new Error('Cannot get file: received file is too short');
|
|
@@ -191,14 +201,18 @@ class Text2Speech {
|
|
|
191
201
|
fs.writeFileSync(this.MP3FILE, response.data, 'binary');
|
|
192
202
|
}
|
|
193
203
|
|
|
194
|
-
sayItGetSpeechPolly(text, language) {
|
|
204
|
+
sayItGetSpeechPolly(text, language, _, testOptions) {
|
|
195
205
|
aws = aws || require('aws-sdk');
|
|
206
|
+
const awsAccessKey = (testOptions && testOptions.awsAccessKey) || this.adapter.config.awsAccessKey;
|
|
207
|
+
const awsSecretKey = (testOptions && testOptions.awsSecretKey) || this.adapter.config.awsSecretKey;
|
|
208
|
+
const awsRegion = (testOptions && testOptions.awsRegion) || this.adapter.config.awsRegion;
|
|
196
209
|
|
|
197
210
|
this.polly = this.polly || new aws.Polly({
|
|
198
|
-
accessKeyId:
|
|
199
|
-
secretAccessKey:
|
|
200
|
-
region:
|
|
211
|
+
accessKeyId: awsAccessKey,
|
|
212
|
+
secretAccessKey: awsSecretKey,
|
|
213
|
+
region: awsRegion,
|
|
201
214
|
});
|
|
215
|
+
|
|
202
216
|
let type = 'text';
|
|
203
217
|
if (text.match(/<[-+\w\s'"=]+>/)) {
|
|
204
218
|
if (!text.match(/^<speak>/)) {
|
|
@@ -231,10 +245,10 @@ class Text2Speech {
|
|
|
231
245
|
}));
|
|
232
246
|
}
|
|
233
247
|
|
|
234
|
-
async sayItGetSpeechCoquiTTS(text, language) {
|
|
248
|
+
async sayItGetSpeechCoquiTTS(text, language, _, testOptions) {
|
|
235
249
|
language = language.substring(0, 2);
|
|
236
250
|
let cmd;
|
|
237
|
-
const coquiVocoder = this.adapter.config.coquiVocoder;
|
|
251
|
+
const coquiVocoder = (testOptions && testOptions.coquiVocoder) || this.adapter.config.coquiVocoder;
|
|
238
252
|
if (coquiVocoder === 'default') {
|
|
239
253
|
cmd = `tts --text ". ${text} ." --model_name tts_models/${language}/${coquiVocoder.replace(' ', '/')} --out_path ${__dirname}/say.wav`;
|
|
240
254
|
} else {
|
|
@@ -255,11 +269,13 @@ class Text2Speech {
|
|
|
255
269
|
}
|
|
256
270
|
}
|
|
257
271
|
|
|
258
|
-
async sayItGetSpeechCloud(text, language) {
|
|
272
|
+
async sayItGetSpeechCloud(text, language, _, testOptions) {
|
|
259
273
|
axios = axios || require('axios');
|
|
260
274
|
|
|
261
275
|
if (!this.cloudAppKey) {
|
|
262
|
-
const
|
|
276
|
+
const cloudInstance = (testOptions && testOptions.cloudInstance) || this.adapter.config.cloudInstance;
|
|
277
|
+
|
|
278
|
+
const obj = await this.adapter.getForeignObjectAsync(`system.this.adapter.${cloudInstance}`);
|
|
263
279
|
this.cloudAppKey = obj && obj.native && obj.native.apikey ? obj.native.apikey : 'error';
|
|
264
280
|
this.cloudUrl = (obj && obj.native && obj.native.cloudUrl) || '';
|
|
265
281
|
if (this.cloudAppKey && this.cloudAppKey.match(/^@pro_/)) {
|
|
@@ -352,8 +368,8 @@ class Text2Speech {
|
|
|
352
368
|
}
|
|
353
369
|
};
|
|
354
370
|
|
|
355
|
-
async sayItGetSpeech(text, language, volume) {
|
|
356
|
-
if (this.adapter.config.cache) {
|
|
371
|
+
async sayItGetSpeech(text, language, volume, testOptions) {
|
|
372
|
+
if (this.adapter.config.cache && !testOptions) {
|
|
357
373
|
const md5filename = this.isCached(this.options.cacheDir, `${language};${text}`, this.options.outFileExt, this.adapter.config.cacheExpiryDays);
|
|
358
374
|
|
|
359
375
|
if (md5filename) {
|
|
@@ -371,25 +387,25 @@ class Text2Speech {
|
|
|
371
387
|
const engine = sayitEngines[language].engine;
|
|
372
388
|
|
|
373
389
|
if (engine === 'google') {
|
|
374
|
-
await this.sayItGetSpeechGoogle(text, language, volume);
|
|
390
|
+
await this.sayItGetSpeechGoogle(text, language, volume, testOptions);
|
|
375
391
|
} else if (engine === 'yandex') {
|
|
376
|
-
await this.sayItGetSpeechYandex(text, language,
|
|
392
|
+
await this.sayItGetSpeechYandex(text, language, null, testOptions);
|
|
377
393
|
} else if (engine === 'yandexCloud') {
|
|
378
|
-
await this.sayItGetSpeechYandexCloud(text, language,
|
|
394
|
+
await this.sayItGetSpeechYandexCloud(text, language, null, testOptions);
|
|
379
395
|
} else if (engine === 'polly') {
|
|
380
|
-
await this.sayItGetSpeechPolly(text, language,
|
|
396
|
+
await this.sayItGetSpeechPolly(text, language, null, testOptions);
|
|
381
397
|
} else if (engine === 'coquiTTS') {
|
|
382
|
-
await this.sayItGetSpeechCoquiTTS(text, language,
|
|
398
|
+
await this.sayItGetSpeechCoquiTTS(text, language, null, testOptions);
|
|
383
399
|
} else if (engine === 'cloud') {
|
|
384
|
-
await this.sayItGetSpeechCloud(text, language,
|
|
400
|
+
await this.sayItGetSpeechCloud(text, language, null, testOptions);
|
|
385
401
|
} else if (engine === 'PicoTTS') {
|
|
386
|
-
await this.sayItGetSpeechPicoTTS(text, language,
|
|
402
|
+
await this.sayItGetSpeechPicoTTS(text, language, null, testOptions);
|
|
387
403
|
} else {
|
|
388
404
|
throw new Error(`Engine ${engine} not yet supported.`);
|
|
389
405
|
}
|
|
390
406
|
} else {
|
|
391
407
|
// fallback to google
|
|
392
|
-
await this.sayItGetSpeechGoogle(text, language, volume);
|
|
408
|
+
await this.sayItGetSpeechGoogle(text, language, volume, testOptions);
|
|
393
409
|
}
|
|
394
410
|
|
|
395
411
|
if (this.adapter.config.cache) {
|
package/main.js
CHANGED
|
@@ -78,7 +78,7 @@ function startAdapter(options) {
|
|
|
78
78
|
|
|
79
79
|
adapter.on('objectChange', (id, obj) => {
|
|
80
80
|
if (id === `system.adapter.${adapter.config.webInstance}`) {
|
|
81
|
-
|
|
81
|
+
options.webLink = getWebLink(obj, adapter.config.webServer, adapter.config.webInstance);
|
|
82
82
|
}
|
|
83
83
|
});
|
|
84
84
|
|
|
@@ -166,6 +166,38 @@ function processMessage(obj) {
|
|
|
166
166
|
}
|
|
167
167
|
adapter.sendTo(obj.from, obj.command, list, obj.callback);
|
|
168
168
|
});
|
|
169
|
+
} else if (obj.callback && obj.command === 'test') {
|
|
170
|
+
const language = (obj.message.engine || adapter.config.engine).substring(0, 2);
|
|
171
|
+
let text = 'Hello';
|
|
172
|
+
if (language === 'de') {
|
|
173
|
+
text = 'Hallo';
|
|
174
|
+
} else if (language === 'pl') {
|
|
175
|
+
text = 'Cześć';
|
|
176
|
+
} else if (language === 'uk') {
|
|
177
|
+
text = 'Привіт';
|
|
178
|
+
} else if (language === 'ru') {
|
|
179
|
+
text = 'Привет';
|
|
180
|
+
} else if (language === 'it') {
|
|
181
|
+
text = 'Ciao';
|
|
182
|
+
} else if (language === 'pt') {
|
|
183
|
+
text = 'Olá';
|
|
184
|
+
} else if (language === 'es') {
|
|
185
|
+
text = 'Hola';
|
|
186
|
+
} else if (language === 'fr') {
|
|
187
|
+
text = 'Bonjour';
|
|
188
|
+
} else if (language === 'nl') {
|
|
189
|
+
text = 'Hallo';
|
|
190
|
+
} else if (language === 'zh') {
|
|
191
|
+
text = '你好';
|
|
192
|
+
}
|
|
193
|
+
const opts = {...obj.message};
|
|
194
|
+
if (obj.callback) {
|
|
195
|
+
opts.callback = error => {
|
|
196
|
+
adapter.sendTo(obj.from, obj.command, {error, result: error ? undefined : 'Ok'}, obj.callback);
|
|
197
|
+
};
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
addToQueue(text, null, null, null, opts);
|
|
169
201
|
}
|
|
170
202
|
}
|
|
171
203
|
}
|
|
@@ -210,7 +242,7 @@ function mkpathSync(rootpath, dirpath) {
|
|
|
210
242
|
}
|
|
211
243
|
}
|
|
212
244
|
|
|
213
|
-
function addToQueue(text, language, volume, onlyCache) {
|
|
245
|
+
function addToQueue(text, language, volume, onlyCache, testOptions) {
|
|
214
246
|
// Extract language from "en;volume;Text to say"
|
|
215
247
|
if (text.includes(';')) {
|
|
216
248
|
const arr = text.split(';', 3);
|
|
@@ -252,7 +284,7 @@ function addToQueue(text, language, volume, onlyCache) {
|
|
|
252
284
|
volume = undefined;
|
|
253
285
|
}
|
|
254
286
|
|
|
255
|
-
const task = {text, language, volume, onlyCache, ts: Date.now(), combined};
|
|
287
|
+
const task = {text, language, volume, onlyCache, ts: Date.now(), combined, testOptions};
|
|
256
288
|
|
|
257
289
|
// If more time than 15 seconds till last text, add announcement
|
|
258
290
|
if (!onlyCache && adapter.config.announce && !tasks.length && (!lastSay || (Date.now() - lastSay > adapter.config.annoTimeout * 1000))) {
|
|
@@ -261,7 +293,8 @@ function addToQueue(text, language, volume, onlyCache) {
|
|
|
261
293
|
text: adapter.config.announce,
|
|
262
294
|
language,
|
|
263
295
|
volume: Math.round((volume || 70) / 100 * (parseInt(adapter.config.annoVolume, 10) || 50)),
|
|
264
|
-
ts: task.ts
|
|
296
|
+
ts: task.ts,
|
|
297
|
+
testOptions
|
|
265
298
|
});
|
|
266
299
|
// and then text
|
|
267
300
|
tasks.push(task);
|
|
@@ -303,7 +336,8 @@ async function processTasks() {
|
|
|
303
336
|
return;
|
|
304
337
|
}
|
|
305
338
|
processing = true;
|
|
306
|
-
let {text, language, volume, onlyCache} = tasks[0];
|
|
339
|
+
let {text, language, volume, onlyCache, testOptions} = tasks[0];
|
|
340
|
+
let error;
|
|
307
341
|
|
|
308
342
|
if (text[0] === '!') {
|
|
309
343
|
text = text.substring(1);
|
|
@@ -318,7 +352,7 @@ async function processTasks() {
|
|
|
318
352
|
// find out if say.mp3 must be generated
|
|
319
353
|
const isGenerate = !Speech2Device.isPlayFile(text) && sayitOptions[adapter.config.type].mp3Required;
|
|
320
354
|
|
|
321
|
-
language = language || adapter.config.engine;
|
|
355
|
+
language = language || (testOptions && testOptions.engine) || adapter.config.engine;
|
|
322
356
|
|
|
323
357
|
// if no text => do not process
|
|
324
358
|
if (isGenerate && text.length && text2speech && speech2device) {
|
|
@@ -376,19 +410,22 @@ async function processTasks() {
|
|
|
376
410
|
|
|
377
411
|
// If text first must be generated, and it is not the same as last one
|
|
378
412
|
if (!fileName && isGenerate) {
|
|
379
|
-
if (sayLastGeneratedText !== `[${language}]${text}`) {
|
|
380
|
-
if (adapter.config.cache) {
|
|
413
|
+
if (sayLastGeneratedText !== `[${language}]${text}` || testOptions) {
|
|
414
|
+
if (adapter.config.cache && !testOptions) {
|
|
381
415
|
let md5filename = isCached(options.cacheDir, `${language};${text}`, fileExt, adapter.config.cacheExpiryDays);
|
|
382
416
|
if (md5filename) {
|
|
383
417
|
fileName = md5filename;
|
|
384
|
-
}
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
418
|
+
}
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
if (!fileName) {
|
|
422
|
+
try {
|
|
423
|
+
fileName = await text2speech.sayItGetSpeech(text, language, volume, testOptions);
|
|
424
|
+
sayLastGeneratedText = `[${language}]${text}`;
|
|
425
|
+
} catch (e) {
|
|
426
|
+
fileName = null;
|
|
427
|
+
error = `Cannot generate speech file: ${e}`;
|
|
428
|
+
adapter.log.error(error);
|
|
392
429
|
}
|
|
393
430
|
}
|
|
394
431
|
} else {
|
|
@@ -400,24 +437,30 @@ async function processTasks() {
|
|
|
400
437
|
let duration = 0;
|
|
401
438
|
|
|
402
439
|
if (!onlyCache && text.length) {
|
|
403
|
-
await
|
|
440
|
+
await adapter.setStateAsync('tts.playing', true, true);
|
|
404
441
|
try {
|
|
405
442
|
// play file
|
|
406
443
|
if (fileName) {
|
|
407
444
|
duration = await text2speech.getDuration(fileName);
|
|
408
|
-
duration = await speech2device.playFile(adapter.config.type, fileName, language, volume, duration);
|
|
445
|
+
duration = await speech2device.playFile(adapter.config.type, fileName, language, volume, duration, testOptions);
|
|
409
446
|
} else if (!isGenerate) {
|
|
410
447
|
if (Speech2Device.isPlayFile(text)) {
|
|
411
448
|
duration = await text2speech.getDuration(text);
|
|
412
449
|
}
|
|
413
450
|
|
|
414
|
-
duration = await speech2device.playFile(adapter.config.type, text, language, volume, duration);
|
|
451
|
+
duration = await speech2device.playFile(adapter.config.type, text, language, volume, duration, testOptions);
|
|
415
452
|
}
|
|
416
453
|
lastSay = Date.now();
|
|
417
454
|
} catch (e) {
|
|
418
|
-
|
|
455
|
+
error = `Cannot play file: ${e}`;
|
|
456
|
+
adapter.log.error(error);
|
|
419
457
|
}
|
|
420
|
-
await
|
|
458
|
+
await adapter.setStateAsync('tts.playing', false, true);
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
if (tasks[0] && tasks[0].testOptions && tasks[0].testOptions.callback) {
|
|
462
|
+
tasks[0].testOptions.callback(error);
|
|
463
|
+
tasks[0].testOptions.callback = null;
|
|
421
464
|
}
|
|
422
465
|
|
|
423
466
|
tasks.shift();
|
|
@@ -477,9 +520,9 @@ async function uploadFiles() {
|
|
|
477
520
|
type: 'meta',
|
|
478
521
|
common: {
|
|
479
522
|
name: 'User files for SayIt',
|
|
480
|
-
type: 'meta.user'
|
|
523
|
+
type: 'meta.user',
|
|
481
524
|
},
|
|
482
|
-
native: {}
|
|
525
|
+
native: {},
|
|
483
526
|
});
|
|
484
527
|
}
|
|
485
528
|
|
|
@@ -538,6 +581,9 @@ async function start() {
|
|
|
538
581
|
delete newConfig.pass;
|
|
539
582
|
delete newConfig.cDevice;
|
|
540
583
|
delete newConfig.instance;
|
|
584
|
+
delete newConfig.sonos;
|
|
585
|
+
delete newConfig.googleHome;
|
|
586
|
+
delete newConfig.device;
|
|
541
587
|
|
|
542
588
|
if (newConfig.engine === 'ru_YA_CLOUD') {
|
|
543
589
|
newConfig.yandexKey = newConfig.key;
|
|
@@ -568,10 +614,11 @@ async function start() {
|
|
|
568
614
|
delete newConfig.voice;
|
|
569
615
|
delete newConfig.key;
|
|
570
616
|
delete newConfig.folderID;
|
|
617
|
+
delete newConfig.cloud;
|
|
571
618
|
|
|
572
619
|
newConfig.convertedV1toV2 = true;
|
|
573
620
|
|
|
574
|
-
const configObj = await adapter.getForeignObjectAsync(
|
|
621
|
+
const configObj = await adapter.getForeignObjectAsync(`system.adapter.${adapter.namespace}`);
|
|
575
622
|
configObj.native = newConfig;
|
|
576
623
|
await adapter.setForeignObjectAsync(configObj._id, configObj);
|
|
577
624
|
// wait for restart
|
|
@@ -700,8 +747,8 @@ async function start() {
|
|
|
700
747
|
(adapter.config.type === 'mpd') ||
|
|
701
748
|
(adapter.config.type === 'googleHome')
|
|
702
749
|
) {
|
|
703
|
-
const
|
|
704
|
-
|
|
750
|
+
const obj = await adapter.getForeignObjectAsync(`system.adapter.${adapter.config.webInstance}`);
|
|
751
|
+
options.webLink = getWebLink(obj, adapter.config.webServer, adapter.config.webInstance);
|
|
705
752
|
|
|
706
753
|
// update web link on changes
|
|
707
754
|
await adapter.subscribeForeignObjectsAsync(`system.adapter.${adapter.config.webInstance}`);
|
|
@@ -724,6 +771,7 @@ async function start() {
|
|
|
724
771
|
options.addToQueue = addToQueue;
|
|
725
772
|
options.getCachedFileName = getCachedFileName;
|
|
726
773
|
options.isCached = isCached;
|
|
774
|
+
options.getWebLink = getWebLink;
|
|
727
775
|
options.MP3FILE = MP3FILE;
|
|
728
776
|
text2speech = new Text2Speech(adapter, options);
|
|
729
777
|
speech2device = new Speech2Device(adapter, options);
|
|
@@ -758,31 +806,34 @@ async function start() {
|
|
|
758
806
|
adapter.subscribeStates('*');
|
|
759
807
|
}
|
|
760
808
|
|
|
761
|
-
function
|
|
809
|
+
function getWebLink(obj, webServer, webInstance) {
|
|
810
|
+
let webLink = '';
|
|
762
811
|
if (obj && obj.native) {
|
|
763
|
-
|
|
812
|
+
webLink = 'http';
|
|
764
813
|
if (obj.native.auth) {
|
|
765
|
-
adapter.log.error(`Cannot use server "${
|
|
814
|
+
adapter.log.error(`Cannot use server "${obj._id}" with authentication for sonos/heos/chromecast. Select other or create another one.`);
|
|
766
815
|
} else {
|
|
767
816
|
if (obj.native.secure) {
|
|
768
|
-
|
|
817
|
+
webLink += 's';
|
|
769
818
|
}
|
|
770
|
-
|
|
819
|
+
webLink += '://';
|
|
771
820
|
if (obj.native.bind === 'localhost' || obj.native.bind === '127.0.0.1') {
|
|
772
|
-
adapter.log.error(`Selected web server "${
|
|
821
|
+
adapter.log.error(`Selected web server "${obj._id}" is only on local device available. Select other or create another one.`);
|
|
773
822
|
} else {
|
|
774
823
|
if (obj.native.bind === '0.0.0.0') {
|
|
775
|
-
|
|
824
|
+
webLink += webServer || adapter.config.webServer;
|
|
776
825
|
} else {
|
|
777
|
-
|
|
826
|
+
webLink += obj.native.bind;
|
|
778
827
|
}
|
|
779
828
|
}
|
|
780
829
|
|
|
781
|
-
|
|
830
|
+
webLink += `:${obj.native.port}`;
|
|
782
831
|
}
|
|
783
832
|
} else {
|
|
784
|
-
adapter.log.error(`Cannot read information about "${adapter.config.webInstance}". No web server is active`);
|
|
833
|
+
adapter.log.error(`Cannot read information about "${webInstance || adapter.config.webInstance}". No web server is active`);
|
|
785
834
|
}
|
|
835
|
+
|
|
836
|
+
return webLink;
|
|
786
837
|
}
|
|
787
838
|
|
|
788
839
|
async function main() {
|