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

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,59 @@ 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 (preview)
791
742
  return;
792
743
  if (audioDestination)
793
744
  audioDestination.pause();
794
- if (speechSynthesizer) {
795
- speechSynthesizer.close();
796
- speechSynthesizer = null;
745
+ let isSafari = window.navigator.userAgent.includes('Safari') &&
746
+ !window.navigator.userAgent.includes('Chrome');
747
+ let isIOS = /iPad|iPhone|iPod/.test(navigator.userAgent);
748
+ if (isIOS && isSafari) {
749
+ audioContext.suspend();
797
750
  }
798
- if (muteSpeaker && fireListeningEvent) {
799
- setTimeout(() => {
800
- document.dispatchEvent(new Event('endSpeakStartListen'));
801
- }, 3000);
802
- return;
751
+ else if (audioContext.state === 'suspended') {
752
+ stopAudio();
753
+ audioContext = new AudioContext();
754
+ let buffer = audioContext.createBuffer(1, 10000, 22050);
755
+ let source = audioContext.createBufferSource();
756
+ source.buffer = buffer;
757
+ source.connect(audioContext.destination);
803
758
  }
804
- else if (muteSpeaker) {
759
+ if (!speechSynthesizer) {
760
+ audioDestination = new speechSdk.SpeakerAudioDestination();
761
+ let audioConfig = speechSdk.AudioConfig.fromSpeakerOutput(audioDestination);
762
+ speechSynthesizer = new speechSdk.SpeechSynthesizer(speechConfig, audioConfig);
763
+ }
764
+ if (muteSpeaker) {
765
+ if (continuousSpeech) {
766
+ setListeningTimeout();
767
+ }
805
768
  return;
806
769
  }
807
- audioDestination = new speechSdk.SpeakerAudioDestination();
808
- let audioConfig = speechSdk.AudioConfig.fromSpeakerOutput(audioDestination);
809
- speechSynthesizer = new speechSdk.SpeechSynthesizer(speechConfig, audioConfig);
810
770
  audioDestination.onAudioEnd = () => {
811
771
  setIsPlayingAudio(false);
812
- if (fireListeningEvent) {
772
+ if (continuousSpeech) {
813
773
  document.dispatchEvent(new Event('endSpeakStartListen'));
814
774
  }
815
775
  };
816
776
  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);
822
777
  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
778
  if (result) {
779
+ console.log('result', result);
824
780
  try {
781
+ audioContext.decodeAudioData(result.audioData, function (buffer) {
782
+ const source = audioContext.createBufferSource();
783
+ source.buffer = buffer;
784
+ source.connect(audioContext.destination);
785
+ if (history.length < 1 || (isSafari && isIOS)) {
786
+ source.start(0);
787
+ }
788
+ });
789
+ audioContext.resume();
825
790
  if (speechSynthesizer) {
826
791
  speechSynthesizer.close();
827
792
  speechSynthesizer = null;
@@ -831,10 +796,14 @@ const MemoriWidget = ({ memori, memoriConfigs, memoriLang, integration, showInst
831
796
  console.error('speak error: ', e);
832
797
  window.speechSynthesis.speak(new SpeechSynthesisUtterance(text));
833
798
  setIsPlayingAudio(false);
799
+ if (speechSynthesizer) {
800
+ speechSynthesizer.close();
801
+ speechSynthesizer = null;
802
+ }
834
803
  }
835
804
  }
836
805
  else {
837
- window.speechSynthesis.speak(new SpeechSynthesisUtterance(text));
806
+ audioContext.resume();
838
807
  setIsPlayingAudio(false);
839
808
  }
840
809
  }, error => {
@@ -843,12 +812,20 @@ const MemoriWidget = ({ memori, memoriConfigs, memoriLang, integration, showInst
843
812
  setIsPlayingAudio(false);
844
813
  });
845
814
  setIsPlayingAudio(false);
815
+ setMemoriTyping(false);
846
816
  };
847
817
  const stopAudio = () => {
848
818
  if (speechSynthesizer) {
849
819
  speechSynthesizer.close();
850
820
  speechSynthesizer = null;
851
821
  }
822
+ if (audioContext) {
823
+ audioContext.close();
824
+ }
825
+ if (audioDestination) {
826
+ audioDestination.pause();
827
+ audioDestination.close();
828
+ }
852
829
  };
853
830
  useEffect(() => {
854
831
  let textarea = document.querySelector('#chat-fieldset textarea');
@@ -887,11 +864,6 @@ const MemoriWidget = ({ memori, memoriConfigs, memoriLang, integration, showInst
887
864
  useEffect(() => {
888
865
  resetListeningTimeout();
889
866
  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
867
  }, [transcript]);
896
868
  const startListening = () => {
897
869
  console.log('start listening');
@@ -917,9 +889,14 @@ const MemoriWidget = ({ memori, memoriConfigs, memoriLang, integration, showInst
917
889
  recognizer = new speechSdk.SpeechRecognizer(speechConfig, audioConfig);
918
890
  setListening(true);
919
891
  recognizer.recognized = (_s, e) => {
920
- var _a;
921
892
  if (e.result.reason === speechSdk.ResultReason.RecognizedSpeech) {
922
- setTranscript((_a = e.result.text) !== null && _a !== void 0 ? _a : '');
893
+ let transcript = e.result.text;
894
+ setTranscript(transcript || '');
895
+ if ((transcript === null || transcript === void 0 ? void 0 : transcript.length) > 0) {
896
+ const transcriptMessage = stripDuplicates(transcript);
897
+ if (transcriptMessage.length > 0)
898
+ setUserMessage(transcriptMessage);
899
+ }
923
900
  }
924
901
  else if (e.result.reason === speechSdk.ResultReason.NoMatch) {
925
902
  console.debug('NOMATCH: Speech could not be recognized.');
@@ -973,15 +950,6 @@ const MemoriWidget = ({ memori, memoriConfigs, memoriLang, integration, showInst
973
950
  if ((currentDialogState === null || currentDialogState === void 0 ? void 0 : currentDialogState.state) === 'Z0')
974
951
  clearListening();
975
952
  }, [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
953
  const [requestedListening, setRequestedListening] = useState(false);
986
954
  const onEndSpeakStartListen = useCallback((_e) => {
987
955
  if (isPlayingAudio && speechSynthesizer) {
@@ -1185,7 +1153,15 @@ const MemoriWidget = ({ memori, memoriConfigs, memoriLang, integration, showInst
1185
1153
  const sessionID = (session === null || session === void 0 ? void 0 : session.sessionID) || sessionId;
1186
1154
  const dialogState = (session === null || session === void 0 ? void 0 : session.dialogState) || currentDialogState;
1187
1155
  setClickedStart(true);
1188
- console.log('onClickStart');
1156
+ let memoriAudioElement = document.getElementById('memori-audio');
1157
+ let isSafari = window.navigator.userAgent.includes('Safari') &&
1158
+ !window.navigator.userAgent.includes('Chrome');
1159
+ if (memoriAudioElement && isSafari) {
1160
+ memoriAudioElement.muted = false;
1161
+ memoriAudioElement.play().catch((e) => {
1162
+ console.error('error playing intro audio', e);
1163
+ });
1164
+ }
1189
1165
  if ((!sessionID &&
1190
1166
  memori.privacyType !== 'PUBLIC' &&
1191
1167
  !memori.secretToken &&
@@ -1207,7 +1183,7 @@ const MemoriWidget = ({ memori, memoriConfigs, memoriLang, integration, showInst
1207
1183
  initialContextVars,
1208
1184
  initialQuestion,
1209
1185
  });
1210
- onClickStart(session || undefined);
1186
+ await onClickStart(session || undefined);
1211
1187
  return;
1212
1188
  }
1213
1189
  else if (initialSessionID) {
@@ -1217,7 +1193,7 @@ const MemoriWidget = ({ memori, memoriConfigs, memoriLang, integration, showInst
1217
1193
  setGotErrorInOpening(true);
1218
1194
  setSessionId(undefined);
1219
1195
  setClickedStart(false);
1220
- onClickStart();
1196
+ await onClickStart();
1221
1197
  return;
1222
1198
  }
1223
1199
  setHistory([]);
@@ -1229,7 +1205,13 @@ const MemoriWidget = ({ memori, memoriConfigs, memoriLang, integration, showInst
1229
1205
  await changeTag(memori.engineMemoriID, sessionID, '-');
1230
1206
  const session = await changeTag(memori.engineMemoriID, sessionID, memori.giverTag, memori.giverPIN);
1231
1207
  if (session && session.resultCode === 0) {
1232
- translateDialogState(session.currentState, userLang).finally(() => {
1208
+ translateDialogState(session.currentState, userLang)
1209
+ .then(ts => {
1210
+ if (ts.emission) {
1211
+ speak(ts.emission);
1212
+ }
1213
+ })
1214
+ .finally(() => {
1233
1215
  setHasUserActivatedSpeak(true);
1234
1216
  });
1235
1217
  }
@@ -1253,7 +1235,13 @@ const MemoriWidget = ({ memori, memoriConfigs, memoriLang, integration, showInst
1253
1235
  await changeTag(memori.engineMemoriID, sessionID, '-');
1254
1236
  const session = await changeTag(memori.engineMemoriID, sessionID, personification.tag, personification.pin);
1255
1237
  if (session && session.resultCode === 0) {
1256
- translateDialogState(session.currentState, userLang).finally(() => {
1238
+ translateDialogState(session.currentState, userLang)
1239
+ .then(ts => {
1240
+ if (ts.emission) {
1241
+ speak(ts.emission);
1242
+ }
1243
+ })
1244
+ .finally(() => {
1257
1245
  setHasUserActivatedSpeak(true);
1258
1246
  });
1259
1247
  }
@@ -1277,7 +1265,13 @@ const MemoriWidget = ({ memori, memoriConfigs, memoriLang, integration, showInst
1277
1265
  await changeTag(memori.engineMemoriID, sessionID, '-');
1278
1266
  const session = await changeTag(memori.engineMemoriID, sessionID, anonTag);
1279
1267
  if (session && session.resultCode === 0) {
1280
- translateDialogState(session.currentState, userLang).finally(() => {
1268
+ translateDialogState(session.currentState, userLang)
1269
+ .then(ts => {
1270
+ if (ts.emission) {
1271
+ speak(ts.emission);
1272
+ }
1273
+ })
1274
+ .finally(() => {
1281
1275
  setHasUserActivatedSpeak(true);
1282
1276
  });
1283
1277
  }
@@ -1294,14 +1288,26 @@ const MemoriWidget = ({ memori, memoriConfigs, memoriLang, integration, showInst
1294
1288
  }
1295
1289
  }
1296
1290
  else {
1297
- translateDialogState(currentState, userLang).finally(() => {
1291
+ translateDialogState(currentState, userLang)
1292
+ .then(ts => {
1293
+ if (ts.emission) {
1294
+ speak(ts.emission);
1295
+ }
1296
+ })
1297
+ .finally(() => {
1298
1298
  setHasUserActivatedSpeak(true);
1299
1299
  });
1300
1300
  }
1301
1301
  }
1302
1302
  else {
1303
1303
  setHistory([]);
1304
- translateDialogState(dialogState, userLang).finally(() => {
1304
+ translateDialogState(dialogState, userLang)
1305
+ .then(ts => {
1306
+ if (ts.emission) {
1307
+ speak(ts.emission);
1308
+ }
1309
+ })
1310
+ .finally(() => {
1305
1311
  setHasUserActivatedSpeak(true);
1306
1312
  });
1307
1313
  }
@@ -1337,7 +1343,19 @@ const MemoriWidget = ({ memori, memoriConfigs, memoriLang, integration, showInst
1337
1343
  observer.disconnect();
1338
1344
  };
1339
1345
  }, []);
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 }));
1346
+ const header = (React.createElement(Header, { memori: memori, history: history, showShare: showShare, position: position, setShowPositionDrawer: setShowPositionDrawer, setShowSettingsDrawer: setShowSettingsDrawer, speakerMuted: muteSpeaker, setSpeakerMuted: mute => {
1347
+ setMuteSpeaker(mute);
1348
+ if (mute) {
1349
+ stopAudio();
1350
+ }
1351
+ else {
1352
+ audioContext = new AudioContext();
1353
+ let buffer = audioContext.createBuffer(1, 10000, 22050);
1354
+ let source = audioContext.createBufferSource();
1355
+ source.buffer = buffer;
1356
+ source.connect(audioContext.destination);
1357
+ }
1358
+ }, showSettings: showSettings, hasUserActivatedSpeak: hasUserActivatedSpeak }));
1341
1359
  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
1360
  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
1361
  const chat = sessionId ? (React.createElement(Chat, { memori: memori, sessionID: sessionId, tenant: tenant, translateTo: isMultilanguageEnabled &&
@@ -1376,9 +1394,9 @@ const MemoriWidget = ({ memori, memoriConfigs, memoriLang, integration, showInst
1376
1394
  if (values['tokens'])
1377
1395
  setMemoriTokens(values['tokens']);
1378
1396
  reopenSession(!sessionId, values['password'], values['tokens'], instruct ? memori.giverTag : undefined, instruct ? memori.giverPIN : undefined, initialContextVars, initialQuestion)
1379
- .then(() => {
1397
+ .then(state => {
1380
1398
  setAuthModalState(null);
1381
- setHasUserActivatedSpeak(true);
1399
+ onClickStart(state || undefined);
1382
1400
  })
1383
1401
  .catch(() => {
1384
1402
  setAuthModalState(null);
@@ -1412,6 +1430,7 @@ const MemoriWidget = ({ memori, memoriConfigs, memoriLang, integration, showInst
1412
1430
  media: currentState.media,
1413
1431
  fromUser: false,
1414
1432
  });
1433
+ speak(currentState.emission);
1415
1434
  }
1416
1435
  }
1417
1436
  else {
@@ -1450,6 +1469,7 @@ const MemoriWidget = ({ memori, memoriConfigs, memoriLang, integration, showInst
1450
1469
  media: currentState.media,
1451
1470
  fromUser: false,
1452
1471
  });
1472
+ speak(currentState.emission);
1453
1473
  }
1454
1474
  }
1455
1475
  else {