iobroker.assistant 1.16.0 → 1.16.1

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
@@ -237,6 +237,9 @@ 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.16.1 (2026-11-29)
241
+ * (@GermanBluefox) Gender of the voice: the cloud LLM and pi-agent also get a line right after the question in the language of the answer ("speak of yourself in the feminine form"); the hint in the instructions alone did not hold, and a female Russian voice still said «включил»
242
+
240
243
  ### 1.16.0 (2026-11-29)
241
244
  * (@GermanBluefox) Gender of the voice: the table "Voice per answer language" has a column "Voice gender", and the assistant speaks of itself in the form of its voice (a female Russian voice says «я сделала», not «я сделал») — in the instructions of the cloud LLM and pi-agent and in the fixed Russian answers
242
245
  * (@GermanBluefox) "Automatic" takes the gender from the voice list of Azure and AWS, or from the name of a known voice (OpenAI, Piper, Gemini, ElevenLabs, HeyGen and Kokoro on OpenRouter); the log tells at the start what was found
@@ -253,13 +256,6 @@ train it twice.
253
256
  ### 1.15.0 (2026-11-26)
254
257
  * (@GermanBluefox) A wake word for free questions: the table of the wake words has a purpose, and with "Free questions only" a wake word ("Hey Bro, how old can cats get?") skips the commands of the house and asks the cloud tier without device list and tools, in a conversation of its own; its follow-ups and dialog mode keep it. Instructions of its own: `freeTalkPrompt`
255
258
 
256
- ### 1.14.0 (2026-11-23)
257
- * (@GermanBluefox) Commands of other adapters by the shared catalog (`HELP.md`): the assistant asks the `help` of every instance and understands "call Anna" (`phone.call`), "send me a picture of the front door" (`camera.snapshot` → `message.send`), "show the driveway on the TV" (`screen.show`: camera, view, text), also in German and Russian, and plays music on the players of other adapters (`media.getPlayers`/`search`/`play`); message `getStandards`
258
- * (@GermanBluefox) The cloud tier (LLM or pi-agent) gets "answer in <language>" after a question whose language is clear (its letters, the wake word or its words): pi-agent answered a Russian question in German after German turns
259
- * (@GermanBluefox) Music and YouTube on the players of their tables are understood also with the rule-based commands switched off (pi-agent has no tools for them)
260
- * (@GermanBluefox) Music without a named player plays on the device that was spoken to (new column "Satellite" in the table, now "Music players", which also takes players of other adapters); "play the Piano Guys" works without a kind word and plays only something named like it
261
- * (@GermanBluefox) 3D plan: "show the lower deck", "show the galley", "show the whole house" (also in German and Russian) make every open 3D view of home3d fly there (writes `home3d.N.show`); only names the plan knows (`home3d.N.places`) are taken, everything else goes on as before
262
-
263
259
  [Older changelogs can be found there](CHANGELOG_OLD.md)
264
260
 
265
261
  ## License
@@ -13,6 +13,7 @@ exports.parseVoiceTable = parseVoiceTable;
13
13
  exports.cellGender = cellGender;
14
14
  exports.parseVoiceGenders = parseVoiceGenders;
15
15
  exports.voiceGenderHint = voiceGenderHint;
16
+ exports.selfGenderLine = selfGenderLine;
16
17
  /** Script of the languages that are not written in Latin letters; everything else is Latin. */
17
18
  const SCRIPT_OF = {
18
19
  ru: 'cyrillic',
@@ -396,6 +397,37 @@ function voiceGenderHint(genders, promptLanguage) {
396
397
  }
397
398
  return `The gender of your voice per answer language: ${list}. When you speak of yourself in that language, use the grammatical gender of that voice, in text answers too.`;
398
399
  }
400
+ /** "Speak of yourself in the feminine" in the language itself, for the languages {@link SELF_FORMS} knows. */
401
+ const SELF_GENDER_LINES = {
402
+ ru: { female: 'О себе говори в женском роде', male: 'О себе говори в мужском роде' },
403
+ uk: { female: 'Про себе говори в жіночому роді', male: 'Про себе говори в чоловічому роді' },
404
+ be: { female: 'Пра сябе кажы ў жаночым родзе', male: 'Пра сябе кажы ў мужчынскім родзе' },
405
+ pl: { female: 'Mów o sobie w rodzaju żeńskim', male: 'Mów o sobie w rodzaju męskim' },
406
+ cs: { female: 'O sobě mluv v ženském rodě', male: 'O sobě mluv v mužském rodě' },
407
+ };
408
+ /**
409
+ * One line for the user turn of a cloud model: speak of yourself in the gender of the voice that reads the answer. The
410
+ * hint in the system prompt ({@link voiceGenderHint}) was not enough — pi-agent answered «теперь включил» with a
411
+ * female Russian voice, after earlier turns in the male form. '' for a language whose speaker has no grammatical gender
412
+ * ("ich habe", "I did") or without a gender.
413
+ *
414
+ * @param lang ISO-639-1 code of the answer
415
+ * @param gender gender of the voice for that language
416
+ */
417
+ function selfGenderLine(lang, gender) {
418
+ const base = baseLanguage(lang);
419
+ const forms = SELF_FORMS[base];
420
+ if (!gender || !forms) {
421
+ return '';
422
+ }
423
+ const other = gender === 'female' ? 'male' : 'female';
424
+ const own = SELF_GENDER_LINES[base];
425
+ if (own) {
426
+ const not = { ru: 'а не', uk: 'а не', be: 'а не', pl: 'a nie', cs: 'ne' }[base];
427
+ return `${own[gender]}: «${forms[gender]}», ${not} «${forms[other]}».`;
428
+ }
429
+ return `Speak of yourself in the ${gender === 'female' ? 'feminine' : 'masculine'} form: «${forms[gender]}», not «${forms[other]}».`;
430
+ }
399
431
  /**
400
432
  * The outermost TTS layer: speaks every text in its own language ({@link speechLanguage}). `reported` looks up the
401
433
  * language the answering tier gave for exactly this text.
@@ -1 +1 @@
1
- {"version":3,"file":"speechLanguage.js","sourceRoot":"","sources":["../../../src/lib/voice/speechLanguage.ts"],"names":[],"mappings":";;;AA0DA,oCAKC;AAoDD,wCAkBC;AASD,8CAuBC;AAUD,wCAmBC;AAuCD,4CAwBC;AA+CD,8CAOC;AAYD,oCAGC;AAMD,kDAeC;AAGD,0CAcC;AAGD,gCAGC;AAMD,8CAaC;AAgCD,0CAyBC;AAzaD,+FAA+F;AAC/F,MAAM,SAAS,GAA2B;IACtC,EAAE,EAAE,UAAU;IACd,EAAE,EAAE,UAAU;IACd,EAAE,EAAE,UAAU;IACd,EAAE,EAAE,UAAU;IACd,EAAE,EAAE,UAAU;IACd,EAAE,EAAE,UAAU;IACd,EAAE,EAAE,UAAU;IACd,EAAE,EAAE,OAAO;IACX,EAAE,EAAE,KAAK;IACT,EAAE,EAAE,KAAK;IACT,EAAE,EAAE,QAAQ;IACZ,EAAE,EAAE,QAAQ;IACZ,EAAE,EAAE,QAAQ;IACZ,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MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,UAAU,CAAC,EAAE,CAAC;YAC3D,IAAI,IAAI,KAAK,YAAY,CAAC,IAAI,CAAC,EAAE,CAAC;gBAC9B,MAAM,MAAM,CAAC,OAAO,EAAE,CAAC,IAAI,CAAC,CAAC;YACjC,CAAC;QACL,CAAC;IACL,CAAC;IAED,IAAI,CAAC,OAAiB,EAAE,IAAY;QAChC,OAAO,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,CAAC,OAAO,EAAE,IAAI,CAAC,IAAI,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;IAC5E,CAAC;IAED,WAAW,CAAC,IAAY;QACpB,OAAO,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,WAAW,EAAE,CAAC,IAAI,CAAC,IAAI,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;IAC3E,CAAC;CACJ;AApCD,4CAoCC","sourcesContent":["/**\n * The language an answer is spoken in. The transports hand the TTS the language the satellite listens in, but an\n * answer can be in another one (a question asked in Russian on a German satellite, pi-agent answering in the language\n * of the question). A German voice reads Cyrillic letter by letter (\"kyrillisch a, kyrillisch b …\"), so the TTS\n * takes the language of the text:\n *\n * 1. the language the answering tier reported (pi-agent ≥ 0.10.1 returns `language`), unless the letters contradict it;\n * 2. otherwise the letters: a text in another script than the configured language (Cyrillic, Greek, CJK …) is spoken\n * in the language of that script. Latin letters do not tell German from English: then the configured language\n * stays, unless it is itself written in another script (a Russian satellite answering in Latin letters → English).\n *\n * {@link LanguageTts} applies this in front of every TTS engine; {@link VoicePerLanguage} picks the voice of the\n * table \"voice per language\" for it.\n */\nimport type { TtsEngine, TtsResult } from './tts';\nimport type { VoiceGender } from './voiceGender';\n\nexport type { VoiceGender };\n\ntype Script = 'latin' | 'cyrillic' | 'greek' | 'cjk' | 'hangul' | 'arabic' | 'hebrew';\n\n/** Script of the languages that are not written in Latin letters; everything else is Latin. */\nconst SCRIPT_OF: Record<string, Script> = {\n ru: 'cyrillic',\n uk: 'cyrillic',\n be: 'cyrillic',\n bg: 'cyrillic',\n sr: 'cyrillic',\n mk: 'cyrillic',\n kk: 'cyrillic',\n el: 'greek',\n zh: 'cjk',\n ja: 'cjk',\n ko: 'hangul',\n ar: 'arabic',\n fa: 'arabic',\n he: 'hebrew',\n};\n\nconst LETTERS: [Script, RegExp][] = [\n ['latin', /[a-zÀ-ɏ]/gi],\n ['cyrillic', /[Ѐ-ӿ]/g],\n ['greek', /[Ͱ-Ͽ]/g],\n ['cjk', /[぀-ヿ㐀-鿿]/g],\n ['hangul', /[가-힯ᄀ-ᇿ]/g],\n ['arabic', /[؀-ۿ]/g],\n ['hebrew', /[֐-׿]/g],\n];\n\n/** Fewer letters than this say nothing about the language (\"OK\", \"5 °C\"). */\nconst MIN_LETTERS = 3;\n\n/** Letters only Ukrainian has among the Cyrillic languages. */\nconst UKRAINIAN = /[ґєії]/i;\n/** Kana: Japanese, not Chinese. */\nconst KANA = /[぀-ヿ]/;\n\n/** ISO-639-1 code of a language or locale: 'ru-RU' → 'ru', 'zh-cn' → 'zh'. */\nexport function baseLanguage(lang: string | undefined): string {\n return String(lang || '')\n .trim()\n .split(/[-_]/)[0]\n .toLowerCase();\n}\n\nfunction scriptOf(lang: string): Script {\n return SCRIPT_OF[baseLanguage(lang)] || 'latin';\n}\n\n/** Grammar words of English and German: a device name hardly has two of them, a sentence has. */\nconst LATIN_GRAMMAR = new Set(\n \"the a an is are was it its it's of to and this that there der die das den dem des ein eine einen ist sind war und es nicht\".split(\n ' ',\n ),\n);\n\n/**\n * Does the text carry words of this language's script? For a language not written in Latin letters a few of its\n * letters are enough: \"Температура (Küche): Kueche Sensor 1: 24 °C\" is a Russian sentence with German names in it,\n * and an English voice would read the Russian words badly. Latin letters alone prove nothing (names, units, brands) —\n * unless they carry the grammar of a sentence: \"The lamp \"Свет\" is on.\" is English with a Russian name.\n */\nfunction hasOwnLetters(text: string, lang: string): boolean {\n const script = scriptOf(lang);\n if (script === 'latin') {\n return false;\n }\n const re = LETTERS.find(([s]) => s === script)?.[1];\n if (!re || (text.match(re) || []).length < MIN_LETTERS) {\n return false;\n }\n const latinWords = text.toLowerCase().match(/[a-zà-ɏ']+/g) || [];\n return latinWords.filter(w => LATIN_GRAMMAR.has(w)).length < 2;\n}\n\n/** The script most letters of the text are in; '' for too few letters. */\nfunction dominantScript(text: string): Script | '' {\n let best: Script | '' = '';\n let most = 0;\n let total = 0;\n for (const [script, re] of LETTERS) {\n const count = (text.match(re) || []).length;\n total += count;\n if (count > most) {\n best = script;\n most = count;\n }\n }\n return total >= MIN_LETTERS ? best : '';\n}\n\n/**\n * The language a text is written in as far as its letters tell; '' for Latin letters (German or English?) and for\n * too few letters.\n */\nexport function scriptLanguage(text: string): string {\n const script = dominantScript(String(text || ''));\n switch (script) {\n case 'cyrillic':\n return UKRAINIAN.test(text) ? 'uk' : 'ru';\n case 'greek':\n return 'el';\n case 'cjk':\n return KANA.test(text) ? 'ja' : 'zh';\n case 'hangul':\n return 'ko';\n case 'arabic':\n return 'ar';\n case 'hebrew':\n return 'he';\n default:\n return '';\n }\n}\n\n/**\n * One line for the user turn of a cloud model: \"answer in this language\". The general hint in the system prompt\n * (\"answer in the language of the question\") is not enough for a conversation that ran in another language so far —\n * pi-agent answered a Russian question in German after German turns and a German system prompt.\n *\n * @param lang ISO-639-1 code of the question\n */\nexport function replyLanguageLine(lang: string): string {\n const base = baseLanguage(lang);\n switch (base) {\n case '':\n return '';\n case 'ru':\n return 'Ответь по-русски.';\n case 'uk':\n return 'Відповідай українською.';\n case 'de':\n return 'Antworte auf Deutsch.';\n case 'en':\n return 'Answer in English.';\n default: {\n let name = base;\n try {\n name = new Intl.DisplayNames(['en'], { type: 'language' }).of(base) || base;\n } catch {\n // an unknown code: the code itself\n }\n return `Answer in ${name}.`;\n }\n }\n}\n\n/**\n * The language to speak a text in.\n *\n * @param text what is spoken\n * @param configured the language the caller asked for (the satellite's language)\n * @param reported the language the answering tier reported ('' = none)\n * @returns ISO-639-1 code, or `configured` unchanged when nothing speaks against it\n */\nexport function speechLanguage(text: string, configured: string, reported?: string): string {\n const script = dominantScript(String(text || ''));\n const said = /^[a-z]{2,3}(-[a-z]{2,4})?$/i.test(String(reported || '').trim()) ? baseLanguage(reported) : '';\n // a report is believed unless the letters contradict it (a \"de\" mark on a Cyrillic answer); Latin names inside a\n // Russian sentence do not contradict \"ru\"\n if (said && (!script || scriptOf(said) === script || hasOwnLetters(text, said))) {\n // the configured language in its own form ('de-DE'): same voice, same cache entry\n return said === baseLanguage(configured) ? configured : said;\n }\n if (!script || (!said && script !== scriptOf(configured) && hasOwnLetters(text, configured))) {\n return configured; // too few letters, or a sentence of the configured language with Latin names in it\n }\n const byLetters = scriptLanguage(text);\n if (scriptOf(configured) === script) {\n // the letters fit the configured language; only Ukrainian letters say more than \"Cyrillic\"\n return byLetters === 'uk' && baseLanguage(configured) !== 'uk' ? 'uk' : configured;\n }\n // Latin letters while the satellite speaks Russian: English is the best guess\n return byLetters || 'en';\n}\n\n/**\n * Words that say a Latin-script question is English or German. Only words of one of the two: \"in\", \"an\", \"die\",\n * \"was\", \"will\", \"so\", \"man\" are both and say nothing. Kept to what short spoken commands and questions use.\n */\nconst FUNCTION_WORDS: Record<'en' | 'de', ReadonlySet<string>> = {\n en: new Set(\n (\n \"the what what's whats is are it it's its how turn switch please light lights time me my of to and you your \" +\n 'on off set tell which where when who open close this that temperature weather today tomorrow now much many ' +\n 'does do can could would there all up down timer alarm minutes hours at for be play stop'\n ).split(' '),\n ),\n de: new Set(\n (\n 'der den dem des das ist wie wer wo welche welcher welches schalte schalt mach mache ein eine einen aus bitte ' +\n 'licht spät uhr und im es mir mein meine ich du sind auf zu wieviel viel wetter heute morgen jetzt gibt ' +\n 'alle stelle stell setze öffne schließe temperatur minuten stunden wecker um nach noch lange sag sage mal ' +\n 'kannst spiele spiel'\n ).split(' '),\n ),\n};\n\n/** Function words of `lang` in the words of a text; 0 for a language without a list. */\nfunction functionWords(words: string[], lang: string): number {\n const list = FUNCTION_WORDS[lang as 'en' | 'de'];\n return list ? words.filter(w => list.has(w)).length : 0;\n}\n\n/**\n * The language a question is asked in, for the fixed answers of the rule NLU (\"скажи, сколько сейчас времени\" on a\n * German satellite was answered in German). Another script than the configured language's tells it by the letters\n * (like {@link speechLanguage}); for Latin letters English and German are told apart by function words — only with\n * at least two of them and more than twice as many as of the configured language, so a German command with an\n * English device name stays German and a French question on a French system is not taken for German.\n *\n * @returns ISO-639-1 code, or `configured` unchanged when nothing speaks against it\n */\nexport function questionLanguage(text: string, configured: string): string {\n const question = String(text || '');\n const script = dominantScript(question);\n if (!script) {\n return configured;\n }\n if (script !== 'latin') {\n return speechLanguage(question, configured);\n }\n const words = question.toLowerCase().match(/[\\p{L}']+/gu) || [];\n const base = baseLanguage(configured);\n let best = '';\n let most = 0;\n for (const lang of ['en', 'de']) {\n const hits = functionWords(words, lang);\n if (hits > most) {\n best = lang;\n most = hits;\n }\n }\n if (!best || best === base || most < 2 || most <= 2 * functionWords(words, base)) {\n return configured;\n }\n return best;\n}\n\n/** How many answers {@link AnswerLanguages} remembers. */\nconst KEPT_LANGUAGES = 50;\n\n/**\n * The language of recent answers, by their text. An answer travels as plain text through the tiers and transports to\n * the TTS; this finds its language again there. The key is the text without control markers ([[LISTEN]], [[DONE]]):\n * the assistant takes them out before speaking.\n */\nexport class AnswerLanguages {\n private readonly byText = new Map<string, string>();\n\n private static key(text: string): string {\n return String(text || '')\n .replace(/\\[\\[[A-Z]+\\]\\]/gi, ' ')\n .replace(/\\s+/g, ' ')\n .trim();\n }\n\n /** Remember the language of an answer; anything but an ISO code (`ru`, `en-us`) is ignored. */\n remember(text: string, language: string): void {\n const lang = String(language || '')\n .trim()\n .toLowerCase();\n const key = AnswerLanguages.key(text);\n if (!key || !/^[a-z]{2,3}(-[a-z]{2,4})?$/.test(lang)) {\n return;\n }\n this.byText.delete(key);\n this.byText.set(key, lang);\n if (this.byText.size > KEPT_LANGUAGES) {\n this.byText.delete(this.byText.keys().next().value as string);\n }\n }\n\n /** The language remembered for this answer, '' for none. */\n languageOf(text: string): string {\n return this.byText.get(AnswerLanguages.key(text)) || '';\n }\n}\n\n/**\n * Can this voice speak the language? Told by the locale at the start of its name (`de_DE-thorsten-medium`,\n * `de-DE-KatjaNeural`, `de-DE-Klaus:MAI-Voice-2`); a name without a locale (OpenAI `alloy`, Gemini `Kore`) and a\n * multilingual Azure voice can speak every language.\n */\nexport function voiceFitsLanguage(voice: string, lang: string): boolean {\n const iso = baseLanguage(lang);\n const locale = /^([a-z]{2,3})[-_][A-Z]{2}(?![a-z])/.exec(String(voice || '').trim());\n if (!iso || !locale || /multilingual/i.test(voice)) {\n return true;\n }\n return locale[1] === iso;\n}\n\n/** A row of the table \"voice per language\": the voice and/or the TTS model ('' = the ones set above). */\nexport interface LanguageVoice {\n voice: string;\n model: string;\n}\n\n/**\n * The language code at the start of a table cell: 'de', 'de-DE' → 'de'. The column was a free text field with\n * suggestions, and picking one saved its label ('de – Deutsch'), so the code is read from the start.\n */\nexport function cellLanguage(value: unknown): string {\n const match = typeof value === 'string' ? /^\\s*([a-z]{2,3})(?![a-z])/i.exec(value) : null;\n return match ? match[1].toLowerCase() : '';\n}\n\n/**\n * The table \"voice per language\" with a code in each language cell, or `null` when every cell has one already.\n * The column is a drop-down now, which shows nothing for 'de – Deutsch' or 'de-DE'.\n */\nexport function normalizeVoiceTable(rows: unknown): unknown[] | null {\n if (!Array.isArray(rows)) {\n return null;\n }\n let changed = false;\n const fixed = rows.map(row => {\n const language = (row as { language?: unknown } | null)?.language;\n const code = cellLanguage(language);\n if (!code || code === language) {\n return row;\n }\n changed = true;\n return { ...(row as object), language: code };\n });\n return changed ? fixed : null;\n}\n\n/** Parse the config table \"voice per language\" into ISO code → voice and model; rows without either are skipped. */\nexport function parseVoiceTable(rows: unknown): Record<string, LanguageVoice> {\n const table: Record<string, LanguageVoice> = {};\n if (!Array.isArray(rows)) {\n return table;\n }\n for (const row of rows as { language?: unknown; voice?: unknown; model?: unknown }[]) {\n const lang = cellLanguage(row?.language);\n const voice = typeof row?.voice === 'string' ? row.voice.trim() : '';\n const model = typeof row?.model === 'string' ? row.model.trim() : '';\n if (lang && (voice || model)) {\n table[lang] = { voice, model };\n }\n }\n return table;\n}\n\n/** The gender in a table cell, '' for none. */\nexport function cellGender(value: unknown): VoiceGender | '' {\n const gender = typeof value === 'string' ? value.trim().toLowerCase() : '';\n return gender === 'female' || gender === 'male' ? gender : '';\n}\n\n/**\n * Parse the column \"gender\" of the table \"voice per language\" into ISO code → gender. A row needs no voice for it:\n * language and gender alone tell the gender of the voice set above for that language.\n */\nexport function parseVoiceGenders(rows: unknown): Record<string, VoiceGender> {\n const genders: Record<string, VoiceGender> = {};\n if (!Array.isArray(rows)) {\n return genders;\n }\n for (const row of rows as { language?: unknown; gender?: unknown }[]) {\n const lang = cellLanguage(row?.language);\n const gender = cellGender(row?.gender);\n if (lang && gender) {\n genders[lang] = gender;\n }\n }\n return genders;\n}\n\n/** How one speaks of oneself per gender, as an example for the model. */\nconst SELF_FORMS: Record<string, Record<VoiceGender, string>> = {\n ru: { female: 'я сделала', male: 'я сделал' },\n uk: { female: 'я зробила', male: 'я зробив' },\n be: { female: 'я зрабіла', male: 'я зрабіў' },\n pl: { female: 'zrobiłam', male: 'zrobiłem' },\n cs: { female: 'udělala jsem', male: 'udělal jsem' },\n fr: { female: 'je suis prête', male: 'je suis prêt' },\n es: { female: 'estoy lista', male: 'estoy listo' },\n it: { female: 'sono pronta', male: 'sono pronto' },\n pt: { female: 'obrigada', male: 'obrigado' },\n el: { female: 'είμαι έτοιμη', male: 'είμαι έτοιμος' },\n};\n\n/** Name of a language in the language of the prompt ('Russisch', 'русский'), the code when Node.js has no name. */\nfunction languageName(code: string, inLanguage: string): string {\n try {\n return new Intl.DisplayNames([inLanguage], { type: 'language' }).of(code) || code;\n } catch {\n return code;\n }\n}\n\n/**\n * Instruction for the cloud model (system prompt): the gender of the voice per answer language, so that it speaks of\n * itself in that form. Empty without genders. In the prompt language (de/en/ru), like the other hints.\n *\n * @param genders ISO code → gender of the voice ({@link parseVoiceGenders})\n * @param promptLanguage language of the instructions\n */\nexport function voiceGenderHint(genders: Record<string, VoiceGender>, promptLanguage: string): string {\n const lang = baseLanguage(promptLanguage) === 'ru' ? 'ru' : baseLanguage(promptLanguage) === 'de' ? 'de' : 'en';\n const words: Record<'de' | 'en' | 'ru', Record<VoiceGender, string>> = {\n de: { female: 'weiblich', male: 'männlich' },\n en: { female: 'female', male: 'male' },\n ru: { female: 'женский', male: 'мужской' },\n };\n const not = { de: 'nicht', en: 'not', ru: 'а не' }[lang];\n const items = Object.entries(genders).map(([code, gender]) => {\n const forms = SELF_FORMS[code];\n const other: VoiceGender = gender === 'female' ? 'male' : 'female';\n const example = forms ? ` («${forms[gender]}», ${not} «${forms[other]}»)` : '';\n return `${languageName(code, lang)} – ${words[lang][gender]}${example}`;\n });\n if (!items.length) {\n return '';\n }\n const list = items.join(', ');\n if (lang === 'ru') {\n return `Пол твоего голоса по языку ответа: ${list}. Говоря о себе на этом языке, используй грамматический род этого голоса, и в текстовых ответах тоже.`;\n }\n if (lang === 'de') {\n return `Geschlecht deiner Stimme je Antwortsprache: ${list}. Wenn du in dieser Sprache von dir selbst sprichst, nimm das grammatische Geschlecht dieser Stimme, auch in Textantworten.`;\n }\n return `The gender of your voice per answer language: ${list}. When you speak of yourself in that language, use the grammatical gender of that voice, in text answers too.`;\n}\n\n/** Log of the TTS layer. */\ninterface Logger {\n debug(msg: string): void;\n}\n\n/**\n * The outermost TTS layer: speaks every text in its own language ({@link speechLanguage}). `reported` looks up the\n * language the answering tier gave for exactly this text.\n */\nexport class LanguageTts implements TtsEngine {\n constructor(\n private readonly inner: TtsEngine,\n private readonly reported: ((text: string) => string | undefined) | undefined,\n private readonly log: Logger,\n ) {}\n\n /** The language `text` is spoken in when the caller asks for `lang`. */\n languageFor(text: string, lang: string): string {\n const spoken = speechLanguage(text, lang, this.reported?.(text));\n if (spoken !== lang) {\n this.log.debug(`TTS in '${spoken}' instead of '${lang}': \"${String(text).slice(0, 40)}\"`);\n }\n return spoken;\n }\n\n synthesize(text: string, lang: string): Promise<TtsResult> {\n return this.inner.synthesize(text, this.languageFor(text, lang));\n }\n\n synthesizeSsml(ssml: string, lang: string): Promise<TtsResult> {\n const spoken = this.languageFor(ssml.replace(/<[^>]*>/g, ' '), lang);\n return this.inner.synthesizeSsml\n ? this.inner.synthesizeSsml(ssml, spoken)\n : this.inner.synthesize(ssml, spoken);\n }\n\n prepare(lang: string): Promise<void> {\n return this.inner.prepare ? this.inner.prepare(lang) : Promise.resolve();\n }\n\n warm(phrases: string[], lang: string): Promise<number> {\n return this.inner.warm ? this.inner.warm(phrases, lang) : Promise.resolve(0);\n }\n\n voiceGender(lang: string): Promise<VoiceGender | ''> {\n return this.inner.voiceGender ? this.inner.voiceGender(lang) : Promise.resolve('');\n }\n}\n\n/**\n * The voices of the table \"voice per language\": one engine per row, the default engine for every other language.\n * Each engine has its own cache (the directory is per voice).\n */\nexport class VoicePerLanguage implements TtsEngine {\n constructor(\n private readonly fallback: TtsEngine,\n private readonly byLanguage: Record<string, TtsEngine>,\n ) {}\n\n private engineFor(lang: string): TtsEngine {\n return this.byLanguage[baseLanguage(lang)] || this.fallback;\n }\n\n synthesize(text: string, lang: string): Promise<TtsResult> {\n return this.engineFor(lang).synthesize(text, lang);\n }\n\n synthesizeSsml(ssml: string, lang: string): Promise<TtsResult> {\n const engine = this.engineFor(lang);\n return engine.synthesizeSsml ? engine.synthesizeSsml(ssml, lang) : engine.synthesize(ssml, lang);\n }\n\n /** The configured language and every language of the table: a Piper voice is a download of ~60 MB. */\n async prepare(lang: string): Promise<void> {\n await this.engineFor(lang).prepare?.(lang);\n for (const [code, engine] of Object.entries(this.byLanguage)) {\n if (code !== baseLanguage(lang)) {\n await engine.prepare?.(code);\n }\n }\n }\n\n warm(phrases: string[], lang: string): Promise<number> {\n return this.engineFor(lang).warm?.(phrases, lang) ?? Promise.resolve(0);\n }\n\n voiceGender(lang: string): Promise<VoiceGender | ''> {\n return this.engineFor(lang).voiceGender?.(lang) ?? Promise.resolve('');\n }\n}\n"]}
1
+ {"version":3,"file":"speechLanguage.js","sourceRoot":"","sources":["../../../src/lib/voice/speechLanguage.ts"],"names":[],"mappings":";;;AA0DA,oCAKC;AAoDD,wCAkBC;AASD,8CAuBC;AAUD,wCAmBC;AAuCD,4CAwBC;AA+CD,8CAOC;AAYD,oCAGC;AAMD,kDAeC;AAGD,0CAcC;AAGD,gCAGC;AAMD,8CAaC;AAgCD,0CAyBC;AAoBD,wCAaC;AA1cD,+FAA+F;AAC/F,MAAM,SAAS,GAA2B;IACtC,EAAE,EAAE,UAAU;IACd,EAAE,EAAE,UAAU;IACd,EAAE,EAAE,UAAU;IACd,EAAE,EAAE,UAAU;IACd,EAAE,EAAE,UAAU;IACd,EAAE,EAAE,UAAU;IACd,EAAE,EAAE,UAAU;IACd,EAAE,EAAE,OAAO;IACX,EAAE,EAAE,KAAK;IACT,EAAE,EAAE,KAAK;IACT,EAAE,EAAE,QAAQ;IACZ,EAAE,EAAE,QAAQ;IACZ,EAAE,EAAE,QAAQ;IACZ,EAAE,EAAE,QAAQ;CACf,CAAC;AAEF,MAAM,OAAO,GAAuB;IAChC,CAAC,OAAO,EAAE,YAAY,CAAC;IACvB,CAAC,UAAU,EAAE,QAAQ,CAAC;IACtB,CAAC,OAAO,EAAE,QAAQ,CAAC;IACnB,CAAC,KAAK,EAAE,WAAW,CAAC;IACpB,CAAC,QAAQ,EAAE,WAAW,CAAC;IACvB,CAAC,QAAQ,EAAE,QAAQ,CAAC;IACpB,CAAC,QAAQ,EAAE,QAAQ,CAAC;CACvB,CAAC;AAEF,6EAA6E;AAC7E,MAAM,WAAW,GAAG,CAAC,CAAC;AAEtB,+DAA+D;AAC/D,MAAM,SAAS,GAAG,SAAS,CAAC;AAC5B,mCAAmC;AACnC,MAAM,IAAI,GAAG,OAAO,C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AI,CAAC,IAAI,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;IAC5E,CAAC;IAED,WAAW,CAAC,IAAY;QACpB,OAAO,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,WAAW,EAAE,CAAC,IAAI,CAAC,IAAI,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;IAC3E,CAAC;CACJ;AApCD,4CAoCC","sourcesContent":["/**\n * The language an answer is spoken in. The transports hand the TTS the language the satellite listens in, but an\n * answer can be in another one (a question asked in Russian on a German satellite, pi-agent answering in the language\n * of the question). A German voice reads Cyrillic letter by letter (\"kyrillisch a, kyrillisch b …\"), so the TTS\n * takes the language of the text:\n *\n * 1. the language the answering tier reported (pi-agent ≥ 0.10.1 returns `language`), unless the letters contradict it;\n * 2. otherwise the letters: a text in another script than the configured language (Cyrillic, Greek, CJK …) is spoken\n * in the language of that script. Latin letters do not tell German from English: then the configured language\n * stays, unless it is itself written in another script (a Russian satellite answering in Latin letters → English).\n *\n * {@link LanguageTts} applies this in front of every TTS engine; {@link VoicePerLanguage} picks the voice of the\n * table \"voice per language\" for it.\n */\nimport type { TtsEngine, TtsResult } from './tts';\nimport type { VoiceGender } from './voiceGender';\n\nexport type { VoiceGender };\n\ntype Script = 'latin' | 'cyrillic' | 'greek' | 'cjk' | 'hangul' | 'arabic' | 'hebrew';\n\n/** Script of the languages that are not written in Latin letters; everything else is Latin. */\nconst SCRIPT_OF: Record<string, Script> = {\n ru: 'cyrillic',\n uk: 'cyrillic',\n be: 'cyrillic',\n bg: 'cyrillic',\n sr: 'cyrillic',\n mk: 'cyrillic',\n kk: 'cyrillic',\n el: 'greek',\n zh: 'cjk',\n ja: 'cjk',\n ko: 'hangul',\n ar: 'arabic',\n fa: 'arabic',\n he: 'hebrew',\n};\n\nconst LETTERS: [Script, RegExp][] = [\n ['latin', /[a-zÀ-ɏ]/gi],\n ['cyrillic', /[Ѐ-ӿ]/g],\n ['greek', /[Ͱ-Ͽ]/g],\n ['cjk', /[぀-ヿ㐀-鿿]/g],\n ['hangul', /[가-힯ᄀ-ᇿ]/g],\n ['arabic', /[؀-ۿ]/g],\n ['hebrew', /[֐-׿]/g],\n];\n\n/** Fewer letters than this say nothing about the language (\"OK\", \"5 °C\"). */\nconst MIN_LETTERS = 3;\n\n/** Letters only Ukrainian has among the Cyrillic languages. */\nconst UKRAINIAN = /[ґєії]/i;\n/** Kana: Japanese, not Chinese. */\nconst KANA = /[぀-ヿ]/;\n\n/** ISO-639-1 code of a language or locale: 'ru-RU' → 'ru', 'zh-cn' → 'zh'. */\nexport function baseLanguage(lang: string | undefined): string {\n return String(lang || '')\n .trim()\n .split(/[-_]/)[0]\n .toLowerCase();\n}\n\nfunction scriptOf(lang: string): Script {\n return SCRIPT_OF[baseLanguage(lang)] || 'latin';\n}\n\n/** Grammar words of English and German: a device name hardly has two of them, a sentence has. */\nconst LATIN_GRAMMAR = new Set(\n \"the a an is are was it its it's of to and this that there der die das den dem des ein eine einen ist sind war und es nicht\".split(\n ' ',\n ),\n);\n\n/**\n * Does the text carry words of this language's script? For a language not written in Latin letters a few of its\n * letters are enough: \"Температура (Küche): Kueche Sensor 1: 24 °C\" is a Russian sentence with German names in it,\n * and an English voice would read the Russian words badly. Latin letters alone prove nothing (names, units, brands) —\n * unless they carry the grammar of a sentence: \"The lamp \"Свет\" is on.\" is English with a Russian name.\n */\nfunction hasOwnLetters(text: string, lang: string): boolean {\n const script = scriptOf(lang);\n if (script === 'latin') {\n return false;\n }\n const re = LETTERS.find(([s]) => s === script)?.[1];\n if (!re || (text.match(re) || []).length < MIN_LETTERS) {\n return false;\n }\n const latinWords = text.toLowerCase().match(/[a-zà-ɏ']+/g) || [];\n return latinWords.filter(w => LATIN_GRAMMAR.has(w)).length < 2;\n}\n\n/** The script most letters of the text are in; '' for too few letters. */\nfunction dominantScript(text: string): Script | '' {\n let best: Script | '' = '';\n let most = 0;\n let total = 0;\n for (const [script, re] of LETTERS) {\n const count = (text.match(re) || []).length;\n total += count;\n if (count > most) {\n best = script;\n most = count;\n }\n }\n return total >= MIN_LETTERS ? best : '';\n}\n\n/**\n * The language a text is written in as far as its letters tell; '' for Latin letters (German or English?) and for\n * too few letters.\n */\nexport function scriptLanguage(text: string): string {\n const script = dominantScript(String(text || ''));\n switch (script) {\n case 'cyrillic':\n return UKRAINIAN.test(text) ? 'uk' : 'ru';\n case 'greek':\n return 'el';\n case 'cjk':\n return KANA.test(text) ? 'ja' : 'zh';\n case 'hangul':\n return 'ko';\n case 'arabic':\n return 'ar';\n case 'hebrew':\n return 'he';\n default:\n return '';\n }\n}\n\n/**\n * One line for the user turn of a cloud model: \"answer in this language\". The general hint in the system prompt\n * (\"answer in the language of the question\") is not enough for a conversation that ran in another language so far —\n * pi-agent answered a Russian question in German after German turns and a German system prompt.\n *\n * @param lang ISO-639-1 code of the question\n */\nexport function replyLanguageLine(lang: string): string {\n const base = baseLanguage(lang);\n switch (base) {\n case '':\n return '';\n case 'ru':\n return 'Ответь по-русски.';\n case 'uk':\n return 'Відповідай українською.';\n case 'de':\n return 'Antworte auf Deutsch.';\n case 'en':\n return 'Answer in English.';\n default: {\n let name = base;\n try {\n name = new Intl.DisplayNames(['en'], { type: 'language' }).of(base) || base;\n } catch {\n // an unknown code: the code itself\n }\n return `Answer in ${name}.`;\n }\n }\n}\n\n/**\n * The language to speak a text in.\n *\n * @param text what is spoken\n * @param configured the language the caller asked for (the satellite's language)\n * @param reported the language the answering tier reported ('' = none)\n * @returns ISO-639-1 code, or `configured` unchanged when nothing speaks against it\n */\nexport function speechLanguage(text: string, configured: string, reported?: string): string {\n const script = dominantScript(String(text || ''));\n const said = /^[a-z]{2,3}(-[a-z]{2,4})?$/i.test(String(reported || '').trim()) ? baseLanguage(reported) : '';\n // a report is believed unless the letters contradict it (a \"de\" mark on a Cyrillic answer); Latin names inside a\n // Russian sentence do not contradict \"ru\"\n if (said && (!script || scriptOf(said) === script || hasOwnLetters(text, said))) {\n // the configured language in its own form ('de-DE'): same voice, same cache entry\n return said === baseLanguage(configured) ? configured : said;\n }\n if (!script || (!said && script !== scriptOf(configured) && hasOwnLetters(text, configured))) {\n return configured; // too few letters, or a sentence of the configured language with Latin names in it\n }\n const byLetters = scriptLanguage(text);\n if (scriptOf(configured) === script) {\n // the letters fit the configured language; only Ukrainian letters say more than \"Cyrillic\"\n return byLetters === 'uk' && baseLanguage(configured) !== 'uk' ? 'uk' : configured;\n }\n // Latin letters while the satellite speaks Russian: English is the best guess\n return byLetters || 'en';\n}\n\n/**\n * Words that say a Latin-script question is English or German. Only words of one of the two: \"in\", \"an\", \"die\",\n * \"was\", \"will\", \"so\", \"man\" are both and say nothing. Kept to what short spoken commands and questions use.\n */\nconst FUNCTION_WORDS: Record<'en' | 'de', ReadonlySet<string>> = {\n en: new Set(\n (\n \"the what what's whats is are it it's its how turn switch please light lights time me my of to and you your \" +\n 'on off set tell which where when who open close this that temperature weather today tomorrow now much many ' +\n 'does do can could would there all up down timer alarm minutes hours at for be play stop'\n ).split(' '),\n ),\n de: new Set(\n (\n 'der den dem des das ist wie wer wo welche welcher welches schalte schalt mach mache ein eine einen aus bitte ' +\n 'licht spät uhr und im es mir mein meine ich du sind auf zu wieviel viel wetter heute morgen jetzt gibt ' +\n 'alle stelle stell setze öffne schließe temperatur minuten stunden wecker um nach noch lange sag sage mal ' +\n 'kannst spiele spiel'\n ).split(' '),\n ),\n};\n\n/** Function words of `lang` in the words of a text; 0 for a language without a list. */\nfunction functionWords(words: string[], lang: string): number {\n const list = FUNCTION_WORDS[lang as 'en' | 'de'];\n return list ? words.filter(w => list.has(w)).length : 0;\n}\n\n/**\n * The language a question is asked in, for the fixed answers of the rule NLU (\"скажи, сколько сейчас времени\" on a\n * German satellite was answered in German). Another script than the configured language's tells it by the letters\n * (like {@link speechLanguage}); for Latin letters English and German are told apart by function words — only with\n * at least two of them and more than twice as many as of the configured language, so a German command with an\n * English device name stays German and a French question on a French system is not taken for German.\n *\n * @returns ISO-639-1 code, or `configured` unchanged when nothing speaks against it\n */\nexport function questionLanguage(text: string, configured: string): string {\n const question = String(text || '');\n const script = dominantScript(question);\n if (!script) {\n return configured;\n }\n if (script !== 'latin') {\n return speechLanguage(question, configured);\n }\n const words = question.toLowerCase().match(/[\\p{L}']+/gu) || [];\n const base = baseLanguage(configured);\n let best = '';\n let most = 0;\n for (const lang of ['en', 'de']) {\n const hits = functionWords(words, lang);\n if (hits > most) {\n best = lang;\n most = hits;\n }\n }\n if (!best || best === base || most < 2 || most <= 2 * functionWords(words, base)) {\n return configured;\n }\n return best;\n}\n\n/** How many answers {@link AnswerLanguages} remembers. */\nconst KEPT_LANGUAGES = 50;\n\n/**\n * The language of recent answers, by their text. An answer travels as plain text through the tiers and transports to\n * the TTS; this finds its language again there. The key is the text without control markers ([[LISTEN]], [[DONE]]):\n * the assistant takes them out before speaking.\n */\nexport class AnswerLanguages {\n private readonly byText = new Map<string, string>();\n\n private static key(text: string): string {\n return String(text || '')\n .replace(/\\[\\[[A-Z]+\\]\\]/gi, ' ')\n .replace(/\\s+/g, ' ')\n .trim();\n }\n\n /** Remember the language of an answer; anything but an ISO code (`ru`, `en-us`) is ignored. */\n remember(text: string, language: string): void {\n const lang = String(language || '')\n .trim()\n .toLowerCase();\n const key = AnswerLanguages.key(text);\n if (!key || !/^[a-z]{2,3}(-[a-z]{2,4})?$/.test(lang)) {\n return;\n }\n this.byText.delete(key);\n this.byText.set(key, lang);\n if (this.byText.size > KEPT_LANGUAGES) {\n this.byText.delete(this.byText.keys().next().value as string);\n }\n }\n\n /** The language remembered for this answer, '' for none. */\n languageOf(text: string): string {\n return this.byText.get(AnswerLanguages.key(text)) || '';\n }\n}\n\n/**\n * Can this voice speak the language? Told by the locale at the start of its name (`de_DE-thorsten-medium`,\n * `de-DE-KatjaNeural`, `de-DE-Klaus:MAI-Voice-2`); a name without a locale (OpenAI `alloy`, Gemini `Kore`) and a\n * multilingual Azure voice can speak every language.\n */\nexport function voiceFitsLanguage(voice: string, lang: string): boolean {\n const iso = baseLanguage(lang);\n const locale = /^([a-z]{2,3})[-_][A-Z]{2}(?![a-z])/.exec(String(voice || '').trim());\n if (!iso || !locale || /multilingual/i.test(voice)) {\n return true;\n }\n return locale[1] === iso;\n}\n\n/** A row of the table \"voice per language\": the voice and/or the TTS model ('' = the ones set above). */\nexport interface LanguageVoice {\n voice: string;\n model: string;\n}\n\n/**\n * The language code at the start of a table cell: 'de', 'de-DE' → 'de'. The column was a free text field with\n * suggestions, and picking one saved its label ('de – Deutsch'), so the code is read from the start.\n */\nexport function cellLanguage(value: unknown): string {\n const match = typeof value === 'string' ? /^\\s*([a-z]{2,3})(?![a-z])/i.exec(value) : null;\n return match ? match[1].toLowerCase() : '';\n}\n\n/**\n * The table \"voice per language\" with a code in each language cell, or `null` when every cell has one already.\n * The column is a drop-down now, which shows nothing for 'de – Deutsch' or 'de-DE'.\n */\nexport function normalizeVoiceTable(rows: unknown): unknown[] | null {\n if (!Array.isArray(rows)) {\n return null;\n }\n let changed = false;\n const fixed = rows.map(row => {\n const language = (row as { language?: unknown } | null)?.language;\n const code = cellLanguage(language);\n if (!code || code === language) {\n return row;\n }\n changed = true;\n return { ...(row as object), language: code };\n });\n return changed ? fixed : null;\n}\n\n/** Parse the config table \"voice per language\" into ISO code → voice and model; rows without either are skipped. */\nexport function parseVoiceTable(rows: unknown): Record<string, LanguageVoice> {\n const table: Record<string, LanguageVoice> = {};\n if (!Array.isArray(rows)) {\n return table;\n }\n for (const row of rows as { language?: unknown; voice?: unknown; model?: unknown }[]) {\n const lang = cellLanguage(row?.language);\n const voice = typeof row?.voice === 'string' ? row.voice.trim() : '';\n const model = typeof row?.model === 'string' ? row.model.trim() : '';\n if (lang && (voice || model)) {\n table[lang] = { voice, model };\n }\n }\n return table;\n}\n\n/** The gender in a table cell, '' for none. */\nexport function cellGender(value: unknown): VoiceGender | '' {\n const gender = typeof value === 'string' ? value.trim().toLowerCase() : '';\n return gender === 'female' || gender === 'male' ? gender : '';\n}\n\n/**\n * Parse the column \"gender\" of the table \"voice per language\" into ISO code → gender. A row needs no voice for it:\n * language and gender alone tell the gender of the voice set above for that language.\n */\nexport function parseVoiceGenders(rows: unknown): Record<string, VoiceGender> {\n const genders: Record<string, VoiceGender> = {};\n if (!Array.isArray(rows)) {\n return genders;\n }\n for (const row of rows as { language?: unknown; gender?: unknown }[]) {\n const lang = cellLanguage(row?.language);\n const gender = cellGender(row?.gender);\n if (lang && gender) {\n genders[lang] = gender;\n }\n }\n return genders;\n}\n\n/** How one speaks of oneself per gender, as an example for the model. */\nconst SELF_FORMS: Record<string, Record<VoiceGender, string>> = {\n ru: { female: 'я сделала', male: 'я сделал' },\n uk: { female: 'я зробила', male: 'я зробив' },\n be: { female: 'я зрабіла', male: 'я зрабіў' },\n pl: { female: 'zrobiłam', male: 'zrobiłem' },\n cs: { female: 'udělala jsem', male: 'udělal jsem' },\n fr: { female: 'je suis prête', male: 'je suis prêt' },\n es: { female: 'estoy lista', male: 'estoy listo' },\n it: { female: 'sono pronta', male: 'sono pronto' },\n pt: { female: 'obrigada', male: 'obrigado' },\n el: { female: 'είμαι έτοιμη', male: 'είμαι έτοιμος' },\n};\n\n/** Name of a language in the language of the prompt ('Russisch', 'русский'), the code when Node.js has no name. */\nfunction languageName(code: string, inLanguage: string): string {\n try {\n return new Intl.DisplayNames([inLanguage], { type: 'language' }).of(code) || code;\n } catch {\n return code;\n }\n}\n\n/**\n * Instruction for the cloud model (system prompt): the gender of the voice per answer language, so that it speaks of\n * itself in that form. Empty without genders. In the prompt language (de/en/ru), like the other hints.\n *\n * @param genders ISO code → gender of the voice ({@link parseVoiceGenders})\n * @param promptLanguage language of the instructions\n */\nexport function voiceGenderHint(genders: Record<string, VoiceGender>, promptLanguage: string): string {\n const lang = baseLanguage(promptLanguage) === 'ru' ? 'ru' : baseLanguage(promptLanguage) === 'de' ? 'de' : 'en';\n const words: Record<'de' | 'en' | 'ru', Record<VoiceGender, string>> = {\n de: { female: 'weiblich', male: 'männlich' },\n en: { female: 'female', male: 'male' },\n ru: { female: 'женский', male: 'мужской' },\n };\n const not = { de: 'nicht', en: 'not', ru: 'а не' }[lang];\n const items = Object.entries(genders).map(([code, gender]) => {\n const forms = SELF_FORMS[code];\n const other: VoiceGender = gender === 'female' ? 'male' : 'female';\n const example = forms ? ` («${forms[gender]}», ${not} «${forms[other]}»)` : '';\n return `${languageName(code, lang)} – ${words[lang][gender]}${example}`;\n });\n if (!items.length) {\n return '';\n }\n const list = items.join(', ');\n if (lang === 'ru') {\n return `Пол твоего голоса по языку ответа: ${list}. Говоря о себе на этом языке, используй грамматический род этого голоса, и в текстовых ответах тоже.`;\n }\n if (lang === 'de') {\n return `Geschlecht deiner Stimme je Antwortsprache: ${list}. Wenn du in dieser Sprache von dir selbst sprichst, nimm das grammatische Geschlecht dieser Stimme, auch in Textantworten.`;\n }\n return `The gender of your voice per answer language: ${list}. When you speak of yourself in that language, use the grammatical gender of that voice, in text answers too.`;\n}\n\n/** \"Speak of yourself in the feminine\" in the language itself, for the languages {@link SELF_FORMS} knows. */\nconst SELF_GENDER_LINES: Record<string, Record<VoiceGender, string>> = {\n ru: { female: 'О себе говори в женском роде', male: 'О себе говори в мужском роде' },\n uk: { female: 'Про себе говори в жіночому роді', male: 'Про себе говори в чоловічому роді' },\n be: { female: 'Пра сябе кажы ў жаночым родзе', male: 'Пра сябе кажы ў мужчынскім родзе' },\n pl: { female: 'Mów o sobie w rodzaju żeńskim', male: 'Mów o sobie w rodzaju męskim' },\n cs: { female: 'O sobě mluv v ženském rodě', male: 'O sobě mluv v mužském rodě' },\n};\n\n/**\n * One line for the user turn of a cloud model: speak of yourself in the gender of the voice that reads the answer. The\n * hint in the system prompt ({@link voiceGenderHint}) was not enough — pi-agent answered «теперь включил» with a\n * female Russian voice, after earlier turns in the male form. '' for a language whose speaker has no grammatical gender\n * (\"ich habe\", \"I did\") or without a gender.\n *\n * @param lang ISO-639-1 code of the answer\n * @param gender gender of the voice for that language\n */\nexport function selfGenderLine(lang: string, gender: VoiceGender | ''): string {\n const base = baseLanguage(lang);\n const forms = SELF_FORMS[base];\n if (!gender || !forms) {\n return '';\n }\n const other: VoiceGender = gender === 'female' ? 'male' : 'female';\n const own = SELF_GENDER_LINES[base];\n if (own) {\n const not = { ru: 'а не', uk: 'а не', be: 'а не', pl: 'a nie', cs: 'ne' }[base as 'ru'];\n return `${own[gender]}: «${forms[gender]}», ${not} «${forms[other]}».`;\n }\n return `Speak of yourself in the ${gender === 'female' ? 'feminine' : 'masculine'} form: «${forms[gender]}», not «${forms[other]}».`;\n}\n\n/** Log of the TTS layer. */\ninterface Logger {\n debug(msg: string): void;\n}\n\n/**\n * The outermost TTS layer: speaks every text in its own language ({@link speechLanguage}). `reported` looks up the\n * language the answering tier gave for exactly this text.\n */\nexport class LanguageTts implements TtsEngine {\n constructor(\n private readonly inner: TtsEngine,\n private readonly reported: ((text: string) => string | undefined) | undefined,\n private readonly log: Logger,\n ) {}\n\n /** The language `text` is spoken in when the caller asks for `lang`. */\n languageFor(text: string, lang: string): string {\n const spoken = speechLanguage(text, lang, this.reported?.(text));\n if (spoken !== lang) {\n this.log.debug(`TTS in '${spoken}' instead of '${lang}': \"${String(text).slice(0, 40)}\"`);\n }\n return spoken;\n }\n\n synthesize(text: string, lang: string): Promise<TtsResult> {\n return this.inner.synthesize(text, this.languageFor(text, lang));\n }\n\n synthesizeSsml(ssml: string, lang: string): Promise<TtsResult> {\n const spoken = this.languageFor(ssml.replace(/<[^>]*>/g, ' '), lang);\n return this.inner.synthesizeSsml\n ? this.inner.synthesizeSsml(ssml, spoken)\n : this.inner.synthesize(ssml, spoken);\n }\n\n prepare(lang: string): Promise<void> {\n return this.inner.prepare ? this.inner.prepare(lang) : Promise.resolve();\n }\n\n warm(phrases: string[], lang: string): Promise<number> {\n return this.inner.warm ? this.inner.warm(phrases, lang) : Promise.resolve(0);\n }\n\n voiceGender(lang: string): Promise<VoiceGender | ''> {\n return this.inner.voiceGender ? this.inner.voiceGender(lang) : Promise.resolve('');\n }\n}\n\n/**\n * The voices of the table \"voice per language\": one engine per row, the default engine for every other language.\n * Each engine has its own cache (the directory is per voice).\n */\nexport class VoicePerLanguage implements TtsEngine {\n constructor(\n private readonly fallback: TtsEngine,\n private readonly byLanguage: Record<string, TtsEngine>,\n ) {}\n\n private engineFor(lang: string): TtsEngine {\n return this.byLanguage[baseLanguage(lang)] || this.fallback;\n }\n\n synthesize(text: string, lang: string): Promise<TtsResult> {\n return this.engineFor(lang).synthesize(text, lang);\n }\n\n synthesizeSsml(ssml: string, lang: string): Promise<TtsResult> {\n const engine = this.engineFor(lang);\n return engine.synthesizeSsml ? engine.synthesizeSsml(ssml, lang) : engine.synthesize(ssml, lang);\n }\n\n /** The configured language and every language of the table: a Piper voice is a download of ~60 MB. */\n async prepare(lang: string): Promise<void> {\n await this.engineFor(lang).prepare?.(lang);\n for (const [code, engine] of Object.entries(this.byLanguage)) {\n if (code !== baseLanguage(lang)) {\n await engine.prepare?.(code);\n }\n }\n }\n\n warm(phrases: string[], lang: string): Promise<number> {\n return this.engineFor(lang).warm?.(phrases, lang) ?? Promise.resolve(0);\n }\n\n voiceGender(lang: string): Promise<VoiceGender | ''> {\n return this.engineFor(lang).voiceGender?.(lang) ?? Promise.resolve('');\n }\n}\n"]}
package/build/main.js CHANGED
@@ -4059,17 +4059,6 @@ class Assistant extends adapter_core_1.Adapter {
4059
4059
  genderHint() {
4060
4060
  return (0, speechLanguage_1.voiceGenderHint)(this.voiceGenders(), String(this.config.voiceLanguage || this.language || 'en'));
4061
4061
  }
4062
- /**
4063
- * Length instruction for a request that came in by voice: the answer is cut at `ttsMaxChars` before it is
4064
- * spoken, so the model is asked to stay within it. Empty for text requests (chat, Telegram, scripts) and
4065
- * when the limit is off.
4066
- */
4067
- /**
4068
- * "Answer in Russian." after the question for the cloud tiers, when the question tells its language: a conversation
4069
- * that ran in German so far kept answering in German despite the hint in the instructions.
4070
- *
4071
- * @param question the question as asked
4072
- */
4073
4062
  /** The table `wakeWordLanguages` (language and purpose per wake word), parsed once. */
4074
4063
  wakeWordProfiles() {
4075
4064
  this.wakeProfiles ??= (0, wakeWordLanguage_1.parseWakeWordProfiles)(this.config.wakeWordLanguages);
@@ -4100,6 +4089,12 @@ class Assistant extends adapter_core_1.Adapter {
4100
4089
  }
4101
4090
  return 'You are a friendly conversation partner. People can ask you about anything: nature, animals, history, science, cooking, technology, everyday life. Answer from your own knowledge. Your answers are read aloud: plain running text, no Markdown, no lists, no emojis, short and clear. In this conversation you do not control the smart home and do not look at devices; whoever wants to switch something or know what is going on in the house should say the wake word for the house. When you are not sure about a fact, say so.';
4102
4091
  }
4092
+ /**
4093
+ * "Answer in Russian." after the question for the cloud tiers, when the question tells its language: a conversation
4094
+ * that ran in German so far kept answering in German despite the hint in the instructions.
4095
+ *
4096
+ * @param question the question as asked
4097
+ */
4103
4098
  replyLanguageHint(question) {
4104
4099
  const origin = this.requestOrigin.getStore();
4105
4100
  if (!origin?.language) {
@@ -4110,6 +4105,20 @@ class Assistant extends adapter_core_1.Adapter {
4110
4105
  const told = !!origin.listenLanguage || !!(0, speechLanguage_1.scriptLanguage)(question) || origin.language !== configured;
4111
4106
  return told ? (0, speechLanguage_1.replyLanguageLine)(origin.language) : '';
4112
4107
  }
4108
+ /**
4109
+ * "Speak of yourself in the feminine" after the question for the cloud tiers, in the language of the answer, when
4110
+ * its voice has a gender and the language marks it (ru «включила»): the hint in the instructions alone did not
4111
+ * hold — pi-agent answered «теперь включил» with a female Russian voice. Empty for German and English.
4112
+ */
4113
+ replyGenderHint() {
4114
+ const lang = (0, speechLanguage_1.baseLanguage)(this.answerLanguage());
4115
+ return (0, speechLanguage_1.selfGenderLine)(lang, this.voiceGender(lang));
4116
+ }
4117
+ /**
4118
+ * Length instruction for a request that came in by voice: the answer is cut at `ttsMaxChars` before it is
4119
+ * spoken, so the model is asked to stay within it. Empty for text requests (chat, Telegram, scripts) and
4120
+ * when the limit is off.
4121
+ */
4113
4122
  spokenLengthHint() {
4114
4123
  if (!this.config.voiceEnabled || !this.requestOrigin.getStore()?.voice) {
4115
4124
  return '';
@@ -4603,6 +4612,7 @@ class Assistant extends adapter_core_1.Adapter {
4603
4612
  // every time voice and text requests alternate.
4604
4613
  const time = this.buildTimeContext();
4605
4614
  const lengthHint = this.spokenLengthHint();
4615
+ const genderLine = this.replyGenderHint();
4606
4616
  // The pictures themselves go along; only a video needs a word, the model gets nothing of it
4607
4617
  const questionForLlm = [
4608
4618
  time,
@@ -4610,6 +4620,7 @@ class Assistant extends adapter_core_1.Adapter {
4610
4620
  question,
4611
4621
  (0, media_1.attachmentNote)(0, !!video),
4612
4622
  this.replyLanguageHint(question),
4623
+ genderLine,
4613
4624
  lengthHint,
4614
4625
  ]
4615
4626
  .filter(Boolean)
@@ -4628,6 +4639,7 @@ class Assistant extends adapter_core_1.Adapter {
4628
4639
  systemPrompt: style,
4629
4640
  freeTalk: freeTalk || undefined,
4630
4641
  genderHint: gender || undefined,
4642
+ genderLine: genderLine || undefined,
4631
4643
  followUpHint: followUp || undefined,
4632
4644
  doneHint: done || undefined,
4633
4645
  lengthHint: lengthHint || undefined,
@@ -4694,6 +4706,7 @@ class Assistant extends adapter_core_1.Adapter {
4694
4706
  question,
4695
4707
  (0, media_1.attachmentNote)(images.length, !!video),
4696
4708
  this.replyLanguageHint(question),
4709
+ this.replyGenderHint(),
4697
4710
  ]
4698
4711
  .filter(Boolean)
4699
4712
  .join('\n\n');