iobroker.sayit 2.1.1 → 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 CHANGED
@@ -265,6 +265,9 @@ Following values for engines are possible:
265
265
  ### **WORK IN PROGRESS**
266
266
  -->
267
267
  ## Changelog
268
+ ### 2.1.2 (2023-03-27)
269
+ * (bluefox) Corrected engines with web-link
270
+
268
271
  ### 2.1.1 (2023-03-24)
269
272
  * (Jey-Cee) Added support for Coqui TTS
270
273
  * (bluefox) Renamed all configuration attributes
@@ -265,6 +265,15 @@
265
265
  "sm": 6,
266
266
  "md": 4,
267
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"
268
277
  }
269
278
  }
270
279
  },
package/io-package.json CHANGED
@@ -1,8 +1,21 @@
1
1
  {
2
2
  "common": {
3
3
  "name": "sayit",
4
- "version": "2.1.1",
4
+ "version": "2.1.2",
5
5
  "news": {
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
+ },
6
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",
@@ -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",
@@ -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
- await this.adapter.setForeignStateAsync('vis.0.control.instance', this.adapter.config.browserInstance);
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 sayItSonos(text, language, volume, duration) {
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 fileName = `${volume ? `${volume};` : ''}${this.options.webLink}${result.fileInDB}`;
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 (this.adapter.config.sonosDevice && this.options.webLink) {
129
- this.adapter.log.info(`Set "${this.adapter.config.sonosDevice}.tts: ${fileName}`);
130
- await this.adapter.setForeignStateAsync(`${this.adapter.config.sonosDevice}.tts`, fileName);
131
- } else if (this.options.webLink) {
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};` : ''}${this.options.webLink}${result.fileInDB}`;
171
+ const fileName = `${volume ? `${volume};` : ''}${webLink}${result.fileInDB}`;
172
+ const heosDevice = (testOptions && testOptions.heosDevice) || this.adapter.config.heosDevice;
151
173
 
152
- if (this.adapter.config.heosDevice && this.options.webLink) {
153
- this.adapter.log.info(`Set "${this.adapter.config.heosDevice}.tts: ${fileName}`);
154
- await this.adapter.setForeignStateAsync(`${this.adapter.config.heosDevice}.tts`, fileName);
155
- } else if (this.options.webLink) {
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};` : ''}${this.options.webLink}${result.fileInDB}`;
197
+ const fileName = `${volume ? `${volume};` : ''}${webLink}${result.fileInDB}`;
174
198
 
175
- if (this.adapter.config.mpdInstance && this.options.webLink) {
176
- this.adapter.log.info(`Set "${this.adapter.config.mpdInstance}.say: ${fileName}`);
177
- await this.adapter.setForeignStateAsync(`${this.adapter.config.mpdInstance}.say`, fileName);
178
- } else if (this.options.webLink) {
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: `${this.options.webLink}${result.fileInDB}`,
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 (this.adapter.config.chromecastDevice && this.options.webLink) {
207
- const chromecastAnnouncementDev = `${this.adapter.config.chromecastDevice}.player.announcement`;
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 (this.adapter.config.googleHomeServer && this.options.webLink) {
313
- const url = `${this.options.webLink}${result.fileInDB}`;
314
- this.adapter.log.debug(`Send to google home "${this.adapter.config.googleHomeServer}": ${url}`);
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(this.adapter.config.googleHomeServer, url, volume);
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 (this.adapter.config.mp24Server) {
356
+ if (mp24Server) {
328
357
  if (!Speech2Device.isPlayFile(text)) {
329
358
  // say
330
- this.adapter.log.debug(`Request MediaPlayer24 "http://${this.adapter.config.mp24Server}:50000/tts=${encodeURI(text)}"`);
359
+ this.adapter.log.debug(`Request MediaPlayer24 "http://${mp24Server}:50000/tts=${encodeURI(text)}"`);
331
360
  try {
332
- const response = await axios.get(`http://${this.adapter.config.mp24Server}:50000/tts=${encodeURI(text)}`);
333
- this.adapter.log.debug(`Response from MediaPlayer24 "${this.adapter.config.mp24Server}": ${response.data}`);
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 "${this.adapter.config.mp24Server}": ${e.message}`);
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://${this.adapter.config.mp24Server}:50000/track=${text}`);
346
- this.adapter.log.debug(`Response from MediaPlayer24 "${this.adapter.config.mp24Server}": ${response.data}`);
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 "${this.adapter.config.mp24Server}": ${e.message}`);
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 (this.adapter.config.ftpPort && this.adapter.config.mp24Server) {
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: this.adapter.config.mp24Server,
371
- port: parseInt(this.adapter.config.ftpPort, 10), // defaults to 21
372
- user: this.adapter.config.ftpUser || 'anonymous', // defaults to 'anonymous'
373
- pass: this.adapter.config.ftpPassword || 'anonymous', // defaults to 'anonymous'
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://${this.adapter.config.mp24Server}:50000/track=${fileNameOnFTP}`);
389
- this.adapter.log.debug(`Response from MediaPlayer24 "${this.adapter.config.mp24Server}": ${response.data}`);
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 "${this.adapter.config.mp24Server}": ${e.message}`);
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 ${this.adapter.config.mp24Server}:${this.adapter.config.port}`);
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 (this.adapter.config.systemCommand) {
462
+ if (systemCommand) {
428
463
  // custom command
429
- if (this.adapter.config.systemCommand.includes('%s')) {
430
- cmd = this.adapter.config.systemCommand.replace('%s', result.fileOnDisk);
464
+ if (systemCommand.includes('%s')) {
465
+ cmd = systemCommand.replace('%s', result.fileOnDisk);
431
466
  } else {
432
467
  if (p.match(/^win/)) {
433
- cmd = `${this.adapter.config.systemCommand} "${result.fileOnDisk}"`;
468
+ cmd = `${systemCommand} "${result.fileOnDisk}"`;
434
469
  } else {
435
- cmd = `${this.adapter.config.systemCommand} ${result.fileOnDisk}`;
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 (this.adapter.config.systemPlayer === 'omxplayer') {
481
+ if (systemPlayer === 'omxplayer') {
447
482
  cmd = `omxplayer -o local ${result.fileOnDisk}`;
448
- } else if (this.adapter.config.systemPlayer === 'mpg321') {
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' && this.adapter.config.player !== 'mpg321') {
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`, ['setsysvolume', level], true);
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
  }
@@ -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(`http://${this.options.host}${this.options.path}\nCannot get file: ${buf.toString()}`);
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', voice.replace(' Premium', ''));
142
- params.append('folderId', this.adapter.config.yandexFolderID || '');
143
- if (this.adapter.config.yandexEmotion !== 'none' && this.adapter.config.yandexEmotion) {
144
- params.append('emotion', this.adapter.config.yandexEmotion);
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 ${this.adapter.config.yandexKey}`,
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=${this.adapter.config.yandexVoice}&key=${this.adapter.config.yandexKey}&text=${encodeURI(text.trim())}`;
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 (this.adapter.config.yandexEmotion && this.adapter.config.yandexEmotion !== 'none') {
175
- url += `&emotion=${this.adapter.config.yandexEmotion}`;
184
+ if (yandexEmotion && yandexEmotion !== 'none') {
185
+ url += `&emotion=${yandexEmotion}`;
176
186
  }
177
- if (this.adapter.config.yandexDrunk === 'true' || this.adapter.config.yandexDrunk === true) {
187
+ if (yandexDrunk === 'true' || yandexDrunk === true) {
178
188
  url += '&drunk=true';
179
189
  }
180
- if (this.adapter.config.yandexIll === 'true' || this.adapter.config.yandexIll === true) {
190
+ if (yandexIll === 'true' || yandexIll === true) {
181
191
  url += '&ill=true';
182
192
  }
183
- if (this.adapter.config.yandexRobot === 'true' || this.adapter.config.yandexRobot === true) {
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: this.adapter.config.awsAccessKey,
199
- secretAccessKey: this.adapter.config.awsSecretKey,
200
- region: this.adapter.config.awsRegion,
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 obj = await this.adapter.getForeignObjectAsync(`system.this.adapter.${this.adapter.config.cloudInstance}`);
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, volume);
392
+ await this.sayItGetSpeechYandex(text, language, null, testOptions);
377
393
  } else if (engine === 'yandexCloud') {
378
- await this.sayItGetSpeechYandexCloud(text, language, volume);
394
+ await this.sayItGetSpeechYandexCloud(text, language, null, testOptions);
379
395
  } else if (engine === 'polly') {
380
- await this.sayItGetSpeechPolly(text, language, volume);
396
+ await this.sayItGetSpeechPolly(text, language, null, testOptions);
381
397
  } else if (engine === 'coquiTTS') {
382
- await this.sayItGetSpeechCoquiTTS(text, language, volume);
398
+ await this.sayItGetSpeechCoquiTTS(text, language, null, testOptions);
383
399
  } else if (engine === 'cloud') {
384
- await this.sayItGetSpeechCloud(text, language, volume);
400
+ await this.sayItGetSpeechCloud(text, language, null, testOptions);
385
401
  } else if (engine === 'PicoTTS') {
386
- await this.sayItGetSpeechPicoTTS(text, language, volume);
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
- applyWebSettings(obj);
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
- } else {
385
- try {
386
- fileName = await text2speech.sayItGetSpeech(text, language, volume);
387
- sayLastGeneratedText = `[${language}]${text}`;
388
- } catch (e) {
389
- fileName = null;
390
- adapter.log.error(`Cannot generate speech file: ${e}`);
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 {
@@ -405,21 +442,27 @@ async function processTasks() {
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
- adapter.log.error(`Cannot play file: ${e}`);
455
+ error = `Cannot play file: ${e}`;
456
+ adapter.log.error(error);
419
457
  }
420
458
  await adapter.setStateAsync('tts.playing', false, true);
421
459
  }
422
460
 
461
+ if (tasks[0] && tasks[0].testOptions && tasks[0].testOptions.callback) {
462
+ tasks[0].testOptions.callback(error);
463
+ tasks[0].testOptions.callback = null;
464
+ }
465
+
423
466
  tasks.shift();
424
467
 
425
468
  if (tasks.length) {
@@ -704,8 +747,8 @@ async function start() {
704
747
  (adapter.config.type === 'mpd') ||
705
748
  (adapter.config.type === 'googleHome')
706
749
  ) {
707
- const settings = await adapter.getForeignObjectAsync(`system.adapter.${adapter.config.webInstance}`);
708
- applyWebSettings(null, settings);
750
+ const obj = await adapter.getForeignObjectAsync(`system.adapter.${adapter.config.webInstance}`);
751
+ options.webLink = getWebLink(obj, adapter.config.webServer, adapter.config.webInstance);
709
752
 
710
753
  // update web link on changes
711
754
  await adapter.subscribeForeignObjectsAsync(`system.adapter.${adapter.config.webInstance}`);
@@ -728,6 +771,7 @@ async function start() {
728
771
  options.addToQueue = addToQueue;
729
772
  options.getCachedFileName = getCachedFileName;
730
773
  options.isCached = isCached;
774
+ options.getWebLink = getWebLink;
731
775
  options.MP3FILE = MP3FILE;
732
776
  text2speech = new Text2Speech(adapter, options);
733
777
  speech2device = new Speech2Device(adapter, options);
@@ -762,31 +806,34 @@ async function start() {
762
806
  adapter.subscribeStates('*');
763
807
  }
764
808
 
765
- function applyWebSettings(obj) {
809
+ function getWebLink(obj, webServer, webInstance) {
810
+ let webLink = '';
766
811
  if (obj && obj.native) {
767
- options.webLink = 'http';
812
+ webLink = 'http';
768
813
  if (obj.native.auth) {
769
- adapter.log.error(`Cannot use server "${adapter.config.webInstance}" with authentication for sonos/heos/chromecast. Select other or create another one.`);
814
+ adapter.log.error(`Cannot use server "${obj._id}" with authentication for sonos/heos/chromecast. Select other or create another one.`);
770
815
  } else {
771
816
  if (obj.native.secure) {
772
- options.webLink += 's';
817
+ webLink += 's';
773
818
  }
774
- options.webLink += '://';
819
+ webLink += '://';
775
820
  if (obj.native.bind === 'localhost' || obj.native.bind === '127.0.0.1') {
776
- adapter.log.error(`Selected web server "${adapter.config.webInstance}" is only on local device available. Select other or create another one.`);
821
+ adapter.log.error(`Selected web server "${obj._id}" is only on local device available. Select other or create another one.`);
777
822
  } else {
778
823
  if (obj.native.bind === '0.0.0.0') {
779
- options.webLink += adapter.config.webServer;
824
+ webLink += webServer || adapter.config.webServer;
780
825
  } else {
781
- options.webLink += obj.native.bind;
826
+ webLink += obj.native.bind;
782
827
  }
783
828
  }
784
829
 
785
- options.webLink += `:${obj.native.port}`;
830
+ webLink += `:${obj.native.port}`;
786
831
  }
787
832
  } else {
788
- 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`);
789
834
  }
835
+
836
+ return webLink;
790
837
  }
791
838
 
792
839
  async function main() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "iobroker.sayit",
3
- "version": "2.1.1",
3
+ "version": "2.1.2",
4
4
  "description": "Text to speech interface for ioBroker.",
5
5
  "author": {
6
6
  "name": "bluefox",