iobroker.assistant 1.6.0 → 1.7.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 +4 -0
- package/admin/i18n/de.json +4 -1
- package/admin/i18n/en.json +4 -1
- package/admin/i18n/es.json +4 -1
- package/admin/i18n/fr.json +4 -1
- package/admin/i18n/it.json +4 -1
- package/admin/i18n/nl.json +4 -1
- package/admin/i18n/pl.json +4 -1
- package/admin/i18n/pt.json +4 -1
- package/admin/i18n/ru.json +4 -1
- package/admin/i18n/uk.json +4 -1
- package/admin/i18n/zh-cn.json +4 -1
- package/admin/jsonConfig.json +16 -0
- package/build/lib/piAgent.js +33 -0
- package/build/lib/piAgent.js.map +1 -1
- package/build/lib/voice/aws.js +9 -2
- package/build/lib/voice/aws.js.map +1 -1
- package/build/lib/voice/azure.js +6 -2
- package/build/lib/voice/azure.js.map +1 -1
- package/build/lib/voice/engines.js +34 -2
- package/build/lib/voice/engines.js.map +1 -1
- package/build/lib/voice/openrouter.js +5 -3
- package/build/lib/voice/openrouter.js.map +1 -1
- package/build/lib/voice/piper.js +6 -1
- package/build/lib/voice/piper.js.map +1 -1
- package/build/lib/voice/speechLanguage.js +217 -0
- package/build/lib/voice/speechLanguage.js.map +1 -0
- package/build/main.js +35 -1
- package/build/main.js.map +1 -1
- package/io-package.json +15 -14
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -237,6 +237,10 @@ train it twice.
|
|
|
237
237
|
Placeholder for the next version (at the beginning of the line):
|
|
238
238
|
### **WORK IN PROGRESS**
|
|
239
239
|
-->
|
|
240
|
+
### 1.7.0 (2026-11-12)
|
|
241
|
+
* (@sadam6752-tech) A Piper voice set for one language is only used for it, a Russian answer on a German satellite gets a Russian voice instead of being spelled letter by letter; the language pi-agent 0.10.1 reports for an answer is used for its voice (#27)
|
|
242
|
+
* (@GermanBluefox) The language of an answer is taken for every voice: UDP and Wyoming satellites, announcements and the voice test too, and Azure, AWS and OpenRouter voices set for one language are only used for it. New table "Voice per answer language" in the Voice tab (e.g. ru → ru_RU-dmitri-medium); Piper loads its voices at the start. The language pi-agent reports is also found for its questions to confirm, and a mark that the letters contradict is not believed
|
|
243
|
+
|
|
240
244
|
### 1.6.0 (2026-11-10)
|
|
241
245
|
* (@GermanBluefox) Local LLM: new tab "Local models" to keep several models, pick the active one (saving restarts the instance), choose the folder, see sizes and free space, download presets (with description, size and languages) or own GGUF links, delete models, and see statistics per model (questions, answers, hand-overs, failures, tokens/s, time to the first token, load time). A benchmark on the host checks that the loaded model hands home questions over and answers general ones correctly. The model folder can be picked on the disk of the host (Admin 8.3.11+)
|
|
242
246
|
* (@GermanBluefox) Settings split into topic tabs: AI, Commands, Local models, Devices (with the permissions), Services, Triggers, Voice, Satellites (with the connections of the satellites) and Chat as the last one; rarely needed options (max tokens and system prompt, ffmpeg, end of speech and diagnosis) are in sections that open on a click
|
package/admin/i18n/de.json
CHANGED
|
@@ -259,5 +259,8 @@
|
|
|
259
259
|
"End of speech and diagnosis": "Sprachende und Diagnose",
|
|
260
260
|
"Voice is off. Turn it on in the tab \"Voice\" to connect satellites.": "Sprache ist aus. Schalte sie im Reiter „Sprache“ ein, um Satelliten zu verbinden.",
|
|
261
261
|
"Status": "Status",
|
|
262
|
-
"ffmpeg": "ffmpeg"
|
|
262
|
+
"ffmpeg": "ffmpeg",
|
|
263
|
+
"Voice per answer language": "Stimme pro Antwortsprache",
|
|
264
|
+
"An answer in another language than the satellites listen in (e.g. pi-agent answers a Russian question in Russian) is spoken with the voice of its language, not spelled letter by letter by the voice above. Without a row the provider's default voice for that language is used. Voice names of the speech output provider, e.g. ru → ru_RU-dmitri-medium (Piper), ru-RU-SvetlanaNeural (Azure), Tatyana (AWS).": "Eine Antwort in einer anderen Sprache als der der Satelliten (z. B. beantwortet pi-agent eine russische Frage auf Russisch) wird mit einer Stimme dieser Sprache gesprochen, statt von der Stimme oben Buchstabe für Buchstabe vorgelesen zu werden. Ohne Zeile nimmt der Anbieter seine Standardstimme für die Sprache. Stimmnamen des Sprachausgabe-Anbieters, z. B. ru → ru_RU-dmitri-medium (Piper), ru-RU-SvetlanaNeural (Azure), Tatyana (AWS).",
|
|
265
|
+
"Language (e.g. ru)": "Sprache (z. B. ru)"
|
|
263
266
|
}
|
package/admin/i18n/en.json
CHANGED
|
@@ -259,5 +259,8 @@
|
|
|
259
259
|
"End of speech and diagnosis": "End of speech and diagnosis",
|
|
260
260
|
"Voice is off. Turn it on in the tab \"Voice\" to connect satellites.": "Voice is off. Turn it on in the tab \"Voice\" to connect satellites.",
|
|
261
261
|
"Status": "Status",
|
|
262
|
-
"ffmpeg": "ffmpeg"
|
|
262
|
+
"ffmpeg": "ffmpeg",
|
|
263
|
+
"Voice per answer language": "Voice per answer language",
|
|
264
|
+
"An answer in another language than the satellites listen in (e.g. pi-agent answers a Russian question in Russian) is spoken with the voice of its language, not spelled letter by letter by the voice above. Without a row the provider's default voice for that language is used. Voice names of the speech output provider, e.g. ru → ru_RU-dmitri-medium (Piper), ru-RU-SvetlanaNeural (Azure), Tatyana (AWS).": "An answer in another language than the satellites listen in (e.g. pi-agent answers a Russian question in Russian) is spoken with the voice of its language, not spelled letter by letter by the voice above. Without a row the provider's default voice for that language is used. Voice names of the speech output provider, e.g. ru → ru_RU-dmitri-medium (Piper), ru-RU-SvetlanaNeural (Azure), Tatyana (AWS).",
|
|
265
|
+
"Language (e.g. ru)": "Language (e.g. ru)"
|
|
263
266
|
}
|
package/admin/i18n/es.json
CHANGED
|
@@ -259,5 +259,8 @@
|
|
|
259
259
|
"End of speech and diagnosis": "Fin del habla y diagnóstico",
|
|
260
260
|
"Voice is off. Turn it on in the tab \"Voice\" to connect satellites.": "La voz está desactivada. Actívala en la pestaña «Voz» para conectar satélites.",
|
|
261
261
|
"Status": "Estado",
|
|
262
|
-
"ffmpeg": "ffmpeg"
|
|
262
|
+
"ffmpeg": "ffmpeg",
|
|
263
|
+
"Voice per answer language": "Voice per answer language",
|
|
264
|
+
"An answer in another language than the satellites listen in (e.g. pi-agent answers a Russian question in Russian) is spoken with the voice of its language, not spelled letter by letter by the voice above. Without a row the provider's default voice for that language is used. Voice names of the speech output provider, e.g. ru → ru_RU-dmitri-medium (Piper), ru-RU-SvetlanaNeural (Azure), Tatyana (AWS).": "An answer in another language than the satellites listen in (e.g. pi-agent answers a Russian question in Russian) is spoken with the voice of its language, not spelled letter by letter by the voice above. Without a row the provider's default voice for that language is used. Voice names of the speech output provider, e.g. ru → ru_RU-dmitri-medium (Piper), ru-RU-SvetlanaNeural (Azure), Tatyana (AWS).",
|
|
265
|
+
"Language (e.g. ru)": "Language (e.g. ru)"
|
|
263
266
|
}
|
package/admin/i18n/fr.json
CHANGED
|
@@ -259,5 +259,8 @@
|
|
|
259
259
|
"End of speech and diagnosis": "Fin de la parole et diagnostic",
|
|
260
260
|
"Voice is off. Turn it on in the tab \"Voice\" to connect satellites.": "La voix est désactivée. Activez-la dans l’onglet « Voix » pour connecter des satellites.",
|
|
261
261
|
"Status": "État",
|
|
262
|
-
"ffmpeg": "ffmpeg"
|
|
262
|
+
"ffmpeg": "ffmpeg",
|
|
263
|
+
"Voice per answer language": "Voice per answer language",
|
|
264
|
+
"An answer in another language than the satellites listen in (e.g. pi-agent answers a Russian question in Russian) is spoken with the voice of its language, not spelled letter by letter by the voice above. Without a row the provider's default voice for that language is used. Voice names of the speech output provider, e.g. ru → ru_RU-dmitri-medium (Piper), ru-RU-SvetlanaNeural (Azure), Tatyana (AWS).": "An answer in another language than the satellites listen in (e.g. pi-agent answers a Russian question in Russian) is spoken with the voice of its language, not spelled letter by letter by the voice above. Without a row the provider's default voice for that language is used. Voice names of the speech output provider, e.g. ru → ru_RU-dmitri-medium (Piper), ru-RU-SvetlanaNeural (Azure), Tatyana (AWS).",
|
|
265
|
+
"Language (e.g. ru)": "Language (e.g. ru)"
|
|
263
266
|
}
|
package/admin/i18n/it.json
CHANGED
|
@@ -259,5 +259,8 @@
|
|
|
259
259
|
"End of speech and diagnosis": "Fine del parlato e diagnosi",
|
|
260
260
|
"Voice is off. Turn it on in the tab \"Voice\" to connect satellites.": "La voce è disattivata. Attivala nella scheda «Voce» per collegare i satelliti.",
|
|
261
261
|
"Status": "Stato",
|
|
262
|
-
"ffmpeg": "ffmpeg"
|
|
262
|
+
"ffmpeg": "ffmpeg",
|
|
263
|
+
"Voice per answer language": "Voice per answer language",
|
|
264
|
+
"An answer in another language than the satellites listen in (e.g. pi-agent answers a Russian question in Russian) is spoken with the voice of its language, not spelled letter by letter by the voice above. Without a row the provider's default voice for that language is used. Voice names of the speech output provider, e.g. ru → ru_RU-dmitri-medium (Piper), ru-RU-SvetlanaNeural (Azure), Tatyana (AWS).": "An answer in another language than the satellites listen in (e.g. pi-agent answers a Russian question in Russian) is spoken with the voice of its language, not spelled letter by letter by the voice above. Without a row the provider's default voice for that language is used. Voice names of the speech output provider, e.g. ru → ru_RU-dmitri-medium (Piper), ru-RU-SvetlanaNeural (Azure), Tatyana (AWS).",
|
|
265
|
+
"Language (e.g. ru)": "Language (e.g. ru)"
|
|
263
266
|
}
|
package/admin/i18n/nl.json
CHANGED
|
@@ -259,5 +259,8 @@
|
|
|
259
259
|
"End of speech and diagnosis": "Einde van spraak en diagnose",
|
|
260
260
|
"Voice is off. Turn it on in the tab \"Voice\" to connect satellites.": "Spraak staat uit. Zet het aan op het tabblad ‘Stem’ om satellieten te verbinden.",
|
|
261
261
|
"Status": "Status",
|
|
262
|
-
"ffmpeg": "ffmpeg"
|
|
262
|
+
"ffmpeg": "ffmpeg",
|
|
263
|
+
"Voice per answer language": "Voice per answer language",
|
|
264
|
+
"An answer in another language than the satellites listen in (e.g. pi-agent answers a Russian question in Russian) is spoken with the voice of its language, not spelled letter by letter by the voice above. Without a row the provider's default voice for that language is used. Voice names of the speech output provider, e.g. ru → ru_RU-dmitri-medium (Piper), ru-RU-SvetlanaNeural (Azure), Tatyana (AWS).": "An answer in another language than the satellites listen in (e.g. pi-agent answers a Russian question in Russian) is spoken with the voice of its language, not spelled letter by letter by the voice above. Without a row the provider's default voice for that language is used. Voice names of the speech output provider, e.g. ru → ru_RU-dmitri-medium (Piper), ru-RU-SvetlanaNeural (Azure), Tatyana (AWS).",
|
|
265
|
+
"Language (e.g. ru)": "Language (e.g. ru)"
|
|
263
266
|
}
|
package/admin/i18n/pl.json
CHANGED
|
@@ -259,5 +259,8 @@
|
|
|
259
259
|
"End of speech and diagnosis": "Koniec mowy i diagnostyka",
|
|
260
260
|
"Voice is off. Turn it on in the tab \"Voice\" to connect satellites.": "Głos jest wyłączony. Włącz go na karcie „Głos”, aby połączyć satelity.",
|
|
261
261
|
"Status": "Stan",
|
|
262
|
-
"ffmpeg": "ffmpeg"
|
|
262
|
+
"ffmpeg": "ffmpeg",
|
|
263
|
+
"Voice per answer language": "Voice per answer language",
|
|
264
|
+
"An answer in another language than the satellites listen in (e.g. pi-agent answers a Russian question in Russian) is spoken with the voice of its language, not spelled letter by letter by the voice above. Without a row the provider's default voice for that language is used. Voice names of the speech output provider, e.g. ru → ru_RU-dmitri-medium (Piper), ru-RU-SvetlanaNeural (Azure), Tatyana (AWS).": "An answer in another language than the satellites listen in (e.g. pi-agent answers a Russian question in Russian) is spoken with the voice of its language, not spelled letter by letter by the voice above. Without a row the provider's default voice for that language is used. Voice names of the speech output provider, e.g. ru → ru_RU-dmitri-medium (Piper), ru-RU-SvetlanaNeural (Azure), Tatyana (AWS).",
|
|
265
|
+
"Language (e.g. ru)": "Language (e.g. ru)"
|
|
263
266
|
}
|
package/admin/i18n/pt.json
CHANGED
|
@@ -259,5 +259,8 @@
|
|
|
259
259
|
"End of speech and diagnosis": "Fim da fala e diagnóstico",
|
|
260
260
|
"Voice is off. Turn it on in the tab \"Voice\" to connect satellites.": "A voz está desativada. Ative-a no separador «Voz» para ligar satélites.",
|
|
261
261
|
"Status": "Estado",
|
|
262
|
-
"ffmpeg": "ffmpeg"
|
|
262
|
+
"ffmpeg": "ffmpeg",
|
|
263
|
+
"Voice per answer language": "Voice per answer language",
|
|
264
|
+
"An answer in another language than the satellites listen in (e.g. pi-agent answers a Russian question in Russian) is spoken with the voice of its language, not spelled letter by letter by the voice above. Without a row the provider's default voice for that language is used. Voice names of the speech output provider, e.g. ru → ru_RU-dmitri-medium (Piper), ru-RU-SvetlanaNeural (Azure), Tatyana (AWS).": "An answer in another language than the satellites listen in (e.g. pi-agent answers a Russian question in Russian) is spoken with the voice of its language, not spelled letter by letter by the voice above. Without a row the provider's default voice for that language is used. Voice names of the speech output provider, e.g. ru → ru_RU-dmitri-medium (Piper), ru-RU-SvetlanaNeural (Azure), Tatyana (AWS).",
|
|
265
|
+
"Language (e.g. ru)": "Language (e.g. ru)"
|
|
263
266
|
}
|
package/admin/i18n/ru.json
CHANGED
|
@@ -259,5 +259,8 @@
|
|
|
259
259
|
"End of speech and diagnosis": "Конец речи и диагностика",
|
|
260
260
|
"Voice is off. Turn it on in the tab \"Voice\" to connect satellites.": "Голос выключен. Включите его на вкладке «Голос», чтобы подключить спутники.",
|
|
261
261
|
"Status": "Статус",
|
|
262
|
-
"ffmpeg": "ffmpeg"
|
|
262
|
+
"ffmpeg": "ffmpeg",
|
|
263
|
+
"Voice per answer language": "Голос для языка ответа",
|
|
264
|
+
"An answer in another language than the satellites listen in (e.g. pi-agent answers a Russian question in Russian) is spoken with the voice of its language, not spelled letter by letter by the voice above. Without a row the provider's default voice for that language is used. Voice names of the speech output provider, e.g. ru → ru_RU-dmitri-medium (Piper), ru-RU-SvetlanaNeural (Azure), Tatyana (AWS).": "Ответ на другом языке, чем язык сателлитов (например, pi-agent отвечает на русский вопрос по-русски), озвучивается голосом этого языка, а не читается по буквам голосом, выбранным выше. Без строки берётся стандартный голос провайдера для этого языка. Имена голосов провайдера синтеза речи, например ru → ru_RU-dmitri-medium (Piper), ru-RU-SvetlanaNeural (Azure), Tatyana (AWS).",
|
|
265
|
+
"Language (e.g. ru)": "Язык (например, ru)"
|
|
263
266
|
}
|
package/admin/i18n/uk.json
CHANGED
|
@@ -259,5 +259,8 @@
|
|
|
259
259
|
"End of speech and diagnosis": "Кінець мовлення та діагностика",
|
|
260
260
|
"Voice is off. Turn it on in the tab \"Voice\" to connect satellites.": "Голос вимкнено. Увімкніть його на вкладці «Голос», щоб підключити супутники.",
|
|
261
261
|
"Status": "Стан",
|
|
262
|
-
"ffmpeg": "ffmpeg"
|
|
262
|
+
"ffmpeg": "ffmpeg",
|
|
263
|
+
"Voice per answer language": "Voice per answer language",
|
|
264
|
+
"An answer in another language than the satellites listen in (e.g. pi-agent answers a Russian question in Russian) is spoken with the voice of its language, not spelled letter by letter by the voice above. Without a row the provider's default voice for that language is used. Voice names of the speech output provider, e.g. ru → ru_RU-dmitri-medium (Piper), ru-RU-SvetlanaNeural (Azure), Tatyana (AWS).": "An answer in another language than the satellites listen in (e.g. pi-agent answers a Russian question in Russian) is spoken with the voice of its language, not spelled letter by letter by the voice above. Without a row the provider's default voice for that language is used. Voice names of the speech output provider, e.g. ru → ru_RU-dmitri-medium (Piper), ru-RU-SvetlanaNeural (Azure), Tatyana (AWS).",
|
|
265
|
+
"Language (e.g. ru)": "Language (e.g. ru)"
|
|
263
266
|
}
|
package/admin/i18n/zh-cn.json
CHANGED
|
@@ -259,5 +259,8 @@
|
|
|
259
259
|
"End of speech and diagnosis": "语音结束检测与诊断",
|
|
260
260
|
"Voice is off. Turn it on in the tab \"Voice\" to connect satellites.": "语音已关闭。请在“嗓音”选项卡中开启,以连接卫星。",
|
|
261
261
|
"Status": "状态",
|
|
262
|
-
"ffmpeg": "ffmpeg"
|
|
262
|
+
"ffmpeg": "ffmpeg",
|
|
263
|
+
"Voice per answer language": "Voice per answer language",
|
|
264
|
+
"An answer in another language than the satellites listen in (e.g. pi-agent answers a Russian question in Russian) is spoken with the voice of its language, not spelled letter by letter by the voice above. Without a row the provider's default voice for that language is used. Voice names of the speech output provider, e.g. ru → ru_RU-dmitri-medium (Piper), ru-RU-SvetlanaNeural (Azure), Tatyana (AWS).": "An answer in another language than the satellites listen in (e.g. pi-agent answers a Russian question in Russian) is spoken with the voice of its language, not spelled letter by letter by the voice above. Without a row the provider's default voice for that language is used. Voice names of the speech output provider, e.g. ru → ru_RU-dmitri-medium (Piper), ru-RU-SvetlanaNeural (Azure), Tatyana (AWS).",
|
|
265
|
+
"Language (e.g. ru)": "Language (e.g. ru)"
|
|
263
266
|
}
|
package/admin/jsonConfig.json
CHANGED
|
@@ -1494,6 +1494,22 @@
|
|
|
1494
1494
|
"lg": 5,
|
|
1495
1495
|
"xl": 5
|
|
1496
1496
|
},
|
|
1497
|
+
"ttsVoices": {
|
|
1498
|
+
"newLine": true,
|
|
1499
|
+
"type": "table",
|
|
1500
|
+
"label": "Voice per answer language",
|
|
1501
|
+
"help": "An answer in another language than the satellites listen in (e.g. pi-agent answers a Russian question in Russian) is spoken with the voice of its language, not spelled letter by letter by the voice above. Without a row the provider's default voice for that language is used. Voice names of the speech output provider, e.g. ru → ru_RU-dmitri-medium (Piper), ru-RU-SvetlanaNeural (Azure), Tatyana (AWS).",
|
|
1502
|
+
"hidden": "!data.voiceEnabled",
|
|
1503
|
+
"xs": 12,
|
|
1504
|
+
"sm": 12,
|
|
1505
|
+
"md": 12,
|
|
1506
|
+
"lg": 12,
|
|
1507
|
+
"xl": 12,
|
|
1508
|
+
"items": [
|
|
1509
|
+
{ "type": "text", "attr": "language", "title": "Language (e.g. ru)", "width": "30%" },
|
|
1510
|
+
{ "type": "text", "attr": "voice", "title": "Voice", "width": "70%" }
|
|
1511
|
+
]
|
|
1512
|
+
},
|
|
1497
1513
|
"_ffmpegPanel": {
|
|
1498
1514
|
"type": "panel",
|
|
1499
1515
|
"collapsable": true,
|
package/build/lib/piAgent.js
CHANGED
|
@@ -15,6 +15,9 @@
|
|
|
15
15
|
* With "Confirmation by text in sendTo conversations", pi-agent answers a write it may not do unasked with a
|
|
16
16
|
* question ending in `[[LISTEN]]`, and the next `ask` of the conversation is the yes or no. `language` makes it
|
|
17
17
|
* ask that question in the language the satellite listens in.
|
|
18
|
+
*
|
|
19
|
+
* pi-agent 0.10.1+ also answers with `language`, the language it wrote the answer in; the voice that speaks the
|
|
20
|
+
* answer is chosen by it ({@link PiAgentHarness.languageOf}).
|
|
18
21
|
*/
|
|
19
22
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
23
|
exports.PiAgentHarness = exports.PI_AGENT_TIMEOUT_SEC = exports.PI_AGENT_MAX_INSTRUCTIONS = void 0;
|
|
@@ -49,11 +52,25 @@ function composeInstructions(required, optional) {
|
|
|
49
52
|
function conversationOf(source) {
|
|
50
53
|
return (source || 'default').replace(/\//g, '_').slice(0, 100);
|
|
51
54
|
}
|
|
55
|
+
/**
|
|
56
|
+
* An answer as the TTS gets it: the assistant takes the control markers ([[LISTEN]] after a question to confirm,
|
|
57
|
+
* [[DONE]]) out before speaking, so the language is kept under the text without them.
|
|
58
|
+
*/
|
|
59
|
+
function answerKey(text) {
|
|
60
|
+
return String(text || '')
|
|
61
|
+
.replace(/\[\[[A-Z]+\]\]/gi, ' ')
|
|
62
|
+
.replace(/\s+/g, ' ')
|
|
63
|
+
.trim();
|
|
64
|
+
}
|
|
65
|
+
/** How many answers {@link PiAgentHarness.languageOf} remembers. */
|
|
66
|
+
const KEPT_LANGUAGES = 50;
|
|
52
67
|
class PiAgentHarness {
|
|
53
68
|
host;
|
|
54
69
|
instance;
|
|
55
70
|
timeoutMs;
|
|
56
71
|
seq = 0;
|
|
72
|
+
/** Language pi-agent reported per answer text (pi-agent 0.10.1+), for the voice that speaks it. */
|
|
73
|
+
languages = new Map();
|
|
57
74
|
constructor(host,
|
|
58
75
|
/** e.g. `pi-agent.0` */
|
|
59
76
|
instance, timeoutMs = exports.PI_AGENT_TIMEOUT_SEC * 1000) {
|
|
@@ -90,8 +107,24 @@ class PiAgentHarness {
|
|
|
90
107
|
if (!answer) {
|
|
91
108
|
throw new Error(`${this.instance} gave no answer`);
|
|
92
109
|
}
|
|
110
|
+
const language = typeof result?.language === 'string' ? result.language.trim().toLowerCase() : '';
|
|
111
|
+
if (/^[a-z]{2,3}(-[a-z]{2,4})?$/.test(language)) {
|
|
112
|
+
const key = answerKey(answer);
|
|
113
|
+
this.languages.delete(key);
|
|
114
|
+
this.languages.set(key, language);
|
|
115
|
+
if (this.languages.size > KEPT_LANGUAGES) {
|
|
116
|
+
this.languages.delete(this.languages.keys().next().value);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
93
119
|
return answer;
|
|
94
120
|
}
|
|
121
|
+
/**
|
|
122
|
+
* The language pi-agent wrote an answer in (`ru`, `de` …), '' when it did not say (older pi-agent, or the model
|
|
123
|
+
* left its mark out). The answer travels as plain text through the tiers; this finds its language again by text.
|
|
124
|
+
*/
|
|
125
|
+
languageOf(answer) {
|
|
126
|
+
return this.languages.get(answerKey(answer)) || '';
|
|
127
|
+
}
|
|
95
128
|
}
|
|
96
129
|
exports.PiAgentHarness = PiAgentHarness;
|
|
97
130
|
//# sourceMappingURL=piAgent.js.map
|
package/build/lib/piAgent.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"piAgent.js","sourceRoot":"","sources":["../../src/lib/piAgent.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;GAgBG;;;AAiDH,kDAaC;AAGD,wCAEC;AA/DD,8FAA8F;AACjF,QAAA,yBAAyB,GAAG,KAAK,CAAC;AAE/C,wFAAwF;AAC3E,QAAA,oBAAoB,GAAG,EAAE,CAAC;AAkCvC;;;;;;GAMG;AACH,SAAgB,mBAAmB,CAAC,QAAkB,EAAE,QAAkB;IACtE,MAAM,MAAM,GAAG,CAAC,GAAG,QAAQ,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC;IAC7C,MAAM,KAAK,GAAG,QAAQ,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;IACvC,IAAI,OAAO,GAAG,CAAC,CAAC;IAChB,OAAO,KAAK,CAAC,MAAM,EAAE,CAAC;QAClB,MAAM,IAAI,GAAG,CAAC,GAAG,MAAM,EAAE,GAAG,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,MAAM,MAAM,GAAG,OAAO,MAAM,EAAE,MAAM,KAAK,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QAC9E,IAAI,CAAC,MAAM,EAAE,CAAC;YACV,MAAM,IAAI,KAAK,CAAC,GAAG,IAAI,CAAC,QAAQ,iBAAiB,CAAC,CAAC;QACvD,CAAC;QACD,OAAO,MAAM,CAAC;IAClB,CAAC;CACJ;AA9CD,wCA8CC","sourcesContent":["/**\n * The adapter `pi-agent` as the cloud tier (\"harness\"): instead of running its own tool loop, the assistant\n * hands the question to a pi-agent instance via `sendTo(<instance>, 'ask', …)`. pi-agent stores every model\n * and tool call as a checkpoint before it runs (an interrupted request continues after a restart, a write is\n * never repeated), enforces its own write permissions and confirmations, and can use the system-wide AI\n * settings of admin — none of which the built-in `LlmAgent` does.\n *\n * Each request source (satellite, `chat`, `telegram:<user>`) gets a conversation of its own in pi-agent\n * (`conversation`), so two rooms do not see each other's follow-ups. The source-independent part of the\n * prompt (style, follow-up marker, memory, device list) goes along as the `instructions` of that\n * conversation; what changes every turn (time, weather, presence) is prepended to the question.\n * pi-agent 0.3.0 and older ignore both fields and answer everything in their root conversation.\n *\n * With \"Confirmation by text in sendTo conversations\", pi-agent answers a write it may not do unasked with a\n * question ending in `[[LISTEN]]`, and the next `ask` of the conversation is the yes or no. `language` makes it\n * ask that question in the language the satellite listens in.\n */\n\nimport type { ImageInput } from './media';\n\n/** Longest instructions pi-agent accepts for a conversation; anything beyond is cut there. */\nexport const PI_AGENT_MAX_INSTRUCTIONS = 20000;\n\n/** Default for `piAgentTimeoutSec`: a tool loop with several reads can take a while. */\nexport const PI_AGENT_TIMEOUT_SEC = 60;\n\n/** The part of the adapter this module needs (kept small so tests can fake it). */\nexport interface PiAgentHost {\n sendToAsync(instance: string, command: string, message: unknown, options?: { timeout?: number }): Promise<unknown>;\n getForeignStateAsync(id: string): Promise<ioBroker.State | null | undefined>;\n}\n\nexport interface PiAgentRequest {\n /** The text pi-agent answers: context lines + the question. */\n text: string;\n /** Conversation of the caller, e.g. the satellite name. */\n conversation: string;\n /** Instructions of that conversation. */\n instructions: string;\n /**\n * Language the user speaks, e.g. `ru`. pi-agent asks its questions to confirm in it; older versions ask in the\n * system language, and a satellite listening in Russian does not hear a German \"Ja\" (the STT returns nothing).\n */\n language?: string;\n /**\n * Pictures that came with the question (`{ data: base64, mimeType }`, the form of pi-ai's `ImageContent`).\n * Versions of pi-agent before image support ignore them; the text then says that pictures came along.\n */\n images?: ImageInput[];\n /**\n * Only for a request from a voice satellite: its id under `assistant.N.satellites.*`, and the full id of its `tts`\n * state. Writing text there speaks it on that satellite — so pi-agent can answer later where it was asked (a\n * reminder, the end of a background task). Chat and Telegram requests have neither.\n */\n satellite?: string;\n tts?: string;\n}\n\n/**\n * Join instruction blocks, leaving out optional ones from the end until the result fits into pi-agent's\n * limit — pi-agent would cut the text in the middle, and a half device list is worse than none.\n *\n * @param required blocks that always go along (style, follow-up marker)\n * @param optional blocks in order of importance (memory before the device list)\n */\nexport function composeInstructions(required: string[], optional: string[]): { text: string; dropped: number } {\n const blocks = [...required.filter(Boolean)];\n const extra = optional.filter(Boolean);\n let dropped = 0;\n while (extra.length) {\n const text = [...blocks, ...extra].join('\\n\\n');\n if (text.length <= PI_AGENT_MAX_INSTRUCTIONS) {\n return { text, dropped };\n }\n extra.pop();\n dropped++;\n }\n return { text: blocks.join('\\n\\n').slice(0, PI_AGENT_MAX_INSTRUCTIONS), dropped };\n}\n\n/** Conversation name for a request source; pi-agent uses \"/\" as separator in its keys. */\nexport function conversationOf(source: string): string {\n return (source || 'default').replace(/\\//g, '_').slice(0, 100);\n}\n\nexport class PiAgentHarness {\n private seq = 0;\n\n public constructor(\n private readonly host: PiAgentHost,\n /** e.g. `pi-agent.0` */\n public readonly instance: string,\n private readonly timeoutMs: number = PI_AGENT_TIMEOUT_SEC * 1000,\n ) {}\n\n /**\n * Ask pi-agent. Fails fast when the instance is not running (otherwise the caller would wait for the whole\n * timeout), and turns pi-agent's `{error}` into an exception so the caller can fall back to the local model.\n */\n public async ask(req: PiAgentRequest): Promise<string> {\n const alive = await this.host.getForeignStateAsync(`system.adapter.${this.instance}.alive`);\n if (!alive?.val) {\n throw new Error(`${this.instance} is not running`);\n }\n // Unique per request: pi-agent answers a repeated requestId only once.\n const requestId = `assistant-${Date.now().toString(36)}-${(++this.seq).toString(36)}`;\n const result = (await this.host.sendToAsync(\n this.instance,\n 'ask',\n {\n text: req.text,\n conversation: conversationOf(req.conversation),\n instructions: req.instructions,\n ...(req.language ? { language: req.language } : {}),\n ...(req.images?.length ? { images: req.images } : {}),\n ...(req.satellite ? { satellite: req.satellite } : {}),\n ...(req.tts ? { tts: req.tts } : {}),\n requestId,\n },\n { timeout: this.timeoutMs },\n )) as { answer?: unknown; error?: unknown } | null | undefined;\n if (result?.error) {\n const error = typeof result.error === 'string' ? result.error : JSON.stringify(result.error);\n throw new Error(`${this.instance}: ${error}`);\n }\n const answer = typeof result?.answer === 'string' ? result.answer.trim() : '';\n if (!answer) {\n throw new Error(`${this.instance} gave no answer`);\n }\n return answer;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"piAgent.js","sourceRoot":"","sources":["../../src/lib/piAgent.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;GAmBG;;;AAiDH,kDAaC;AAGD,wCAEC;AA/DD,8FAA8F;AACjF,QAAA,yBAAyB,GAAG,KAAK,CAAC;AAE/C,wFAAwF;AAC3E,QAAA,oBAAoB,GAAG,EAAE,CAAC;AAkCvC;;;;;;GAMG;AACH,SAAgB,mBAAmB,CAAC,QAAkB,EAAE,QAAkB;IACtE,MAAM,MAAM,GAAG,CAAC,GAAG,QAAQ,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC;IAC7C,MAAM,KAAK,GAAG,QAAQ,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;IACvC,IAAI,OAAO,GAAG,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CAAC,SAAS,CAAC,IAAI,EAAE,CAAC,IAAI,EAAE,CAAC,KAAe,CAAC,CAAC;YACxE,CAAC;QACL,CAAC;QACD,OAAO,MAAM,CAAC;IAClB,CAAC;IAED;;;OAGG;IACI,UAAU,CAAC,MAAc;QAC5B,OAAO,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,CAAC;IACvD,CAAC;CACJ;AAjED,wCAiEC","sourcesContent":["/**\n * The adapter `pi-agent` as the cloud tier (\"harness\"): instead of running its own tool loop, the assistant\n * hands the question to a pi-agent instance via `sendTo(<instance>, 'ask', …)`. pi-agent stores every model\n * and tool call as a checkpoint before it runs (an interrupted request continues after a restart, a write is\n * never repeated), enforces its own write permissions and confirmations, and can use the system-wide AI\n * settings of admin — none of which the built-in `LlmAgent` does.\n *\n * Each request source (satellite, `chat`, `telegram:<user>`) gets a conversation of its own in pi-agent\n * (`conversation`), so two rooms do not see each other's follow-ups. The source-independent part of the\n * prompt (style, follow-up marker, memory, device list) goes along as the `instructions` of that\n * conversation; what changes every turn (time, weather, presence) is prepended to the question.\n * pi-agent 0.3.0 and older ignore both fields and answer everything in their root conversation.\n *\n * With \"Confirmation by text in sendTo conversations\", pi-agent answers a write it may not do unasked with a\n * question ending in `[[LISTEN]]`, and the next `ask` of the conversation is the yes or no. `language` makes it\n * ask that question in the language the satellite listens in.\n *\n * pi-agent 0.10.1+ also answers with `language`, the language it wrote the answer in; the voice that speaks the\n * answer is chosen by it ({@link PiAgentHarness.languageOf}).\n */\n\nimport type { ImageInput } from './media';\n\n/** Longest instructions pi-agent accepts for a conversation; anything beyond is cut there. */\nexport const PI_AGENT_MAX_INSTRUCTIONS = 20000;\n\n/** Default for `piAgentTimeoutSec`: a tool loop with several reads can take a while. */\nexport const PI_AGENT_TIMEOUT_SEC = 60;\n\n/** The part of the adapter this module needs (kept small so tests can fake it). */\nexport interface PiAgentHost {\n sendToAsync(instance: string, command: string, message: unknown, options?: { timeout?: number }): Promise<unknown>;\n getForeignStateAsync(id: string): Promise<ioBroker.State | null | undefined>;\n}\n\nexport interface PiAgentRequest {\n /** The text pi-agent answers: context lines + the question. */\n text: string;\n /** Conversation of the caller, e.g. the satellite name. */\n conversation: string;\n /** Instructions of that conversation. */\n instructions: string;\n /**\n * Language the user speaks, e.g. `ru`. pi-agent asks its questions to confirm in it; older versions ask in the\n * system language, and a satellite listening in Russian does not hear a German \"Ja\" (the STT returns nothing).\n */\n language?: string;\n /**\n * Pictures that came with the question (`{ data: base64, mimeType }`, the form of pi-ai's `ImageContent`).\n * Versions of pi-agent before image support ignore them; the text then says that pictures came along.\n */\n images?: ImageInput[];\n /**\n * Only for a request from a voice satellite: its id under `assistant.N.satellites.*`, and the full id of its `tts`\n * state. Writing text there speaks it on that satellite — so pi-agent can answer later where it was asked (a\n * reminder, the end of a background task). Chat and Telegram requests have neither.\n */\n satellite?: string;\n tts?: string;\n}\n\n/**\n * Join instruction blocks, leaving out optional ones from the end until the result fits into pi-agent's\n * limit — pi-agent would cut the text in the middle, and a half device list is worse than none.\n *\n * @param required blocks that always go along (style, follow-up marker)\n * @param optional blocks in order of importance (memory before the device list)\n */\nexport function composeInstructions(required: string[], optional: string[]): { text: string; dropped: number } {\n const blocks = [...required.filter(Boolean)];\n const extra = optional.filter(Boolean);\n let dropped = 0;\n while (extra.length) {\n const text = [...blocks, ...extra].join('\\n\\n');\n if (text.length <= PI_AGENT_MAX_INSTRUCTIONS) {\n return { text, dropped };\n }\n extra.pop();\n dropped++;\n }\n return { text: blocks.join('\\n\\n').slice(0, PI_AGENT_MAX_INSTRUCTIONS), dropped };\n}\n\n/** Conversation name for a request source; pi-agent uses \"/\" as separator in its keys. */\nexport function conversationOf(source: string): string {\n return (source || 'default').replace(/\\//g, '_').slice(0, 100);\n}\n\n/**\n * An answer as the TTS gets it: the assistant takes the control markers ([[LISTEN]] after a question to confirm,\n * [[DONE]]) out before speaking, so the language is kept under the text without them.\n */\nfunction answerKey(text: string): string {\n return String(text || '')\n .replace(/\\[\\[[A-Z]+\\]\\]/gi, ' ')\n .replace(/\\s+/g, ' ')\n .trim();\n}\n\n/** How many answers {@link PiAgentHarness.languageOf} remembers. */\nconst KEPT_LANGUAGES = 50;\n\nexport class PiAgentHarness {\n private seq = 0;\n /** Language pi-agent reported per answer text (pi-agent 0.10.1+), for the voice that speaks it. */\n private readonly languages = new Map<string, string>();\n\n public constructor(\n private readonly host: PiAgentHost,\n /** e.g. `pi-agent.0` */\n public readonly instance: string,\n private readonly timeoutMs: number = PI_AGENT_TIMEOUT_SEC * 1000,\n ) {}\n\n /**\n * Ask pi-agent. Fails fast when the instance is not running (otherwise the caller would wait for the whole\n * timeout), and turns pi-agent's `{error}` into an exception so the caller can fall back to the local model.\n */\n public async ask(req: PiAgentRequest): Promise<string> {\n const alive = await this.host.getForeignStateAsync(`system.adapter.${this.instance}.alive`);\n if (!alive?.val) {\n throw new Error(`${this.instance} is not running`);\n }\n // Unique per request: pi-agent answers a repeated requestId only once.\n const requestId = `assistant-${Date.now().toString(36)}-${(++this.seq).toString(36)}`;\n const result = (await this.host.sendToAsync(\n this.instance,\n 'ask',\n {\n text: req.text,\n conversation: conversationOf(req.conversation),\n instructions: req.instructions,\n ...(req.language ? { language: req.language } : {}),\n ...(req.images?.length ? { images: req.images } : {}),\n ...(req.satellite ? { satellite: req.satellite } : {}),\n ...(req.tts ? { tts: req.tts } : {}),\n requestId,\n },\n { timeout: this.timeoutMs },\n )) as { answer?: unknown; error?: unknown; language?: unknown } | null | undefined;\n if (result?.error) {\n const error = typeof result.error === 'string' ? result.error : JSON.stringify(result.error);\n throw new Error(`${this.instance}: ${error}`);\n }\n const answer = typeof result?.answer === 'string' ? result.answer.trim() : '';\n if (!answer) {\n throw new Error(`${this.instance} gave no answer`);\n }\n const language = typeof result?.language === 'string' ? result.language.trim().toLowerCase() : '';\n if (/^[a-z]{2,3}(-[a-z]{2,4})?$/.test(language)) {\n const key = answerKey(answer);\n this.languages.delete(key);\n this.languages.set(key, language);\n if (this.languages.size > KEPT_LANGUAGES) {\n this.languages.delete(this.languages.keys().next().value as string);\n }\n }\n return answer;\n }\n\n /**\n * The language pi-agent wrote an answer in (`ru`, `de` …), '' when it did not say (older pi-agent, or the model\n * left its mark out). The answer travels as plain text through the tiers; this finds its language again by text.\n */\n public languageOf(answer: string): string {\n return this.languages.get(answerKey(answer)) || '';\n }\n}\n"]}
|
package/build/lib/voice/aws.js
CHANGED
|
@@ -72,11 +72,15 @@ class AwsStt {
|
|
|
72
72
|
exports.AwsStt = AwsStt;
|
|
73
73
|
class AwsTts {
|
|
74
74
|
voice;
|
|
75
|
+
language;
|
|
75
76
|
client;
|
|
76
77
|
constructor(creds,
|
|
77
78
|
/** Polly VoiceId (e.g. 'Vicki', 'Tatyana'); empty → default per language. */
|
|
78
|
-
voice
|
|
79
|
+
voice,
|
|
80
|
+
/** Language the voice is set for ('' = every language); Polly voice ids do not tell it. */
|
|
81
|
+
language = '') {
|
|
79
82
|
this.voice = voice;
|
|
83
|
+
this.language = language;
|
|
80
84
|
this.client = new client_polly_1.PollyClient({
|
|
81
85
|
region: creds.region,
|
|
82
86
|
credentials: { accessKeyId: creds.accessKeyId, secretAccessKey: creds.secretAccessKey },
|
|
@@ -91,7 +95,10 @@ class AwsTts {
|
|
|
91
95
|
}
|
|
92
96
|
async speak(text, lang, textType) {
|
|
93
97
|
const iso = (lang || 'en').split('-')[0].toLowerCase();
|
|
94
|
-
const
|
|
98
|
+
const home = (this.language || '').split('-')[0].toLowerCase();
|
|
99
|
+
// the set voice only for its language: Vicki reads no Russian, Tatyana does
|
|
100
|
+
const own = this.voice && (!home || iso === home || !DEFAULT_POLLY_VOICE[iso]) ? this.voice : '';
|
|
101
|
+
const voice = own || DEFAULT_POLLY_VOICE[iso] || this.voice || 'Joanna';
|
|
95
102
|
const resp = await this.client.send(new client_polly_1.SynthesizeSpeechCommand({
|
|
96
103
|
Text: text,
|
|
97
104
|
TextType: textType,
|
|
@@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EAAE,CAAC;QACvD,MAAM,IAAI,GAAG,CAAC,IAAI,CAAC,QAAQ,IAAI,EAAE,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,CAAC;QAC/D,4EAA4E;QAC5E,MAAM,GAAG,GAAG,IAAI,CAAC,KAAK,IAAI,CAAC,CAAC,IAAI,IAAI,GAAG,KAAK,IAAI,IAAI,CAAC,mBAAmB,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC;QACjG,MAAM,KAAK,GAAG,GAAG,IAAI,mBAAmB,CAAC,GAAG,CAAC,IAAI,IAAI,CAAC,KAAK,IAAI,QAAQ,CAAC;QACxE,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,IAAI,CAC/B,IAAI,sCAAuB,CAAC;YACxB,IAAI,EAAE,IAAI;YACV,QAAQ,EAAE,QAAQ;YAClB,YAAY,EAAE,KAAK,EAAE,wCAAwC;YAC7D,UAAU,EAAE,OAAO;YACnB,OAAO,EAAE,KAAgB;SAC5B,CAAC,CACL,CAAC;QACF,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC;YACpB,MAAM,IAAI,KAAK,CAAC,gCAAgC,CAAC,CAAC;QACtD,CAAC;QACD,MAAM,KAAK,GAAG,MAAM,IAAI,CAAC,WAAW,CAAC,oBAAoB,EAAE,CAAC;QAC5D,OAAO,EAAE,GAAG,EAAE,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,UAAU,EAAE,KAAK,EAAE,CAAC;IAC1D,CAAC;CACJ;AA9CD,wBA8CC","sourcesContent":["/**\n * AWS speech engines: STT via Amazon Transcribe (streaming) and TTS via Amazon Polly.\n * Credentials: accessKeyId + secretAccessKey + region.\n */\nimport {\n PollyClient,\n SynthesizeSpeechCommand,\n DescribeVoicesCommand,\n type VoiceId,\n type LanguageCode as PollyLanguageCode,\n} from '@aws-sdk/client-polly';\nimport {\n TranscribeStreamingClient,\n StartStreamTranscriptionCommand,\n type AudioStream,\n type LanguageCode,\n} from '@aws-sdk/client-transcribe-streaming';\nimport { isoToLocale } from './lang';\nimport type { SttEngine } from './stt';\nimport type { TtsEngine, TtsResult } from './tts';\n\nexport interface AwsCreds {\n accessKeyId: string;\n secretAccessKey: string;\n region: string;\n}\n\n/** Reasonable default Polly voice per language when none is configured. */\nconst DEFAULT_POLLY_VOICE: Record<string, string> = {\n de: 'Vicki',\n en: 'Joanna',\n ru: 'Tatyana',\n fr: 'Lea',\n it: 'Bianca',\n es: 'Lucia',\n nl: 'Laura',\n pl: 'Ewa',\n pt: 'Ines',\n};\n\n/** ~100 ms of 16 kHz mono 16-bit PCM per Transcribe audio chunk. */\nconst STT_CHUNK_BYTES = 3200;\n\n/** List available Polly voice ids, optionally filtered by language (locale, e.g. 'de-DE'). */\nexport async function listPollyVoices(creds: AwsCreds, languageCode: string): Promise<string[]> {\n const client = new PollyClient({\n region: creds.region,\n credentials: { accessKeyId: creds.accessKeyId, secretAccessKey: creds.secretAccessKey },\n });\n const res = await client.send(\n new DescribeVoicesCommand(languageCode ? { LanguageCode: languageCode as PollyLanguageCode } : {}),\n );\n return (res.Voices || []).map(v => v.Id).filter((id): id is VoiceId => !!id);\n}\n\nexport class AwsStt implements SttEngine {\n private readonly client: TranscribeStreamingClient;\n\n constructor(creds: AwsCreds) {\n this.client = new TranscribeStreamingClient({\n region: creds.region,\n credentials: { accessKeyId: creds.accessKeyId, secretAccessKey: creds.secretAccessKey },\n });\n }\n\n // Note: the SttEngine `hints` vocabulary is intentionally not applied here. Amazon Transcribe biases\n // only via a *custom vocabulary* that must be created/registered ahead of time (CreateVocabulary) and\n // referenced by name — there is no inline per-request word list for streaming. So we skip biasing for AWS.\n async transcribe(pcm: Buffer, sampleRate: number, lang: string): Promise<string> {\n // Must be an async generator: Transcribe's AudioStream is an AsyncIterable.\n // eslint-disable-next-line @typescript-eslint/require-await\n async function* audio(): AsyncGenerator<AudioStream> {\n for (let off = 0; off < pcm.length; off += STT_CHUNK_BYTES) {\n yield { AudioEvent: { AudioChunk: pcm.subarray(off, off + STT_CHUNK_BYTES) } };\n }\n }\n\n const resp = await this.client.send(\n new StartStreamTranscriptionCommand({\n LanguageCode: isoToLocale(lang) as LanguageCode,\n MediaSampleRateHertz: sampleRate,\n MediaEncoding: 'pcm',\n AudioStream: audio(),\n }),\n );\n\n let text = '';\n for await (const event of resp.TranscriptResultStream || []) {\n for (const result of event.TranscriptEvent?.Transcript?.Results || []) {\n const transcript = result.Alternatives?.[0]?.Transcript;\n if (!result.IsPartial && transcript) {\n text += (text ? ' ' : '') + transcript;\n }\n }\n }\n return text.trim();\n }\n}\n\nexport class AwsTts implements TtsEngine {\n private readonly client: PollyClient;\n\n constructor(\n creds: AwsCreds,\n /** Polly VoiceId (e.g. 'Vicki', 'Tatyana'); empty → default per language. */\n private readonly voice: string,\n /** Language the voice is set for ('' = every language); Polly voice ids do not tell it. */\n private readonly language = '',\n ) {\n this.client = new PollyClient({\n region: creds.region,\n credentials: { accessKeyId: creds.accessKeyId, secretAccessKey: creds.secretAccessKey },\n });\n }\n\n synthesize(text: string, lang: string): Promise<TtsResult> {\n return this.speak(text, lang, 'text');\n }\n\n /** Polly speaks SSML natively (`TextType: 'ssml'`), so pauses and emphasis survive. */\n synthesizeSsml(ssml: string, lang: string): Promise<TtsResult> {\n return this.speak(ssml, lang, 'ssml');\n }\n\n private async speak(text: string, lang: string, textType: 'text' | 'ssml'): Promise<TtsResult> {\n const iso = (lang || 'en').split('-')[0].toLowerCase();\n const home = (this.language || '').split('-')[0].toLowerCase();\n // the set voice only for its language: Vicki reads no Russian, Tatyana does\n const own = this.voice && (!home || iso === home || !DEFAULT_POLLY_VOICE[iso]) ? this.voice : '';\n const voice = own || DEFAULT_POLLY_VOICE[iso] || this.voice || 'Joanna';\n const resp = await this.client.send(\n new SynthesizeSpeechCommand({\n Text: text,\n TextType: textType,\n OutputFormat: 'pcm', // 16-bit signed 1-channel little-endian\n SampleRate: '16000',\n VoiceId: voice as VoiceId,\n }),\n );\n if (!resp.AudioStream) {\n throw new Error('Polly returned no audio stream');\n }\n const bytes = await resp.AudioStream.transformToByteArray();\n return { pcm: Buffer.from(bytes), sampleRate: 16000 };\n }\n}\n"]}
|
package/build/lib/voice/azure.js
CHANGED
|
@@ -41,6 +41,7 @@ exports.listAzureVoices = listAzureVoices;
|
|
|
41
41
|
*/
|
|
42
42
|
const sdk = __importStar(require("microsoft-cognitiveservices-speech-sdk"));
|
|
43
43
|
const lang_1 = require("./lang");
|
|
44
|
+
const speechLanguage_1 = require("./speechLanguage");
|
|
44
45
|
/** List available Azure voices (short names like 'de-DE-KatjaNeural'), optionally filtered by locale. */
|
|
45
46
|
async function listAzureVoices(key, region, locale) {
|
|
46
47
|
const speechConfig = sdk.SpeechConfig.fromSubscription(key, region);
|
|
@@ -70,7 +71,9 @@ class AzureStt {
|
|
|
70
71
|
const format = sdk.AudioStreamFormat.getWaveFormatPCM(sampleRate, 16, 1);
|
|
71
72
|
const pushStream = sdk.AudioInputStream.createPushStream(format);
|
|
72
73
|
// The push stream needs a standalone ArrayBuffer (not the pooled Node Buffer view).
|
|
73
|
-
|
|
74
|
+
const chunk = new ArrayBuffer(pcm.byteLength);
|
|
75
|
+
new Uint8Array(chunk).set(pcm);
|
|
76
|
+
pushStream.write(chunk);
|
|
74
77
|
pushStream.close();
|
|
75
78
|
const recognizer = new sdk.SpeechRecognizer(speechConfig, sdk.AudioConfig.fromStreamInput(pushStream));
|
|
76
79
|
// A phrase list softly boosts recognition of the given domain vocabulary (device/room names) without
|
|
@@ -125,7 +128,8 @@ class AzureTts {
|
|
|
125
128
|
async speak(lang, run) {
|
|
126
129
|
const speechConfig = sdk.SpeechConfig.fromSubscription(this.key, this.region);
|
|
127
130
|
speechConfig.speechSynthesisOutputFormat = sdk.SpeechSynthesisOutputFormat.Raw24Khz16BitMonoPcm;
|
|
128
|
-
|
|
131
|
+
// the set voice only for its language (de-DE-KatjaNeural reads no Russian); otherwise Azure's voice for it
|
|
132
|
+
if (this.voice && (0, speechLanguage_1.voiceFitsLanguage)(this.voice, lang)) {
|
|
129
133
|
speechConfig.speechSynthesisVoiceName = this.voice;
|
|
130
134
|
}
|
|
131
135
|
else {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"azure.js","sourceRoot":"","sources":["../../../src/lib/voice/azure.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"azure.js","sourceRoot":"","sources":["../../../src/lib/voice/azure.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAWA,0CAYC;AAvBD;;;GAGG;AACH,4EAA8D;AAC9D,iCAAqC;AACrC,qDAAqD;AAIrD,yGAAyG;AAClG,KAAK,UAAU,eAAe,CAAC,GAAW,EAAE,MAAc,EAAE,MAAc;IAC7E,MAAM,YAAY,GAAG,GAAG,CAAC,YAAY,CAAC,gBAAgB,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC;IACpE,MAAM,KAAK,GAAG,IAAI,GAAG,CAAC,iBAAiB,CAAC,YAAY,EAAE,IAAI,CAAC,CAAC;IAC5D,IAAI,CAAC;QACD,MAAM,GAAG,GAAG,MAAM,KAAK,CAAC,cAAc,CAAC,MAAM,IAAI,EAAE,CAAC,CAAC;QACrD,IAAI,GAAG,CAAC,MAAM,KAAK,GAAG,CAAC,YAAY,CAAC,mBAAmB,EAAE,CAAC;YACtD,OAAO,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC;QAC5C,CAAC;QACD,MAAM,IAAI,KAAK,CAAC,GAAG,CAAC,YAAY,IAAI,yBAAyB,CAAC,CAAC;IACnE,CAAC;YAAS,CAAC;QACP,KAAK,CAAC,KAAK,EAAE,CAAC;IAClB,CAAC;AACL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,EAAE,GAAG,EAAE,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,EAAE,UAAU,EAAE,KAAK,EAAE,CAAC;YACrE,CAAC;YACD,MAAM,IAAI,KAAK,CAAC,qBAAqB,MAAM,CAAC,YAAY,IAAI,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC;QACjF,CAAC;gBAAS,CAAC;YACP,KAAK,CAAC,KAAK,EAAE,CAAC;QAClB,CAAC;IACL,CAAC;CACJ;AAhDD,4BAgDC","sourcesContent":["/**\n * Azure Cognitive Services Speech engines (STT + TTS).\n * Credentials: a subscription key + region (e.g. 'westeurope').\n */\nimport * as sdk from 'microsoft-cognitiveservices-speech-sdk';\nimport { isoToLocale } from './lang';\nimport { voiceFitsLanguage } from './speechLanguage';\nimport type { SttEngine } from './stt';\nimport type { TtsEngine, TtsResult } from './tts';\n\n/** List available Azure voices (short names like 'de-DE-KatjaNeural'), optionally filtered by locale. */\nexport async function listAzureVoices(key: string, region: string, locale: string): Promise<string[]> {\n const speechConfig = sdk.SpeechConfig.fromSubscription(key, region);\n const synth = new sdk.SpeechSynthesizer(speechConfig, null);\n try {\n const res = await synth.getVoicesAsync(locale || '');\n if (res.reason === sdk.ResultReason.VoicesListRetrieved) {\n return res.voices.map(v => v.shortName);\n }\n throw new Error(res.errorDetails || 'Azure voice list failed');\n } finally {\n synth.close();\n }\n}\n\n/** Azure STT via `recognizeOnceAsync` fed from a PCM push stream (one short utterance). */\nexport class AzureStt implements SttEngine {\n constructor(\n private readonly key: string,\n private readonly region: string,\n ) {}\n\n async transcribe(pcm: Buffer, sampleRate: number, lang: string, hints?: string[]): Promise<string> {\n const speechConfig = sdk.SpeechConfig.fromSubscription(this.key, this.region);\n speechConfig.speechRecognitionLanguage = isoToLocale(lang);\n\n const format = sdk.AudioStreamFormat.getWaveFormatPCM(sampleRate, 16, 1);\n const pushStream = sdk.AudioInputStream.createPushStream(format);\n // The push stream needs a standalone ArrayBuffer (not the pooled Node Buffer view).\n const chunk = new ArrayBuffer(pcm.byteLength);\n new Uint8Array(chunk).set(pcm);\n pushStream.write(chunk);\n pushStream.close();\n\n const recognizer = new sdk.SpeechRecognizer(speechConfig, sdk.AudioConfig.fromStreamInput(pushStream));\n // A phrase list softly boosts recognition of the given domain vocabulary (device/room names) without\n // restricting the recognizer to only those words.\n if (hints?.length) {\n const phraseList = sdk.PhraseListGrammar.fromRecognizer(recognizer);\n for (const h of hints) {\n const term = (h || '').trim();\n if (term) {\n phraseList.addPhrase(term);\n }\n }\n }\n try {\n const result = await new Promise<sdk.SpeechRecognitionResult>((resolve, reject) => {\n recognizer.recognizeOnceAsync(resolve, reject);\n });\n if (result.reason === sdk.ResultReason.RecognizedSpeech) {\n return result.text.trim();\n }\n if (result.reason === sdk.ResultReason.Canceled) {\n const details = sdk.CancellationDetails.fromResult(result);\n throw new Error(`Azure STT canceled: ${details.errorDetails || details.reason}`);\n }\n return '';\n } finally {\n recognizer.close();\n }\n }\n}\n\n/** Azure TTS to raw 24 kHz mono 16-bit PCM (no server-side playback). */\nexport class AzureTts implements TtsEngine {\n constructor(\n private readonly key: string,\n private readonly region: string,\n /** Full Azure voice name (e.g. 'de-DE-KatjaNeural'); empty → pick by language. */\n private readonly voice: string,\n ) {}\n\n synthesize(text: string, lang: string): Promise<TtsResult> {\n return this.speak(lang, (synth, resolve, reject) => synth.speakTextAsync(text, resolve, reject));\n }\n\n /** Azure speaks SSML natively, so pauses and emphasis survive. */\n synthesizeSsml(ssml: string, lang: string): Promise<TtsResult> {\n return this.speak(lang, (synth, resolve, reject) => synth.speakSsmlAsync(ssml, resolve, reject));\n }\n\n private async speak(\n lang: string,\n run: (\n synth: sdk.SpeechSynthesizer,\n resolve: (r: sdk.SpeechSynthesisResult) => void,\n reject: (e: unknown) => void,\n ) => void,\n ): Promise<TtsResult> {\n const speechConfig = sdk.SpeechConfig.fromSubscription(this.key, this.region);\n speechConfig.speechSynthesisOutputFormat = sdk.SpeechSynthesisOutputFormat.Raw24Khz16BitMonoPcm;\n // the set voice only for its language (de-DE-KatjaNeural reads no Russian); otherwise Azure's voice for it\n if (this.voice && voiceFitsLanguage(this.voice, lang)) {\n speechConfig.speechSynthesisVoiceName = this.voice;\n } else {\n speechConfig.speechSynthesisLanguage = isoToLocale(lang);\n }\n\n // audioConfig=null → synthesise to memory only, no default-speaker output.\n const synth = new sdk.SpeechSynthesizer(speechConfig, null);\n try {\n const result = await new Promise<sdk.SpeechSynthesisResult>((resolve, reject) => {\n run(synth, resolve, reject);\n });\n if (result.reason === sdk.ResultReason.SynthesizingAudioCompleted) {\n return { pcm: Buffer.from(result.audioData), sampleRate: 24000 };\n }\n throw new Error(`Azure TTS failed: ${result.errorDetails || result.reason}`);\n } finally {\n synth.close();\n }\n }\n}\n"]}
|
|
@@ -55,6 +55,7 @@ const path = __importStar(require("node:path"));
|
|
|
55
55
|
const ttsCache_1 = require("./ttsCache");
|
|
56
56
|
const fallback_1 = require("./fallback");
|
|
57
57
|
const lang_1 = require("./lang");
|
|
58
|
+
const speechLanguage_1 = require("./speechLanguage");
|
|
58
59
|
function requireAzure(creds) {
|
|
59
60
|
if (!creds.azureKey || !creds.azureRegion) {
|
|
60
61
|
throw new Error('Azure speech needs a subscription key and region');
|
|
@@ -118,9 +119,13 @@ function buildSttEngine(provider, ctx) {
|
|
|
118
119
|
}
|
|
119
120
|
}
|
|
120
121
|
function createTtsEngine(provider, ctx) {
|
|
122
|
+
// Outermost: every text is spoken in its own language — a German voice spells a Russian answer letter by letter
|
|
123
|
+
return new speechLanguage_1.LanguageTts(fallbackTts(provider, ctx), ctx.reportedLanguage, ctx.log);
|
|
124
|
+
}
|
|
125
|
+
function fallbackTts(provider, ctx) {
|
|
121
126
|
// Each engine gets the shared behaviour (disk cache, length limit, SSML) and its own cache directory,
|
|
122
127
|
// so a fallback engine's voice can never be served later while the primary one is healthy again.
|
|
123
|
-
const primary = { name: provider, engine:
|
|
128
|
+
const primary = { name: provider, engine: withLanguageVoices(provider, ctx) };
|
|
124
129
|
const fallback = ctx.ttsFallback && ctx.ttsFallback !== provider ? ctx.ttsFallback : '';
|
|
125
130
|
if (!fallback) {
|
|
126
131
|
return primary.engine;
|
|
@@ -134,6 +139,33 @@ function createTtsEngine(provider, ctx) {
|
|
|
134
139
|
return primary.engine;
|
|
135
140
|
}
|
|
136
141
|
}
|
|
142
|
+
/** Key of a provider in {@link VoiceNames}; the speech-to-text-only providers have no voice. */
|
|
143
|
+
function voiceKey(provider) {
|
|
144
|
+
return provider === 'vosk' || provider === 'parakeet' ? '' : provider;
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* The main provider with the table "voice per language": one engine per row with that voice. The table names voices
|
|
148
|
+
* of the main provider, so the fallback provider does not get it.
|
|
149
|
+
*/
|
|
150
|
+
function withLanguageVoices(provider, ctx) {
|
|
151
|
+
const main = cachedTts(provider, ctx);
|
|
152
|
+
const key = voiceKey(provider);
|
|
153
|
+
const rows = Object.entries(ctx.voicesByLanguage || {});
|
|
154
|
+
if (!key || !rows.length) {
|
|
155
|
+
return main;
|
|
156
|
+
}
|
|
157
|
+
const byLanguage = {};
|
|
158
|
+
for (const [lang, voice] of rows) {
|
|
159
|
+
try {
|
|
160
|
+
// the voice of a row is for its language (Polly names say nothing about it)
|
|
161
|
+
byLanguage[lang] = cachedTts(provider, { ...ctx, language: lang, voices: { ...ctx.voices, [key]: voice } });
|
|
162
|
+
}
|
|
163
|
+
catch (e) {
|
|
164
|
+
ctx.log.warn(`Voice '${voice}' for '${lang}' unavailable: ${e.message}`);
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
return new speechLanguage_1.VoicePerLanguage(main, byLanguage);
|
|
168
|
+
}
|
|
137
169
|
/**
|
|
138
170
|
* One provider binding plus the shared cache/length/SSML layer. One cache directory per provider+voice —
|
|
139
171
|
* a voice change must not serve audio in the old voice.
|
|
@@ -158,7 +190,7 @@ function buildTtsEngine(provider, ctx) {
|
|
|
158
190
|
return new azure_1.AzureTts(ctx.creds.azureKey, ctx.creds.azureRegion, ctx.voices.azure);
|
|
159
191
|
case 'aws':
|
|
160
192
|
requireAws(ctx.creds);
|
|
161
|
-
return new aws_1.AwsTts(ctx.creds.aws, ctx.voices.aws);
|
|
193
|
+
return new aws_1.AwsTts(ctx.creds.aws, ctx.voices.aws, ctx.language);
|
|
162
194
|
case 'piper':
|
|
163
195
|
return new piper_1.PiperTts(ctx.dataDir, ctx.voices.piper, ctx.log);
|
|
164
196
|
case 'vosk':
|