@memori.ai/memori-react 1.0.0-alpha.21 → 1.0.0-alpha.23

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.
@@ -78,6 +78,7 @@ let recognizer;
78
78
  let speechConfig;
79
79
  let speechSynthesizer;
80
80
  let audioDestination;
81
+ let audioContext;
81
82
  const MemoriWidget = ({ memori, memoriConfigs, memoriLang, integration, showInstruct = false, showShare = true, preview = false, embed = false, showInputs = true, showDates = false, showContextPerLine = false, showSettings = false, height = '100vh', secret, baseUrl = 'https://app.twincreator.com', apiUrl = 'https://backend.memori.ai', initialContextVars, initialQuestion, ogImage, sessionID: initialSessionID, tenant, personification, authToken, AZURE_COGNITIVE_SERVICES_TTS_KEY, onStateChange, }) => {
82
83
  var _a, _b, _c, _d, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _t, _u, _v;
83
84
  const { t, i18n } = useTranslation();
@@ -104,7 +105,7 @@ const MemoriWidget = ({ memori, memoriConfigs, memoriLang, integration, showInst
104
105
  const [showPositionDrawer, setShowPositionDrawer] = useState(false);
105
106
  const [showSettingsDrawer, setShowSettingsDrawer] = useState(false);
106
107
  const [muteSpeaker, setMuteSpeaker] = useState(false);
107
- const [continuousSpeech, setContinuousSpeech] = useState(false);
108
+ const [continuousSpeech, setContinuousSpeech] = useState(true);
108
109
  const [continuousSpeechTimeout, setContinuousSpeechTimeout] = useState(3);
109
110
  const [isPlayingAudio, setIsPlayingAudio] = useState(false);
110
111
  useEffect(() => {
@@ -112,7 +113,7 @@ const MemoriWidget = ({ memori, memoriConfigs, memoriLang, integration, showInst
112
113
  }, [speechSynthesizer]);
113
114
  useEffect(() => {
114
115
  setMuteSpeaker(getLocalConfig('muteSpeaker', false));
115
- setContinuousSpeech(getLocalConfig('continuousSpeech', false));
116
+ setContinuousSpeech(getLocalConfig('continuousSpeech', true));
116
117
  setContinuousSpeechTimeout(getLocalConfig('continuousSpeechTimeout', 3));
117
118
  }, []);
118
119
  const [memoriPwd, setMemoriPwd] = useState(secret);
@@ -191,6 +192,7 @@ const MemoriWidget = ({ memori, memoriConfigs, memoriLang, integration, showInst
191
192
  media: currentState.media,
192
193
  fromUser: false,
193
194
  });
195
+ speak(currentState.emission);
194
196
  }
195
197
  }
196
198
  else {
@@ -213,6 +215,7 @@ const MemoriWidget = ({ memori, memoriConfigs, memoriLang, integration, showInst
213
215
  media: currentState.media,
214
216
  fromUser: false,
215
217
  });
218
+ speak(currentState.emission);
216
219
  }
217
220
  }
218
221
  else {
@@ -229,28 +232,34 @@ const MemoriWidget = ({ memori, memoriConfigs, memoriLang, integration, showInst
229
232
  emission &&
230
233
  !instruct &&
231
234
  isMultilanguageEnabled) {
232
- translateDialogState(currentState, userLang);
235
+ translateDialogState(currentState, userLang).then(ts => {
236
+ if (ts.emission) {
237
+ speak(ts.emission);
238
+ }
239
+ });
233
240
  }
234
241
  else {
235
242
  setCurrentDialogState({
236
243
  ...currentState,
237
244
  emission,
238
245
  });
239
- if (emission)
246
+ if (emission) {
240
247
  pushMessage({
241
248
  text: emission,
242
249
  media: currentState.media,
243
250
  fromUser: false,
244
251
  });
252
+ speak(emission);
253
+ }
245
254
  }
246
255
  }
247
256
  else if (response.resultCode === 404) {
248
257
  setHistory(h => [...h.slice(0, h.length - 1)]);
249
- reopenSession(false, memoriPwd || memori.secretToken, memoriTokens, instruct && memori.giverTag ? memori.giverTag : undefined, instruct && memori.giverPIN ? memori.giverPIN : undefined, initialContextVars, initialQuestion).then(sessionID => {
258
+ reopenSession(false, memoriPwd || memori.secretToken, memoriTokens, instruct && memori.giverTag ? memori.giverTag : undefined, instruct && memori.giverPIN ? memori.giverPIN : undefined, initialContextVars, initialQuestion).then(state => {
250
259
  console.info('session timeout');
251
- if (sessionID) {
260
+ if (state === null || state === void 0 ? void 0 : state.sessionID) {
252
261
  setTimeout(() => {
253
- sendMessage(text, media, sessionID);
262
+ sendMessage(text, media, state === null || state === void 0 ? void 0 : state.sessionID);
254
263
  }, 500);
255
264
  }
256
265
  });
@@ -321,7 +330,7 @@ const MemoriWidget = ({ memori, memoriConfigs, memoriLang, integration, showInst
321
330
  }
322
331
  };
323
332
  const fetchSession = async (params) => {
324
- var _a, _b, _c, _d, _f;
333
+ var _a;
325
334
  if (memori.privacyType !== 'PUBLIC' &&
326
335
  !memori.secretToken &&
327
336
  !memoriPwd &&
@@ -343,50 +352,6 @@ const MemoriWidget = ({ memori, memoriConfigs, memoriLang, integration, showInst
343
352
  (session === null || session === void 0 ? void 0 : session.currentState) &&
344
353
  session.resultCode === 0) {
345
354
  setSessionId(session.sessionID);
346
- const language = (_f = (_d = (_c = (_b = memori.culture) === null || _b === void 0 ? void 0 : _b.split('-')) === null || _c === void 0 ? void 0 : _c[0]) !== null && _d !== void 0 ? _d : i18n.language) !== null && _f !== void 0 ? _f : 'IT';
347
- if (!instruct &&
348
- isMultilanguageEnabled &&
349
- userLang.toLowerCase() !== language.toLowerCase()) {
350
- translateDialogState(session.currentState, userLang).then(state => {
351
- if (state === null || state === void 0 ? void 0 : state.emission) {
352
- history.length <= 1
353
- ? setHistory([
354
- {
355
- text: state.emission,
356
- media: state.media,
357
- fromUser: false,
358
- initial: true,
359
- },
360
- ])
361
- : pushMessage({
362
- text: state.emission,
363
- media: state.media,
364
- fromUser: false,
365
- initial: true,
366
- });
367
- }
368
- });
369
- }
370
- else {
371
- setCurrentDialogState(session.currentState);
372
- if (session.currentState.emission) {
373
- history.length <= 1
374
- ? setHistory([
375
- {
376
- text: session.currentState.emission,
377
- media: session.currentState.media,
378
- fromUser: false,
379
- initial: true,
380
- },
381
- ])
382
- : pushMessage({
383
- text: session.currentState.emission,
384
- media: session.currentState.media,
385
- fromUser: false,
386
- initial: true,
387
- });
388
- }
389
- }
390
355
  if (position)
391
356
  applyPosition(position, session.sessionID);
392
357
  setLoading(false);
@@ -442,7 +407,10 @@ const MemoriWidget = ({ memori, memoriConfigs, memoriLang, integration, showInst
442
407
  if (position)
443
408
  applyPosition(position, sessionID);
444
409
  setLoading(false);
445
- return sessionID;
410
+ return {
411
+ dialogState: currentState,
412
+ sessionID,
413
+ };
446
414
  }
447
415
  else {
448
416
  console.error(response);
@@ -565,7 +533,11 @@ const MemoriWidget = ({ memori, memoriConfigs, memoriLang, integration, showInst
565
533
  userLang !== (i18n === null || i18n === void 0 ? void 0 : i18n.language) &&
566
534
  emission &&
567
535
  emission.length > 0) {
568
- translateDialogState({ ...currentState, emission: emission }, userLang);
536
+ translateDialogState({ ...currentState, emission: emission }, userLang).then(ts => {
537
+ if (ts.emission) {
538
+ speak(ts.emission);
539
+ }
540
+ });
569
541
  }
570
542
  else if (emission && emission.length > 0) {
571
543
  pushMessage({
@@ -573,6 +545,7 @@ const MemoriWidget = ({ memori, memoriConfigs, memoriLang, integration, showInst
573
545
  media: currentState.media,
574
546
  fromUser: false,
575
547
  });
548
+ speak(emission);
576
549
  setCurrentDialogState(currentState);
577
550
  }
578
551
  }
@@ -627,39 +600,15 @@ const MemoriWidget = ({ memori, memoriConfigs, memoriLang, integration, showInst
627
600
  if (hasTouchscreen())
628
601
  speechConfig.speechSynthesisOutputFormat =
629
602
  speechSdk.SpeechSynthesisOutputFormat.Audio16Khz32KBitRateMonoMp3;
630
- let memoriAudioElement = document.getElementById('memori-audio');
631
- if (memoriAudioElement && window.navigator.userAgent.includes('Safari')) {
632
- memoriAudioElement.muted = false;
633
- memoriAudioElement
634
- .play()
635
- .then(() => {
636
- console.log('played intro audio');
637
- try {
638
- const context = new AudioContext();
639
- let buffer = context.createBuffer(1, 1, 22050);
640
- let source = context.createBufferSource();
641
- source.buffer = buffer;
642
- source.connect(context.destination);
643
- }
644
- catch (e) {
645
- console.error(e);
646
- }
647
- })
648
- .catch((e) => {
649
- console.error('error playing intro audio', e);
650
- });
651
- }
603
+ audioContext = new AudioContext();
604
+ let buffer = audioContext.createBuffer(1, 10000, 22050);
605
+ let source = audioContext.createBufferSource();
606
+ source.buffer = buffer;
607
+ source.connect(audioContext.destination);
608
+ audioDestination = new speechSdk.SpeakerAudioDestination();
609
+ let audioConfig = speechSdk.AudioConfig.fromSpeakerOutput(audioDestination);
610
+ speechSynthesizer = new speechSdk.SpeechSynthesizer(speechConfig, audioConfig);
652
611
  };
653
- useEffect(() => {
654
- return () => {
655
- if (audioDestination)
656
- audioDestination.pause();
657
- if (speechSynthesizer) {
658
- speechSynthesizer.close();
659
- speechSynthesizer = null;
660
- }
661
- };
662
- }, []);
663
612
  const getTTSVoice = useCallback((lang) => {
664
613
  var _a, _b, _c, _d;
665
614
  let voice = '';
@@ -714,9 +663,11 @@ const MemoriWidget = ({ memori, memoriConfigs, memoriLang, integration, showInst
714
663
  return voice;
715
664
  }, [memori.voiceType, i18n.language, memori.culture]);
716
665
  const getCultureCodeByLanguage = (lang) => {
717
- var _a, _b, _c;
666
+ var _a, _b;
718
667
  let voice = '';
719
- let voiceLang = ((_c = lang !== null && lang !== void 0 ? lang : (_b = (_a = memori.culture) === null || _a === void 0 ? void 0 : _a.split('-')) === null || _b === void 0 ? void 0 : _b[0]) !== null && _c !== void 0 ? _c : i18n.language,
668
+ let voiceLang = (lang ||
669
+ ((_b = (_a = memori.culture) === null || _a === void 0 ? void 0 : _a.split('-')) === null || _b === void 0 ? void 0 : _b[0]) ||
670
+ i18n.language ||
720
671
  'IT').toUpperCase();
721
672
  switch (voiceLang) {
722
673
  case 'IT':
@@ -783,45 +734,66 @@ const MemoriWidget = ({ memori, memoriConfigs, memoriLang, integration, showInst
783
734
  }, text);
784
735
  return ssmlText;
785
736
  };
786
- const speak = (text, fireListeningEvent = true) => {
737
+ const speak = (text) => {
787
738
  console.log(AZURE_COGNITIVE_SERVICES_TTS_KEY, hasUserActivatedSpeak, preview);
788
739
  if (!AZURE_COGNITIVE_SERVICES_TTS_KEY)
789
740
  return;
790
- if (preview || !hasUserActivatedSpeak)
741
+ if (listening) {
742
+ stopListening();
743
+ }
744
+ if (preview)
791
745
  return;
792
746
  if (audioDestination)
793
747
  audioDestination.pause();
794
- if (speechSynthesizer) {
795
- speechSynthesizer.close();
796
- speechSynthesizer = null;
748
+ let isSafari = window.navigator.userAgent.includes('Safari') &&
749
+ !window.navigator.userAgent.includes('Chrome');
750
+ let isIOS = /iPad|iPhone|iPod/.test(navigator.userAgent);
751
+ if (isIOS && isSafari) {
752
+ audioContext.suspend();
797
753
  }
798
- if (muteSpeaker && fireListeningEvent) {
799
- setTimeout(() => {
800
- document.dispatchEvent(new Event('endSpeakStartListen'));
801
- }, 3000);
802
- return;
754
+ else if (audioContext.state === 'suspended') {
755
+ stopAudio();
756
+ audioContext = new AudioContext();
757
+ let buffer = audioContext.createBuffer(1, 10000, 22050);
758
+ let source = audioContext.createBufferSource();
759
+ source.buffer = buffer;
760
+ source.connect(audioContext.destination);
803
761
  }
804
- else if (muteSpeaker) {
762
+ if (!speechSynthesizer) {
763
+ audioDestination = new speechSdk.SpeakerAudioDestination();
764
+ let audioConfig = speechSdk.AudioConfig.fromSpeakerOutput(audioDestination);
765
+ speechSynthesizer = new speechSdk.SpeechSynthesizer(speechConfig, audioConfig);
766
+ }
767
+ if (muteSpeaker) {
768
+ if (continuousSpeech) {
769
+ setListeningTimeout();
770
+ }
805
771
  return;
806
772
  }
807
- audioDestination = new speechSdk.SpeakerAudioDestination();
808
- let audioConfig = speechSdk.AudioConfig.fromSpeakerOutput(audioDestination);
809
- speechSynthesizer = new speechSdk.SpeechSynthesizer(speechConfig, audioConfig);
810
773
  audioDestination.onAudioEnd = () => {
811
774
  setIsPlayingAudio(false);
812
- if (fireListeningEvent) {
775
+ if (continuousSpeech) {
813
776
  document.dispatchEvent(new Event('endSpeakStartListen'));
814
777
  }
815
778
  };
816
779
  setIsPlayingAudio(true);
817
- console.log('speaking', text);
818
- console.log('speechSynthesizer', speechSynthesizer);
819
- console.log('audioDestination', audioDestination);
820
- console.log('speechConfig', speechConfig);
821
- console.log('audioConfig', audioConfig);
780
+ speechSynthesizer.synthesisCompleted = (s, e) => {
781
+ console.log('synthesisCompleted', s, e);
782
+ setIsPlayingAudio(false);
783
+ };
822
784
  speechSynthesizer.speakSsmlAsync(`<speak version="1.0" xmlns="http://www.w3.org/2001/10/synthesis" xmlns:mstts="https://www.w3.org/2001/mstts" xmlns:emo="http://www.w3.org/2009/10/emotionml" xml:lang="${getCultureCodeByLanguage(userLang)}"><voice name="${getTTSVoice(userLang)}"><s>${replaceTextWithPhonemes(text, userLang.toLowerCase())}</s></voice></speak>`, result => {
823
785
  if (result) {
786
+ console.log('result', result);
824
787
  try {
788
+ audioContext.decodeAudioData(result.audioData, function (buffer) {
789
+ const source = audioContext.createBufferSource();
790
+ source.buffer = buffer;
791
+ source.connect(audioContext.destination);
792
+ if (history.length < 1 || (isSafari && isIOS)) {
793
+ source.start(0);
794
+ }
795
+ });
796
+ audioContext.resume();
825
797
  if (speechSynthesizer) {
826
798
  speechSynthesizer.close();
827
799
  speechSynthesizer = null;
@@ -831,10 +803,14 @@ const MemoriWidget = ({ memori, memoriConfigs, memoriLang, integration, showInst
831
803
  console.error('speak error: ', e);
832
804
  window.speechSynthesis.speak(new SpeechSynthesisUtterance(text));
833
805
  setIsPlayingAudio(false);
806
+ if (speechSynthesizer) {
807
+ speechSynthesizer.close();
808
+ speechSynthesizer = null;
809
+ }
834
810
  }
835
811
  }
836
812
  else {
837
- window.speechSynthesis.speak(new SpeechSynthesisUtterance(text));
813
+ audioContext.resume();
838
814
  setIsPlayingAudio(false);
839
815
  }
840
816
  }, error => {
@@ -843,12 +819,20 @@ const MemoriWidget = ({ memori, memoriConfigs, memoriLang, integration, showInst
843
819
  setIsPlayingAudio(false);
844
820
  });
845
821
  setIsPlayingAudio(false);
822
+ setMemoriTyping(false);
846
823
  };
847
824
  const stopAudio = () => {
848
825
  if (speechSynthesizer) {
849
826
  speechSynthesizer.close();
850
827
  speechSynthesizer = null;
851
828
  }
829
+ if (audioContext) {
830
+ audioContext.close();
831
+ }
832
+ if (audioDestination) {
833
+ audioDestination.pause();
834
+ audioDestination.close();
835
+ }
852
836
  };
853
837
  useEffect(() => {
854
838
  let textarea = document.querySelector('#chat-fieldset textarea');
@@ -887,11 +871,6 @@ const MemoriWidget = ({ memori, memoriConfigs, memoriLang, integration, showInst
887
871
  useEffect(() => {
888
872
  resetListeningTimeout();
889
873
  resetInteractionTimeout();
890
- if ((transcript === null || transcript === void 0 ? void 0 : transcript.length) > 0) {
891
- const transcriptMessage = stripDuplicates(transcript);
892
- if (transcriptMessage.length > 0)
893
- setUserMessage(transcriptMessage);
894
- }
895
874
  }, [transcript]);
896
875
  const startListening = () => {
897
876
  console.log('start listening');
@@ -917,9 +896,14 @@ const MemoriWidget = ({ memori, memoriConfigs, memoriLang, integration, showInst
917
896
  recognizer = new speechSdk.SpeechRecognizer(speechConfig, audioConfig);
918
897
  setListening(true);
919
898
  recognizer.recognized = (_s, e) => {
920
- var _a;
921
899
  if (e.result.reason === speechSdk.ResultReason.RecognizedSpeech) {
922
- setTranscript((_a = e.result.text) !== null && _a !== void 0 ? _a : '');
900
+ let transcript = e.result.text;
901
+ setTranscript(transcript || '');
902
+ if ((transcript === null || transcript === void 0 ? void 0 : transcript.length) > 0) {
903
+ const transcriptMessage = stripDuplicates(transcript);
904
+ if (transcriptMessage.length > 0)
905
+ setUserMessage(transcriptMessage);
906
+ }
923
907
  }
924
908
  else if (e.result.reason === speechSdk.ResultReason.NoMatch) {
925
909
  console.debug('NOMATCH: Speech could not be recognized.');
@@ -934,8 +918,7 @@ const MemoriWidget = ({ memori, memoriConfigs, memoriLang, integration, showInst
934
918
  stopListening();
935
919
  };
936
920
  recognizer.sessionStopped = (_s, _e) => {
937
- if (recognizer)
938
- recognizer.stopContinuousRecognitionAsync();
921
+ stopListening();
939
922
  };
940
923
  recognizer.startContinuousRecognitionAsync();
941
924
  })
@@ -950,8 +933,8 @@ const MemoriWidget = ({ memori, memoriConfigs, memoriLang, integration, showInst
950
933
  recognizer.stopContinuousRecognitionAsync();
951
934
  recognizer.close();
952
935
  recognizer = null;
953
- setListening(false);
954
936
  }
937
+ setListening(false);
955
938
  };
956
939
  const clearListening = () => {
957
940
  setHasUserActivatedListening(false);
@@ -973,15 +956,6 @@ const MemoriWidget = ({ memori, memoriConfigs, memoriLang, integration, showInst
973
956
  if ((currentDialogState === null || currentDialogState === void 0 ? void 0 : currentDialogState.state) === 'Z0')
974
957
  clearListening();
975
958
  }, [currentDialogState === null || currentDialogState === void 0 ? void 0 : currentDialogState.state]);
976
- useEffect(() => {
977
- if (hasUserActivatedSpeak &&
978
- !preview &&
979
- !muteSpeaker &&
980
- history.length > 0 &&
981
- (currentDialogState === null || currentDialogState === void 0 ? void 0 : currentDialogState.emission)) {
982
- speak(currentDialogState.emission, currentDialogState.state !== 'Z0');
983
- }
984
- }, [currentDialogState, hasUserActivatedSpeak]);
985
959
  const [requestedListening, setRequestedListening] = useState(false);
986
960
  const onEndSpeakStartListen = useCallback((_e) => {
987
961
  if (isPlayingAudio && speechSynthesizer) {
@@ -1185,7 +1159,15 @@ const MemoriWidget = ({ memori, memoriConfigs, memoriLang, integration, showInst
1185
1159
  const sessionID = (session === null || session === void 0 ? void 0 : session.sessionID) || sessionId;
1186
1160
  const dialogState = (session === null || session === void 0 ? void 0 : session.dialogState) || currentDialogState;
1187
1161
  setClickedStart(true);
1188
- console.log('onClickStart');
1162
+ let memoriAudioElement = document.getElementById('memori-audio');
1163
+ let isSafari = window.navigator.userAgent.includes('Safari') &&
1164
+ !window.navigator.userAgent.includes('Chrome');
1165
+ if (memoriAudioElement && isSafari) {
1166
+ memoriAudioElement.muted = false;
1167
+ memoriAudioElement.play().catch((e) => {
1168
+ console.error('error playing intro audio', e);
1169
+ });
1170
+ }
1189
1171
  if ((!sessionID &&
1190
1172
  memori.privacyType !== 'PUBLIC' &&
1191
1173
  !memori.secretToken &&
@@ -1207,7 +1189,7 @@ const MemoriWidget = ({ memori, memoriConfigs, memoriLang, integration, showInst
1207
1189
  initialContextVars,
1208
1190
  initialQuestion,
1209
1191
  });
1210
- onClickStart(session || undefined);
1192
+ await onClickStart(session || undefined);
1211
1193
  return;
1212
1194
  }
1213
1195
  else if (initialSessionID) {
@@ -1217,7 +1199,7 @@ const MemoriWidget = ({ memori, memoriConfigs, memoriLang, integration, showInst
1217
1199
  setGotErrorInOpening(true);
1218
1200
  setSessionId(undefined);
1219
1201
  setClickedStart(false);
1220
- onClickStart();
1202
+ await onClickStart();
1221
1203
  return;
1222
1204
  }
1223
1205
  setHistory([]);
@@ -1229,7 +1211,13 @@ const MemoriWidget = ({ memori, memoriConfigs, memoriLang, integration, showInst
1229
1211
  await changeTag(memori.engineMemoriID, sessionID, '-');
1230
1212
  const session = await changeTag(memori.engineMemoriID, sessionID, memori.giverTag, memori.giverPIN);
1231
1213
  if (session && session.resultCode === 0) {
1232
- translateDialogState(session.currentState, userLang).finally(() => {
1214
+ translateDialogState(session.currentState, userLang)
1215
+ .then(ts => {
1216
+ if (ts.emission) {
1217
+ speak(ts.emission);
1218
+ }
1219
+ })
1220
+ .finally(() => {
1233
1221
  setHasUserActivatedSpeak(true);
1234
1222
  });
1235
1223
  }
@@ -1253,7 +1241,13 @@ const MemoriWidget = ({ memori, memoriConfigs, memoriLang, integration, showInst
1253
1241
  await changeTag(memori.engineMemoriID, sessionID, '-');
1254
1242
  const session = await changeTag(memori.engineMemoriID, sessionID, personification.tag, personification.pin);
1255
1243
  if (session && session.resultCode === 0) {
1256
- translateDialogState(session.currentState, userLang).finally(() => {
1244
+ translateDialogState(session.currentState, userLang)
1245
+ .then(ts => {
1246
+ if (ts.emission) {
1247
+ speak(ts.emission);
1248
+ }
1249
+ })
1250
+ .finally(() => {
1257
1251
  setHasUserActivatedSpeak(true);
1258
1252
  });
1259
1253
  }
@@ -1277,7 +1271,13 @@ const MemoriWidget = ({ memori, memoriConfigs, memoriLang, integration, showInst
1277
1271
  await changeTag(memori.engineMemoriID, sessionID, '-');
1278
1272
  const session = await changeTag(memori.engineMemoriID, sessionID, anonTag);
1279
1273
  if (session && session.resultCode === 0) {
1280
- translateDialogState(session.currentState, userLang).finally(() => {
1274
+ translateDialogState(session.currentState, userLang)
1275
+ .then(ts => {
1276
+ if (ts.emission) {
1277
+ speak(ts.emission);
1278
+ }
1279
+ })
1280
+ .finally(() => {
1281
1281
  setHasUserActivatedSpeak(true);
1282
1282
  });
1283
1283
  }
@@ -1294,14 +1294,26 @@ const MemoriWidget = ({ memori, memoriConfigs, memoriLang, integration, showInst
1294
1294
  }
1295
1295
  }
1296
1296
  else {
1297
- translateDialogState(currentState, userLang).finally(() => {
1297
+ translateDialogState(currentState, userLang)
1298
+ .then(ts => {
1299
+ if (ts.emission) {
1300
+ speak(ts.emission);
1301
+ }
1302
+ })
1303
+ .finally(() => {
1298
1304
  setHasUserActivatedSpeak(true);
1299
1305
  });
1300
1306
  }
1301
1307
  }
1302
1308
  else {
1303
1309
  setHistory([]);
1304
- translateDialogState(dialogState, userLang).finally(() => {
1310
+ translateDialogState(dialogState, userLang)
1311
+ .then(ts => {
1312
+ if (ts.emission) {
1313
+ speak(ts.emission);
1314
+ }
1315
+ })
1316
+ .finally(() => {
1305
1317
  setHasUserActivatedSpeak(true);
1306
1318
  });
1307
1319
  }
@@ -1337,7 +1349,19 @@ const MemoriWidget = ({ memori, memoriConfigs, memoriLang, integration, showInst
1337
1349
  observer.disconnect();
1338
1350
  };
1339
1351
  }, []);
1340
- const header = (React.createElement(Header, { memori: memori, history: history, showShare: showShare, position: position, setShowPositionDrawer: setShowPositionDrawer, setShowSettingsDrawer: setShowSettingsDrawer, speakerMuted: muteSpeaker, setSpeakerMuted: setMuteSpeaker, showSettings: showSettings, hasUserActivatedSpeak: hasUserActivatedSpeak }));
1352
+ const header = (React.createElement(Header, { memori: memori, history: history, showShare: showShare, position: position, setShowPositionDrawer: setShowPositionDrawer, setShowSettingsDrawer: setShowSettingsDrawer, speakerMuted: muteSpeaker, setSpeakerMuted: mute => {
1353
+ setMuteSpeaker(mute);
1354
+ if (mute) {
1355
+ stopAudio();
1356
+ }
1357
+ else {
1358
+ audioContext = new AudioContext();
1359
+ let buffer = audioContext.createBuffer(1, 10000, 22050);
1360
+ let source = audioContext.createBufferSource();
1361
+ source.buffer = buffer;
1362
+ source.connect(audioContext.destination);
1363
+ }
1364
+ }, showSettings: showSettings, hasUserActivatedSpeak: hasUserActivatedSpeak }));
1341
1365
  const avatar = (React.createElement(Avatar, { memori: memori, integration: integration, integrationConfig: integrationConfig, tenant: tenant, instruct: instruct, avatar3dVisible: avatar3dVisible, setAvatar3dVisible: setAvatar3dVisible, hasUserActivatedSpeak: hasUserActivatedSpeak, isPlayingAudio: isPlayingAudio, baseUrl: baseUrl }));
1342
1366
  const startPanel = (React.createElement(StartPanel, { memori: memori, tenant: tenant, gamificationLevel: gamificationLevel, language: language, userLang: userLang, setUserLang: setUserLang, baseUrl: baseUrl, position: position, openPositionDrawer: () => setShowPositionDrawer(true), integrationConfig: integrationConfig, instruct: instruct, sessionId: sessionId, clickedStart: clickedStart, onClickStart: onClickStart, initializeTTS: initializeTTS }));
1343
1367
  const chat = sessionId ? (React.createElement(Chat, { memori: memori, sessionID: sessionId, tenant: tenant, translateTo: isMultilanguageEnabled &&
@@ -1376,9 +1400,9 @@ const MemoriWidget = ({ memori, memoriConfigs, memoriLang, integration, showInst
1376
1400
  if (values['tokens'])
1377
1401
  setMemoriTokens(values['tokens']);
1378
1402
  reopenSession(!sessionId, values['password'], values['tokens'], instruct ? memori.giverTag : undefined, instruct ? memori.giverPIN : undefined, initialContextVars, initialQuestion)
1379
- .then(() => {
1403
+ .then(state => {
1380
1404
  setAuthModalState(null);
1381
- setHasUserActivatedSpeak(true);
1405
+ onClickStart(state || undefined);
1382
1406
  })
1383
1407
  .catch(() => {
1384
1408
  setAuthModalState(null);
@@ -1412,6 +1436,7 @@ const MemoriWidget = ({ memori, memoriConfigs, memoriLang, integration, showInst
1412
1436
  media: currentState.media,
1413
1437
  fromUser: false,
1414
1438
  });
1439
+ speak(currentState.emission);
1415
1440
  }
1416
1441
  }
1417
1442
  else {
@@ -1450,6 +1475,7 @@ const MemoriWidget = ({ memori, memoriConfigs, memoriLang, integration, showInst
1450
1475
  media: currentState.media,
1451
1476
  fromUser: false,
1452
1477
  });
1478
+ speak(currentState.emission);
1453
1479
  }
1454
1480
  }
1455
1481
  else {