iobroker.sayit 4.0.5 → 5.0.0

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
@@ -16,12 +16,12 @@ SayIt Adapter can convert text to speech and play it on some device.
16
16
  ## Configuration
17
17
  Actually, the following outputs are supported:
18
18
 
19
- - *Browser* - the text will be played by browser with opened `iobroker.vis` page. It is supported almost by every desktop browser and by few mobile Browsers.
19
+ - *Browser* - browser will play the text within opened `iobroker.vis` page. It is supported almost by every desktop browser and by few mobile Browsers.
20
20
 
21
21
  - *[Home24- MediaPlayer](http://www.home-24.net/index.php?app=media)* - the text will be sent and played to the Android device with Home24 - MediaPlayer installed. For this will be used build in Android text to speech engine. The port cannot be changed and set to 50000.
22
22
 
23
23
  - *Home24 - MediaPlayer and [FTP Server](https://play.google.com/store/apps/details?id=lutey.FTPServer)* - the text will be sent and played on the Android device with Home24 - MediaPlayer installed. For this will be used the Google text to speech engine. Generated mp3 file will be copied over FTP to an Android device and played with Home24 - MediaPlayer.
24
- Both apps have to have same home directories. (E.g. root directory of \"sd card\").
24
+ Both apps have to have same home directories. (E.g., root directory of \"sd card\").
25
25
 
26
26
  - *System* - the text will be played by OS, where the ioBroker adapter runs. Following OS are supported: Windows, linux, Mac OSx.
27
27
 
@@ -49,7 +49,7 @@ Online:
49
49
  To use Yandex.cloud you should register here: [https://cloud.yandex.ru/], install SpeechKIT API in the Cloud and get Auth Token and Folder ID as described in API instructions.
50
50
  - Cloud: To use Cloud voices you need configured and running `cloud` adapter or enter app-key directly in settings
51
51
  - Amazon Web Services Polly:
52
- To use AWS Polly voices you need to create an access key and secret key [here](https://console.aws.amazon.com/iam/home). The Amazon documentation can you find [here](http://docs.aws.amazon.com/general/latest/gr/managing-aws-access-keys.html).
52
+ To use AWS Polly voices, you need to create an access key and secret key [here](https://console.aws.amazon.com/iam/home). The Amazon documentation can you find [here](http://docs.aws.amazon.com/general/latest/gr/managing-aws-access-keys.html).
53
53
 
54
54
  Offline:
55
55
  - PicoTTS (linux only): English, German, Italian, Spanish, French;
@@ -73,17 +73,17 @@ More [info](https://developer.amazon.com/public/solutions/alexa/alexa-skills-kit
73
73
  ### System command
74
74
  If you have some program, that can play audio files locally or somewhere else, you can write this command here. E.g.
75
75
 
76
- ```myCustomPlayer --option```
76
+ `myCustomPlayer --option`
77
77
 
78
78
  If **System** output is selected, the `sayit` adapter will execute the following command on a local system:
79
79
 
80
- ```myCustomPlayer --option /opt/iobroker/node_modules/iobroker.sayit/say.mp3```
80
+ `myCustomPlayer --option /opt/iobroker/node_modules/iobroker.sayit/say.mp3`
81
81
 
82
82
  If file name must stay somewhere in the middle, you can use *%s* to specify where the file name must be placed:
83
83
 
84
- ```myCustomPlayer --option "%s" > /dev/null```
84
+ `myCustomPlayer --option "%s" > /dev/null`
85
85
 
86
- sayIt will make ```myCustomPlayer --option "/opt/iobroker/node_modules/iobroker.sayit/say.mp3" > /dev/null``` from it.
86
+ sayIt will make `myCustomPlayer --option "/opt/iobroker/node_modules/iobroker.sayit/say.mp3" > /dev/null` from it.
87
87
 
88
88
  ## Usage
89
89
  SayIt adapter cannot be used alone. It must be controlled from javascript adapter or from "vis" with specific widget.
@@ -95,20 +95,20 @@ After creation of adapter instance, you can find the following objects:
95
95
  E.g., you can enter here manually "No internet" and if ping to google.com is negative, write "No internet" to "tts.text" and it will be pronounced. Of course, cache must be enabled.
96
96
 
97
97
  State `tts.text` supports extended syntax, so the language/engine and volume can be defined together with text. It is used to enable multi-language text2speech engines.
98
- E.g., if adapter has engine "Google-english", it is possible with phrase ```de:Sag es``` to force using Google-Deutsch speech engine.
98
+ E.g., if adapter has engine `Google-english`, it is possible with phrase `de:Sag es` to force using Google-Deutsch speech engine.
99
99
 
100
- With ```ru;75;Погода хорошая``` we can force using russian language and volume 75%.
100
+ With `ru;75;Погода хорошая` we can force using russian language and volume 75%.
101
101
 
102
- You can specify the volume of announcement in percent from current or given volume (not from maximal). E.g., if command is ```de;75;Gutes Wetter```and "announce volume" is 50%, the announcement will be played with volume 38% from 100% possible.
102
+ You can specify the volume of announcement in percent from current or given volume (not from maximal). E.g., if command is `de;75;Gutes Wetter`and "announce volume" is 50%, the announcement will be played with volume 38% from 100% possible.
103
103
 
104
104
  The system command to play the mp3 file can be specified too. If you leave it blank, the default settings will be used: windows - `cmdmp3.exe`, OSX - `/usr/bin/afplay`, linux - `mpg321` or `omxplayer` (recommended).
105
105
 
106
- To install omxplayer write ```sudo apt-get install omxplayer``` or write ```sudo apt-get install mpg321``` to install mpg321.
106
+ To install omxplayer write `sudo apt-get install omxplayer` or write `sudo apt-get install mpg321` to install mpg321.
107
107
 
108
108
  **Note:** The default announce selection will be possible only after the start of the instance.
109
109
 
110
110
  ### Priorities
111
- To immediately pronounce the text despite the queued texts, you have 2 possibilities:
111
+ To immediately pronounce the text despite the queued texts, you have two possibilities:
112
112
  - place "!" as a first character in text, so this text will be pronounced immediately after the current one.
113
113
  - write true into "tts.clearQueue" state and the queue will be cleared. After that you can write a new text into `tts.text`, but all queued texts are thrown away.
114
114
 
@@ -267,6 +267,11 @@ The following values for engines are possible:
267
267
  ### **WORK IN PROGRESS**
268
268
  -->
269
269
  ## Changelog
270
+ ### 5.0.0 (2024-07-16)
271
+ * (mcm1957) Adapter requires admin v7 or newer now
272
+ * (mcm1957) Adapter requires jas-controller 5 or newer now
273
+ * (bluefox) Added possibility to play directly from states: `sayit.0/tts.userfiles/gong.mp3`
274
+
270
275
  ### 4.0.5 (2024-07-12)
271
276
  * (bluefox) Packages updated
272
277
  * (bluefox) Corrected playing in vis
@@ -337,7 +342,7 @@ The following values for engines are possible:
337
342
 
338
343
  ### 1.11.0 (2020-08-02)
339
344
  * (Apollon77) Move the generated mp3 file to an own directory in iobroker-data instead of inside node_modules (Hopefully not breaking)
340
- * (Apollon77) Change File write to use Sync methods to make sure they cannot run in parallel
345
+ * (Apollon77) Change the file writing to use Sync methods to make sure they cannot run in parallel
341
346
 
342
347
  ### 1.10.2 (2020-07-19)
343
348
  * (Apollon77) Crash case prevented (Sentry IOBROKER-SAYIT-8)
@@ -411,7 +416,7 @@ Changed type of top-level object to "meta" in order to comply with js-controller
411
416
 
412
417
  ### 1.6.3 (2017-10-04)
413
418
  * (bluefox) Code refactoring
414
- * (bluefox) Add google home as output
419
+ * (bluefox) Add Google Home as output
415
420
  * (bluefox) Remove ivona because not more supported
416
421
 
417
422
  ### 1.5.2 (2017-03-09)
@@ -422,11 +427,11 @@ Changed type of top-level object to "meta" in order to comply with js-controller
422
427
 
423
428
  ### 1.5.0 (2017-01-27)
424
429
  * (DarkChaos) Add AWS Polly as source
425
- * (bluefox) Add cloud as source
430
+ * (bluefox) Add cloud as a source
426
431
 
427
432
  ### 1.4.0 (2017-01-16)
428
433
  * (bluefox) fixed install problem
429
- * (bluefox) add PicoTTS as source
434
+ * (bluefox) add PicoTTS as a source
430
435
 
431
436
  ### 1.3.3 (2017-01-13)
432
437
  * (bluefox) show only installed instances in blockly
@@ -454,7 +459,7 @@ Changed type of top-level object to "meta" in order to comply with js-controller
454
459
  * (bluefox) Add omxplayer option
455
460
 
456
461
  ### 1.0.1 (2016-10-12)
457
- * (bluefox) support of blockly
462
+ * (bluefox) support for blockly
458
463
 
459
464
  ### 1.0.0 (2016-05-14)
460
465
  * (bluefox) Make the type of mp3 as file
@@ -476,7 +481,7 @@ Changed type of top-level object to "meta" in order to comply with js-controller
476
481
 
477
482
  ### 0.3.12 (2015-10-06)
478
483
  * (bluefox) fixed error if received mp3 file is too short
479
- * (bluefox) try to implement cache datapoint (you can use sayit.0.tts.cachetext to create cache for phrases and use sayit without internet)
484
+ * (bluefox) try to implement cache datapoint (you can use `sayit.0.tts.cachetext` to create cache for phrases and use sayit without internet)
480
485
 
481
486
  ### 0.3.11 (2015-08-03)
482
487
  * (bluefox) change google requests from http to https
@@ -494,7 +499,7 @@ Changed type of top-level object to "meta" in order to comply with js-controller
494
499
 
495
500
  ### 0.3.7 (2015-05-28)
496
501
  * (bluefox) fixed volume for an announcement
497
- * (bluefox) support for play files from internal filesystem, like "/sayit.0/tts.userfiles/myGong.mp3"
502
+ * (bluefox) support for play files from internal filesystem, like `/sayit.0/tts.userfiles/myGong.mp3`
498
503
 
499
504
  ### 0.3.6 (2015-03-24)
500
505
  * (bluefox) fixed error with volume by sonos
package/io-package.json CHANGED
@@ -1,8 +1,21 @@
1
1
  {
2
2
  "common": {
3
3
  "name": "sayit",
4
- "version": "4.0.5",
4
+ "version": "5.0.0",
5
5
  "news": {
6
+ "5.0.0": {
7
+ "en": "Adapter requires admin v7 or newer now\nAdapter requires jas-controller 5 or newer now\nAdded possibility to play directly from states: `sayit.0/tts.userfiles/gong.mp3`",
8
+ "de": "Adapter erfordert jetzt Admin v7 oder neuer\nAdapter erfordert jetzt Jas-Controller 5 oder neuer\nMöglichkeit, direkt aus Zuständen zu spielen: `sayit.0/tts.userfiles/gong.mp3`",
9
+ "ru": "Адаптер требует администратора v7 или новичка сейчас\nАдаптер требует jas-контроллер 5 или более новый сейчас\nДобавлена возможность играть непосредственно из государств: `sayit.0/tts.userfiles/gong.mp3`",
10
+ "pt": "Adapter requer admin v7 ou mais recente agora\nAdaptador requer jas-controller 5 ou mais recente agora\nAdicionado possibilidade de jogar diretamente de estados: `sayit.0/tts.userfiles/gong.mp3`",
11
+ "nl": "Adapter vereist admin v7 of nieuwer nu\nAdapter vereist jas-controller 5 of nieuwer nu\nToegevoegd mogelijkheid om direct te spelen vanuit staten: ",
12
+ "fr": "Adaptateur nécessite admin v7 ou plus récent maintenant\nAdaptateur nécessite jas-controller 5 ou plus récent maintenant\nAjout de la possibilité de jouer directement à partir des états: `sayit.0/tts.userfiles/gong.mp3`",
13
+ "it": "L'adattatore richiede ora admin v7 o più recente\nAdattatore richiede jas-controller 5 o più nuovo ora\nAggiunta possibilità di giocare direttamente dagli stati: `sayit.0/ttts.userfiles/gong.mp3`",
14
+ "es": "Adaptador requiere administración v7 o nuevo ahora\nAdaptador requiere jas-controller 5 o más nuevo ahora\nAñadido posibilidad de jugar directamente desde los estados: `sayit.0/tts.userfiles/gong.mp3`",
15
+ "pl": "Adapter wymaga admin v7 lub nowszych\nAdapter wymaga sterownika Jas- 5 lub nowszego teraz\nDodano możliwość gry bezpośrednio ze stanów: 'sayit.0 / tts.userfiles / gong.mp3'",
16
+ "uk": "Адаптер вимагає адміністратора v7 або новачка\nАдаптер вимагає jas-controller 5 або новіший зараз\n`sayit.0/tts.userfiles/gong.mp3`",
17
+ "zh-cn": "适配器需要管理员 v7 或者现在更新\n适配器需要JAS控制器 5或现在更新\n添加了直接从状态播放的可能性:`sayit.0/ts.userfiles/gong.mp3'"
18
+ },
6
19
  "4.0.5": {
7
20
  "en": "Packages updated\nCorrected playing in vis\nCorrected blockly\nCorrected upload of files",
8
21
  "de": "Pakete aktualisiert\nKorrigiertes Spielen in Vis\nBlockiert korrigiert\nKorrigierter Upload von Dateien",
@@ -80,19 +93,6 @@
80
93
  "pl": "Poprawione silniki z linkami stron internetowych",
81
94
  "uk": "Виправлені двигуни з веб-посиланням",
82
95
  "zh-cn": "连接网络的工程师"
83
- },
84
- "2.1.1": {
85
- "en": "Added support for Coqui TTS\nRenamed all configuration attributes",
86
- "de": "Unterstützung für Coqui TTS\nAlle Konfigurationsattribute umbenannt",
87
- "ru": "Добавлена поддержка Coqui TTS\nПереименованные все атрибуты конфигурации",
88
- "pt": "Adicionado suporte para Coqui TTS\nRenamed todos os atributos de configuração",
89
- "nl": "Verleende steun voor Coqui TTS\nVertaling:",
90
- "fr": "Ajout du soutien à Coqui TTS\nRenommé tous les attributs de configuration",
91
- "it": "Aggiunto il supporto per Coqui TTS\nRinominare tutti gli attributi di configurazione",
92
- "es": "Apoyo añadido para TTS Coqui\nRenombrado todos los atributos de configuración",
93
- "pl": "Wsparcie Coqui TTS\nNazwy wszystkich cech konfiguracji",
94
- "uk": "Додано підтримку Coqui TTS\nПерейменувати всі атрибути конфігурації",
95
- "zh-cn": "增加对共同采购技术的支持\n重新命名所有组合的属性"
96
96
  }
97
97
  },
98
98
  "title": "Text to speech",
@@ -160,7 +160,12 @@
160
160
  },
161
161
  "dependencies": [
162
162
  {
163
- "js-controller": ">=2.0.0"
163
+ "js-controller": ">=5.0.19"
164
+ }
165
+ ],
166
+ "globalDependencies": [
167
+ {
168
+ "admin": ">=7.0.13"
164
169
  }
165
170
  ]
166
171
  },
@@ -18,6 +18,27 @@ class Speech2Device {
18
18
  this.GHDefaultMediaReceiver = null;
19
19
  }
20
20
 
21
+ async getFileInStates(fileName) {
22
+ if (fileName.match(/^\/?[-_\w]+\.\d+\//)) {
23
+ if (fileName.startsWith('/')) {
24
+ fileName = fileName.substring(1);
25
+ }
26
+ // maybe it is "sayit.0/tts.userfiles/gong.mp3"
27
+ const parts = fileName.split('/');
28
+ const id = parts[0];
29
+ parts.splice(0, 1);
30
+ const file = parts.join('/');
31
+ let data;
32
+ try {
33
+ data = await this.adapter.readFileAsync(id, file);
34
+ return data?.file;
35
+ } catch (e) {
36
+ this.adapter.log.warn(`Cannot read length of file ${fileName}: ${e}`);
37
+ }
38
+ }
39
+ return null;
40
+ }
41
+
21
42
  async exec(cmd, args, cwd) {
22
43
  cp = cp || require('node:child_process');
23
44
  return new Promise((resolve, reject) => {
@@ -77,10 +98,24 @@ class Speech2Device {
77
98
  }
78
99
 
79
100
  // Function to fill the .tts.mp3 state
80
- async uploadToStates(text) {
101
+ async uploadToStates(text, saveToDisk) {
81
102
  let fileData;
82
103
  let fileName;
83
- if (Speech2Device.isPlayFile(text)) {
104
+ const data = await this.getFileInStates(text);
105
+ if (data) {
106
+ if (saveToDisk) {
107
+ try {
108
+ fs.writeFileSync(this.MP3FILE, data);
109
+ } catch (e) {
110
+ throw new Error(`Cannot save file "${this.MP3FILE}" to disk: ${e.toString()}`);
111
+ }
112
+ }
113
+
114
+ return {
115
+ fileInDB: `${text.startsWith('/') ? text : `/${text}`}?ts=${Date.now()}`,
116
+ fileOnDisk: saveToDisk ? this.MP3FILE : null,
117
+ };
118
+ } else if (Speech2Device.isPlayFile(text)) {
84
119
  fileName = path.normalize(text);
85
120
  } else {
86
121
  fileName = this.MP3FILE;
@@ -95,7 +130,10 @@ class Speech2Device {
95
130
  const file = `tts.${this.options.outFileExt}`;
96
131
 
97
132
  await this.adapter.writeFileAsync(this.adapter.namespace, `tts.${this.options.outFileExt}`, fileData);
98
- return {fileInDB: `/${this.adapter.namespace}/${file}?ts=${Date.now()}`, fileOnDisk: fileName};
133
+ return {
134
+ fileInDB: `/${this.adapter.namespace}/${file}?ts=${Date.now()}`,
135
+ fileOnDisk: fileName,
136
+ };
99
137
  }
100
138
 
101
139
  static isPlayFile(text) {
@@ -432,7 +470,7 @@ class Speech2Device {
432
470
  }
433
471
 
434
472
  async sayItMP24ftp(text, language, volume, duration, testOptions) {
435
- const result = await this.uploadToStates(text);
473
+ const result = await this.uploadToStates(text, true);
436
474
  const mp24Server = (testOptions && testOptions.mp24Server) || this.adapter.config.mp24Server;
437
475
  const ftpPort = (testOptions && testOptions.ftpPort) || this.adapter.config.ftpPort;
438
476
  const ftpUser = (testOptions && testOptions.ftpUser) || this.adapter.config.ftpUser;
@@ -492,7 +530,7 @@ class Speech2Device {
492
530
  os = os || require('node:os');
493
531
  cp = cp || require('node:child_process');
494
532
 
495
- const result = await this.uploadToStates(text);
533
+ const result = await this.uploadToStates(text, true);
496
534
  const systemCommand = (testOptions && testOptions.systemCommand) || this.adapter.config.systemCommand;
497
535
  const systemPlayer = (testOptions && testOptions.systemPlayer) || this.adapter.config.systemPlayer;
498
536
 
@@ -21,6 +21,27 @@ class Text2Speech {
21
21
  this.polly = null;
22
22
  }
23
23
 
24
+ async getFileInStates(fileName) {
25
+ if (fileName.match(/^\/?[-_\w]+\.\d+\//)) {
26
+ if (fileName.startsWith('/')) {
27
+ fileName = fileName.substring(1);
28
+ }
29
+ // maybe it is "sayit.0/tts.userfiles/gong.mp3"
30
+ const parts = fileName.split('/');
31
+ const id = parts[0];
32
+ parts.splice(0, 1);
33
+ const file = parts.join('/');
34
+ let data;
35
+ try {
36
+ data = await this.adapter.readFileAsync(id, file);
37
+ return data?.file;
38
+ } catch (e) {
39
+ this.adapter.log.warn(`Cannot read length of file ${fileName}: ${e}`);
40
+ }
41
+ }
42
+ return null;
43
+ }
44
+
24
45
  static splitText(text, max) {
25
46
  max = max || 70;
26
47
  if (text.length > max) {
@@ -405,6 +426,35 @@ class Text2Speech {
405
426
  }
406
427
  }
407
428
  } else {
429
+ const data = await this.getFileInStates(fileName);
430
+
431
+ if (data) {
432
+ if (fileName.endsWith('.mp3')) {
433
+ return new Promise(resolve =>
434
+ mp3Duration(data, (err, duration) => {
435
+ if (err) {
436
+ try {
437
+ const stat = fs.statSync(fileName);
438
+ const size = stat.size;
439
+ resolve(Math.ceil(size / 4096));
440
+ } catch (e) {
441
+ this.adapter.log.warn(`Cannot read length of file ${fileName}`);
442
+ resolve(0);
443
+ }
444
+ } else {
445
+ resolve(Math.ceil(duration));
446
+ }
447
+ }));
448
+ } else {
449
+ try {
450
+ const size = data.file.length;
451
+ return Math.ceil(size / 4096);
452
+ } catch (e) {
453
+ this.adapter.log.warn(`Cannot read length of file ${fileName}`);
454
+ return 0;
455
+ }
456
+ }
457
+ }
408
458
  return 0;
409
459
  }
410
460
  };
package/main.js CHANGED
@@ -402,7 +402,7 @@ async function processTasks() {
402
402
 
403
403
  language = language || (testOptions && testOptions.engine) || adapter.config.engine;
404
404
 
405
- // if no text => do not process
405
+ // if no text => does not process
406
406
  if (isGenerate && text.length && text2speech && speech2device) {
407
407
  // Check: may be it is a file from DB filesystem, like /vis.0/main/img/door-bell.mp3
408
408
  if (text[0] === '/') {
@@ -456,7 +456,7 @@ async function processTasks() {
456
456
 
457
457
  adapter.log.info(`saying: ${text}`);
458
458
 
459
- // If text first must be generated, and it is not the same as last one
459
+ // If a text first must be generated, and it is different from the last one
460
460
  if (!fileName && isGenerate) {
461
461
  // do not cache if test options active, to test the voice generation too
462
462
  if (sayLastGeneratedText !== `[${language}]${text}` || testOptions) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "iobroker.sayit",
3
- "version": "4.0.5",
3
+ "version": "5.0.0",
4
4
  "description": "Text to speech interface for ioBroker.",
5
5
  "author": {
6
6
  "name": "bluefox",