iobroker.sayit 4.0.4 → 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 +26 -20
- package/io-package.json +32 -27
- package/lib/speech2device.js +43 -5
- package/lib/text2speech.js +50 -0
- package/main.js +8 -6
- package/package.json +1 -1
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* -
|
|
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
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
84
|
+
`myCustomPlayer --option "%s" > /dev/null`
|
|
85
85
|
|
|
86
|
-
sayIt will make
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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,10 +267,16 @@ The following values for engines are possible:
|
|
|
267
267
|
### **WORK IN PROGRESS**
|
|
268
268
|
-->
|
|
269
269
|
## Changelog
|
|
270
|
-
###
|
|
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
|
+
|
|
275
|
+
### 4.0.5 (2024-07-12)
|
|
271
276
|
* (bluefox) Packages updated
|
|
272
277
|
* (bluefox) Corrected playing in vis
|
|
273
278
|
* (bluefox) Corrected blockly
|
|
279
|
+
* (bluefox) Corrected upload of files
|
|
274
280
|
|
|
275
281
|
### 4.0.1 (2024-05-25)
|
|
276
282
|
* (bluefox) Packages updated
|
|
@@ -336,7 +342,7 @@ The following values for engines are possible:
|
|
|
336
342
|
|
|
337
343
|
### 1.11.0 (2020-08-02)
|
|
338
344
|
* (Apollon77) Move the generated mp3 file to an own directory in iobroker-data instead of inside node_modules (Hopefully not breaking)
|
|
339
|
-
* (Apollon77) Change
|
|
345
|
+
* (Apollon77) Change the file writing to use Sync methods to make sure they cannot run in parallel
|
|
340
346
|
|
|
341
347
|
### 1.10.2 (2020-07-19)
|
|
342
348
|
* (Apollon77) Crash case prevented (Sentry IOBROKER-SAYIT-8)
|
|
@@ -410,7 +416,7 @@ Changed type of top-level object to "meta" in order to comply with js-controller
|
|
|
410
416
|
|
|
411
417
|
### 1.6.3 (2017-10-04)
|
|
412
418
|
* (bluefox) Code refactoring
|
|
413
|
-
* (bluefox) Add
|
|
419
|
+
* (bluefox) Add Google Home as output
|
|
414
420
|
* (bluefox) Remove ivona because not more supported
|
|
415
421
|
|
|
416
422
|
### 1.5.2 (2017-03-09)
|
|
@@ -421,11 +427,11 @@ Changed type of top-level object to "meta" in order to comply with js-controller
|
|
|
421
427
|
|
|
422
428
|
### 1.5.0 (2017-01-27)
|
|
423
429
|
* (DarkChaos) Add AWS Polly as source
|
|
424
|
-
* (bluefox) Add cloud as source
|
|
430
|
+
* (bluefox) Add cloud as a source
|
|
425
431
|
|
|
426
432
|
### 1.4.0 (2017-01-16)
|
|
427
433
|
* (bluefox) fixed install problem
|
|
428
|
-
* (bluefox) add PicoTTS as source
|
|
434
|
+
* (bluefox) add PicoTTS as a source
|
|
429
435
|
|
|
430
436
|
### 1.3.3 (2017-01-13)
|
|
431
437
|
* (bluefox) show only installed instances in blockly
|
|
@@ -453,7 +459,7 @@ Changed type of top-level object to "meta" in order to comply with js-controller
|
|
|
453
459
|
* (bluefox) Add omxplayer option
|
|
454
460
|
|
|
455
461
|
### 1.0.1 (2016-10-12)
|
|
456
|
-
* (bluefox) support
|
|
462
|
+
* (bluefox) support for blockly
|
|
457
463
|
|
|
458
464
|
### 1.0.0 (2016-05-14)
|
|
459
465
|
* (bluefox) Make the type of mp3 as file
|
|
@@ -475,7 +481,7 @@ Changed type of top-level object to "meta" in order to comply with js-controller
|
|
|
475
481
|
|
|
476
482
|
### 0.3.12 (2015-10-06)
|
|
477
483
|
* (bluefox) fixed error if received mp3 file is too short
|
|
478
|
-
* (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)
|
|
479
485
|
|
|
480
486
|
### 0.3.11 (2015-08-03)
|
|
481
487
|
* (bluefox) change google requests from http to https
|
|
@@ -493,7 +499,7 @@ Changed type of top-level object to "meta" in order to comply with js-controller
|
|
|
493
499
|
|
|
494
500
|
### 0.3.7 (2015-05-28)
|
|
495
501
|
* (bluefox) fixed volume for an announcement
|
|
496
|
-
* (bluefox) support for play files from internal filesystem, like
|
|
502
|
+
* (bluefox) support for play files from internal filesystem, like `/sayit.0/tts.userfiles/myGong.mp3`
|
|
497
503
|
|
|
498
504
|
### 0.3.6 (2015-03-24)
|
|
499
505
|
* (bluefox) fixed error with volume by sonos
|
package/io-package.json
CHANGED
|
@@ -1,20 +1,33 @@
|
|
|
1
1
|
{
|
|
2
2
|
"common": {
|
|
3
3
|
"name": "sayit",
|
|
4
|
-
"version": "
|
|
4
|
+
"version": "5.0.0",
|
|
5
5
|
"news": {
|
|
6
|
-
"
|
|
7
|
-
"en": "
|
|
8
|
-
"de": "
|
|
9
|
-
"ru": "
|
|
10
|
-
"pt": "
|
|
11
|
-
"nl": "
|
|
12
|
-
"fr": "
|
|
13
|
-
"it": "
|
|
14
|
-
"es": "
|
|
15
|
-
"pl": "
|
|
16
|
-
"uk": "
|
|
17
|
-
"zh-cn": "
|
|
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
|
+
},
|
|
19
|
+
"4.0.5": {
|
|
20
|
+
"en": "Packages updated\nCorrected playing in vis\nCorrected blockly\nCorrected upload of files",
|
|
21
|
+
"de": "Pakete aktualisiert\nKorrigiertes Spielen in Vis\nBlockiert korrigiert\nKorrigierter Upload von Dateien",
|
|
22
|
+
"ru": "Обновленные пакеты\nИсправленная игра в vis\nИсправлено блокно\nИсправленная загрузка файлов",
|
|
23
|
+
"pt": "Pacotes atualizados\nJogo correto em vis\nCorrigido em bloco\nUpload corrigido de arquivos",
|
|
24
|
+
"nl": "Pakketten bijgewerkt\nGecorrigeerd spelen in vis\nBloksgewijs gecorrigeerd\nGecorrigeerde upload van bestanden",
|
|
25
|
+
"fr": "Mise à jour des paquets\nCorrigé jouer dans vis\nCorrigé en bloc\nTéléchargement corrigé des fichiers",
|
|
26
|
+
"it": "Pacchetti aggiornati\nCorretto giocare in vis\nCorretto in blocco\nCaricamento corretto dei file",
|
|
27
|
+
"es": "Paquetes actualizados\nCorregido jugando en vis\nCorregido bloqueado\nCarga corregida de archivos",
|
|
28
|
+
"pl": "Aktualizacja pakietów\nPoprawione gry w vis\nPoprawione blokowane\nPoprawione przesyłanie plików",
|
|
29
|
+
"uk": "Пакети оновлені\nПравильна гра в віках\nВиправлено блоклі\nВиправлено завантаження файлів",
|
|
30
|
+
"zh-cn": "更新软件包\n已校正播放相对\n块状修正\n更正了文件的上传"
|
|
18
31
|
},
|
|
19
32
|
"4.0.1": {
|
|
20
33
|
"en": "Packages updated\nUsing the pre-calculated duration of the mp3 to wait long enough even for longer announcements",
|
|
@@ -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": ">=
|
|
163
|
+
"js-controller": ">=5.0.19"
|
|
164
|
+
}
|
|
165
|
+
],
|
|
166
|
+
"globalDependencies": [
|
|
167
|
+
{
|
|
168
|
+
"admin": ">=7.0.13"
|
|
164
169
|
}
|
|
165
170
|
]
|
|
166
171
|
},
|
package/lib/speech2device.js
CHANGED
|
@@ -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
|
-
|
|
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 {
|
|
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
|
|
package/lib/text2speech.js
CHANGED
|
@@ -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 =>
|
|
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] === '/') {
|
|
@@ -425,7 +425,7 @@ async function processTasks() {
|
|
|
425
425
|
}
|
|
426
426
|
|
|
427
427
|
if (!data) {
|
|
428
|
-
//
|
|
428
|
+
// maybe the file is from real FS
|
|
429
429
|
if (fs.existsSync(text)) {
|
|
430
430
|
try {
|
|
431
431
|
data = fs.readFileSync(text);
|
|
@@ -446,7 +446,7 @@ async function processTasks() {
|
|
|
446
446
|
} else {
|
|
447
447
|
fileName = MP3FILE;
|
|
448
448
|
}
|
|
449
|
-
fs.writeFileSync(fileName, data);
|
|
449
|
+
fs.writeFileSync(fileName, data.file ? data.file : data);
|
|
450
450
|
} catch (e) {
|
|
451
451
|
adapter.log.error(`Cannot write file "${MP3FILE}": ${e.toString()}`);
|
|
452
452
|
}
|
|
@@ -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
|
|
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) {
|
|
@@ -547,7 +547,9 @@ async function uploadFile(file) {
|
|
|
547
547
|
|
|
548
548
|
if (!data) {
|
|
549
549
|
try {
|
|
550
|
-
|
|
550
|
+
data = fs.readFileSync(path.join(`${__dirname}/mp3/`, file));
|
|
551
|
+
adapter.log.debug(`Upload file: ${path.join(`${__dirname}/mp3/`, file)} (${data.length} bytes`);
|
|
552
|
+
await adapter.writeFileAsync(adapter.namespace, `tts.userfiles/${file}`, data);
|
|
551
553
|
} catch (e) {
|
|
552
554
|
adapter.log.error(`Cannot write file "${__dirname}/mp3/${file}": ${e.toString()}`);
|
|
553
555
|
}
|
|
@@ -596,7 +598,7 @@ async function prepareAnnounceFiles(config) {
|
|
|
596
598
|
const data = await adapter.readFileAsync(adapter.namespace, `tts.userfiles/${fileName}`);
|
|
597
599
|
if (data) {
|
|
598
600
|
try {
|
|
599
|
-
fs.writeFileSync(path.join(__dirname, fileName), data);
|
|
601
|
+
fs.writeFileSync(path.join(__dirname, fileName), data.file ? data.file : data);
|
|
600
602
|
config.announce = path.join(__dirname, fileName);
|
|
601
603
|
} catch (e) {
|
|
602
604
|
adapter.log.error(`Cannot write file: ${e.toString()}`);
|