iobroker.assistant 1.10.0 → 1.11.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.
@@ -33,12 +33,13 @@ var __importStar = (this && this.__importStar) || (function () {
33
33
  };
34
34
  })();
35
35
  Object.defineProperty(exports, "__esModule", { value: true });
36
- exports.EsphomeSatellites = exports.TIMER_EVENT = exports.DIALOG_IDLE_MS = exports.DEFAULT_SPEECH_LEVEL = void 0;
36
+ exports.EsphomeSatellites = exports.TIMER_EVENT = exports.ESPHOME_ESP32 = exports.ESPHOME_ACTIVE_WAKE_WORDS = exports.DIALOG_IDLE_MS = exports.DEFAULT_SPEECH_LEVEL = void 0;
37
37
  exports.yesNoWord = yesNoWord;
38
38
  exports.confirmAnswerOf = confirmAnswerOf;
39
39
  exports.displayLanguageOption = displayLanguageOption;
40
40
  exports.speechLevelOf = speechLevelOf;
41
41
  exports.esphomeAddress = esphomeAddress;
42
+ exports.activeWakeWordLimit = activeWakeWordLimit;
42
43
  /**
43
44
  * ESPHome voice satellites — the fourth transport, next to the UDP server (`voiceServer.ts`) and the
44
45
  * Wyoming endpoint (`wyoming.ts`).
@@ -316,6 +317,23 @@ function esphomeAddress(device) {
316
317
  const port = Number(device.port) || DEFAULT_PORT;
317
318
  return port === DEFAULT_PORT ? ip : `${ip}:${port}`;
318
319
  }
320
+ /** How many wake words an ESPHome device with microWakeWord listens for at once, although it reports 1. */
321
+ exports.ESPHOME_ACTIVE_WAKE_WORDS = 2;
322
+ /** `manufacturer` of the device info of the ESPHome firmware on an ESP32, the only chip microWakeWord runs on. */
323
+ exports.ESPHOME_ESP32 = 'Espressif';
324
+ /**
325
+ * The number of wake words that may be active at once. The ESPHome firmware on an ESP32 (`voice_assistant.cpp`,
326
+ * 2026.10) reports `max_active_wake_words = 1` for microWakeWord, but its `on_set_configuration` enables every id it
327
+ * is sent, and microWakeWord runs all enabled models side by side (like the Home Assistant Voice PE). Two wake words
328
+ * are what a household needs that gives each of its two languages its own one (`wakeWordLanguages`). Every other
329
+ * device keeps what it reports (linux-voice-assistant, ThirdReality and others may really mean 1).
330
+ *
331
+ * @param reported - `max_active_wake_words` of the device
332
+ * @param manufacturer - `manufacturer` of its device info ('' = not known yet)
333
+ */
334
+ function activeWakeWordLimit(reported, manufacturer) {
335
+ return reported === 1 && manufacturer === exports.ESPHOME_ESP32 ? exports.ESPHOME_ACTIVE_WAKE_WORDS : reported;
336
+ }
319
337
  /** `VoiceAssistantTimerEvent` in api.proto. */
320
338
  exports.TIMER_EVENT = { started: 0, updated: 1, cancelled: 2, finished: 3 };
321
339
  /**
@@ -434,7 +452,7 @@ class EsphomeSatellites {
434
452
  return 0;
435
453
  }
436
454
  await Promise.all(targets.map(c => c
437
- .announce(pcm, sampleRate, startConversation)
455
+ .announce(pcm, sampleRate, startConversation, '', true, true)
438
456
  .catch(e => this.opts.log.warn(`announce to ${c.deviceName} failed: ${e.message}`))));
439
457
  return targets.length;
440
458
  }
@@ -448,6 +466,22 @@ class EsphomeConnection {
448
466
  online = false;
449
467
  /** Last wake-word configuration the device reported; null until the handshake answers. */
450
468
  wakeWordConfig = null;
469
+ /**
470
+ * Language of the conversation going on ({@link EsphomeSatellitesOptions.wakeWordLanguage}); '' = `language`.
471
+ * Set by the wake word that starts a conversation; its follow-ups (a question asked, dialog mode) keep it.
472
+ * Back to '' for a microphone without a wake word outside a conversation, when dialog mode ends, and for a
473
+ * question or dialog mode started from ioBroker: those are spoken in the voice language.
474
+ */
475
+ conversationLanguage = '';
476
+ /** `manufacturer` of the device info: "Espressif" = the ESPHome firmware on an ESP32 ({@link activeWakeWordLimit}) */
477
+ manufacturer = '';
478
+ /** The raised wake word limit was logged (once per device) */
479
+ limitLogged = false;
480
+ /**
481
+ * Phrase of the last pipeline start. ESPHome never clears it: a follow-up carries the phrase of the wake word
482
+ * before it. A different phrase is therefore a wake word just said.
483
+ */
484
+ lastWakePhrase = '';
451
485
  /**
452
486
  * One entry per configuration request in flight, in send order (the device answers each one, in
453
487
  * order): the ids a preceding `SetConfiguration` asked for, or null. The read-back is the only
@@ -708,6 +742,7 @@ class EsphomeConnection {
708
742
  const info = message;
709
743
  this.deviceName = info.getName() || this.host;
710
744
  this.friendlyName = info.getFriendlyName?.() || info.getName() || '';
745
+ this.manufacturer = info.getManufacturer?.() || '';
711
746
  this.online = true;
712
747
  this.opts.log.info(`ESPHome satellite online: ${this.deviceName} (${info.getModel()}) @ ${this.host}${this.room ? `, room ${this.room}` : ''}`);
713
748
  this.status('idle');
@@ -728,8 +763,13 @@ class EsphomeConnection {
728
763
  languages: w.getTrainedLanguagesList(),
729
764
  }))
730
765
  .filter(w => !seen.has(w.id) && !!seen.add(w.id)),
731
- max: config.getMaxActiveWakeWords(),
766
+ max: activeWakeWordLimit(config.getMaxActiveWakeWords(), this.manufacturer),
732
767
  };
768
+ if (this.wakeWordConfig.max !== config.getMaxActiveWakeWords() && !this.limitLogged) {
769
+ this.limitLogged = true;
770
+ this.opts.log.info(`ESPHome ${this.deviceName}: allowing ${this.wakeWordConfig.max} active wake words — the firmware ` +
771
+ `reports ${config.getMaxActiveWakeWords()}, but microWakeWord on an ESP32 runs every one it is sent`);
772
+ }
733
773
  const active = this.wakeWordConfig.active.join(', ') || '(none active)';
734
774
  const available = this.wakeWordConfig.available.map(w => w.id);
735
775
  this.opts.log.info(`ESPHome ${this.deviceName}: wake words ${active}${available.length ? ` (available: ${available.join(', ')})` : ''}`);
@@ -870,11 +910,16 @@ class EsphomeConnection {
870
910
  }
871
911
  /** Pass a button answer on and announce the reply (see {@link onConfirmButton}). */
872
912
  async answerButton(yes, run) {
873
- const text = yesNoWord(this.opts.language, yes);
913
+ const text = yesNoWord(this.speechLanguage(), yes);
874
914
  this.opts.log.info(`ESPHome ${this.deviceName}: answered "${text}" with the button`);
875
915
  this.status('processing');
876
916
  try {
877
- const answer = (await this.opts.answer(text, { device: this.deviceName, room: this.room, button: yes ? 'yes' : 'no' })).trim();
917
+ const answer = (await this.opts.answer(text, {
918
+ device: this.deviceName,
919
+ room: this.room,
920
+ language: this.speechLanguage(),
921
+ button: yes ? 'yes' : 'no',
922
+ })).trim();
878
923
  if (run !== this.run) {
879
924
  return;
880
925
  }
@@ -884,7 +929,7 @@ class EsphomeConnection {
884
929
  }
885
930
  const followUp = this.opts.expectsFollowUp?.(answer, this.deviceName) === true;
886
931
  const ttsStart = Date.now();
887
- const { pcm, sampleRate } = await this.opts.tts.synthesize(answer, this.opts.language);
932
+ const { pcm, sampleRate } = await this.opts.tts.synthesize(answer, this.speechLanguage());
888
933
  if (run !== this.run) {
889
934
  return;
890
935
  }
@@ -936,6 +981,10 @@ class EsphomeConnection {
936
981
  this.send(message);
937
982
  }
938
983
  // ── voice pipeline ──────────────────────────────────────────────────────────────────────────────
984
+ /** Language of the current conversation: the one of its wake word, else the voice language. */
985
+ speechLanguage() {
986
+ return this.conversationLanguage || this.opts.language;
987
+ }
939
988
  onPipelineRequest(request) {
940
989
  if (!request.getStart()) {
941
990
  this.onStopRequest();
@@ -968,6 +1017,21 @@ class EsphomeConnection {
968
1017
  // In dialog mode every microphone is the next turn: the phrase is the stale one of the last wake word.
969
1018
  const dialog = this.dialogOn;
970
1019
  const followUp = answersQuestion || !phrase || dialog;
1020
+ // Another phrase than last time was just said (a follow-up repeats the last one): its language counts, also
1021
+ // while a question is open or in dialog mode. Unknown after a restart of the adapter: then only a new
1022
+ // conversation sets the language, or the answer to a question from ioBroker would get the old wake word's.
1023
+ const newWakeWord = !!phrase && !!this.lastWakePhrase && phrase !== this.lastWakePhrase;
1024
+ if (phrase) {
1025
+ this.lastWakePhrase = phrase;
1026
+ }
1027
+ if (!followUp || newWakeWord) {
1028
+ // a new conversation: the language of its wake word; the follow-ups keep it
1029
+ this.conversationLanguage = this.opts.wakeWordLanguage?.(phrase, this.wakeWordConfig) || '';
1030
+ }
1031
+ else if (!answersQuestion && !dialog) {
1032
+ // a conversation that starts without a wake word: the voice language, not the one of an old conversation
1033
+ this.conversationLanguage = '';
1034
+ }
971
1035
  this.opts.log.debug(`ESPHome ${this.deviceName}: ${answersQuestion
972
1036
  ? 'answer to the question'
973
1037
  : dialog
@@ -1046,6 +1110,10 @@ class EsphomeConnection {
1046
1110
  return;
1047
1111
  }
1048
1112
  this.dialogOn = on;
1113
+ if (!on) {
1114
+ // the dialog was the conversation: the next one starts in the language of its own wake word
1115
+ this.conversationLanguage = '';
1116
+ }
1049
1117
  this.dialogHeardAt = Date.now();
1050
1118
  this.dialogReplyAt = 0;
1051
1119
  this.cancelDialogReopen();
@@ -1070,6 +1138,8 @@ class EsphomeConnection {
1070
1138
  this.dialogTimer = setInterval(() => this.checkDialogIdle(), DIALOG_CHECK_MS);
1071
1139
  this.dialogTimer.unref();
1072
1140
  if (open && this.online && !this.capture && !this.runOpen) {
1141
+ // switched on from ioBroker, not by a request: no wake word, the voice language
1142
+ this.conversationLanguage = '';
1073
1143
  this.noteDialogReply((open.pcm.length / 2 / open.sampleRate) * 1000);
1074
1144
  void this.announce(open.pcm, open.sampleRate, true, '', false).catch(e => this.opts.log.warn(`ESPHome ${this.deviceName}: opening the microphone failed — ${e.message}`));
1075
1145
  }
@@ -1322,7 +1392,7 @@ class EsphomeConnection {
1322
1392
  this.opts.log.debug(`ESPHome ${this.deviceName}: speech recognition gets ${(speech.fromMs / 1000).toFixed(2)}–` +
1323
1393
  `${(speech.toMs / 1000).toFixed(2)} s${speech.gain > 1 ? `, amplified ×${speech.gain}` : ''}`);
1324
1394
  const sttStart = Date.now();
1325
- const text = (await this.opts.stt.transcribe(speech.pcm, MIC_SAMPLE_RATE, this.opts.language, hints)).trim();
1395
+ const text = (await this.opts.stt.transcribe(speech.pcm, MIC_SAMPLE_RATE, this.speechLanguage(), hints)).trim();
1326
1396
  const sttMs = Date.now() - sttStart;
1327
1397
  if (!current()) {
1328
1398
  return;
@@ -1354,6 +1424,7 @@ class EsphomeConnection {
1354
1424
  device: this.deviceName,
1355
1425
  room: this.room,
1356
1426
  wakeWord: capture.wakeWord,
1427
+ language: this.speechLanguage(),
1357
1428
  sttMs,
1358
1429
  audioMs: Math.round(seconds * 1000),
1359
1430
  // Numbers only, no audio: shows where a request was cut off without keeping recordings.
@@ -1381,7 +1452,7 @@ class EsphomeConnection {
1381
1452
  return;
1382
1453
  }
1383
1454
  const ttsStart = Date.now();
1384
- const { pcm: ttsPcm, sampleRate } = await this.opts.tts.synthesize(answer, this.opts.language);
1455
+ const { pcm: ttsPcm, sampleRate } = await this.opts.tts.synthesize(answer, this.speechLanguage());
1385
1456
  if (!current()) {
1386
1457
  return;
1387
1458
  }
@@ -1532,11 +1603,18 @@ class EsphomeConnection {
1532
1603
  /**
1533
1604
  * Speak a ready PCM buffer on this device (timers, alarms, `tts.text`, jingles). With
1534
1605
  * `startConversation` the microphone opens once the clip has played, to catch the answer to a question.
1606
+ * `fromOutside`: the question comes from ioBroker (a script, a trigger), not from a request of this device, so its
1607
+ * answer is heard in the voice language.
1535
1608
  */
1536
- async announce(pcm, sampleRate, startConversation = false, text = '', question = true) {
1609
+ async announce(pcm, sampleRate, startConversation = false, text = '', question = true, fromOutside = false) {
1537
1610
  if (!this.online || !pcm.length) {
1538
1611
  return;
1539
1612
  }
1613
+ if (startConversation && fromOutside) {
1614
+ // A question of a script or trigger is asked in the voice language: the answer is heard in it, not in
1615
+ // the language of a wake word said hours ago.
1616
+ this.conversationLanguage = '';
1617
+ }
1540
1618
  const request = new esphomeProto_1.pb.VoiceAssistantAnnounceRequest();
1541
1619
  request.setMediaId(await this.publish(pcm, sampleRate));
1542
1620
  // What a device with a screen shows while it plays (its on_tts_start)