From 5d105bbece0bada4f913bf7a2defa5c43704466b Mon Sep 17 00:00:00 2001 From: Jicheng Lu <103353@smsassist.com> Date: Mon, 30 Sep 2024 16:02:16 -0500 Subject: [PATCH] disable speech for firefox --- src/lib/scss/custom/pages/_chat.scss | 4 ++ src/lib/services/web-speech.js | 51 ++++++++++--------- .../[conversationId]/chat-box.svelte | 22 +++++--- .../rich-content/rc-plain-options.svelte | 2 +- src/routes/page/conversation/+page.svelte | 1 - 5 files changed, 47 insertions(+), 33 deletions(-) diff --git a/src/lib/scss/custom/pages/_chat.scss b/src/lib/scss/custom/pages/_chat.scss index 6686a15b..ca3d5382 100644 --- a/src/lib/scss/custom/pages/_chat.scss +++ b/src/lib/scss/custom/pages/_chat.scss @@ -709,6 +709,10 @@ .link-option:hover { text-decoration: underline; } + + .chat-uploader { + font-size: 18px; + } } .complex-option-container { diff --git a/src/lib/services/web-speech.js b/src/lib/services/web-speech.js index 2f8a4b3d..4a4057ac 100644 --- a/src/lib/services/web-speech.js +++ b/src/lib/services/web-speech.js @@ -1,15 +1,17 @@ -// https://developer.mozilla.org/en-US/docs/Web/API/Web_Speech_API/Using_the_Web_Speech_API +// // https://developer.mozilla.org/en-US/docs/Web/API/Web_Speech_API/Using_the_Web_Speech_API const SpeechRecognition = window.SpeechRecognition || window.webkitSpeechRecognition; const SpeechRecognitionEvent = window.SpeechRecognitionEvent || window.webkitSpeechRecognitionEvent; -const recognition = new SpeechRecognition(); -recognition.continuous = false; -recognition.lang = "en-US"; -recognition.interimResults = false; -recognition.maxAlternatives = 1; +const recognition = !navigator.userAgent.includes('Firefox') ? new SpeechRecognition() : null; +if (recognition) { + recognition.continuous = false; + recognition.lang = "en-US"; + recognition.interimResults = false; + recognition.maxAlternatives = 1; +} -const synth = window.speechSynthesis; +const synth = window.speechSynthesis; const utterThis = new SpeechSynthesisUtterance(); utterThis.pitch = 1; @@ -25,8 +27,10 @@ export const webSpeech = { onSpeechToTextDetected: () => {}, start() { - recognition.start(); - console.log("Ready to receive a voice command."); + if (recognition) { + recognition.start(); + console.log("Ready to receive a voice command."); + } }, /** @param {string} transcript */ @@ -54,17 +58,18 @@ function setVoiceSynthesis() { } } -recognition.onresult = (/** @type {any} */ event) => { - const text = event.results[0][0].transcript; - console.log(`Confidence: ${text} ${event.results[0][0].confidence}`); - webSpeech.onSpeechToTextDetected(text); -}; - -recognition.onnomatch = (/** @type {any} */ event) => { - console.log("I didn't recognize that color."); -}; - -recognition.onerror = (/** @type {any} */ event) => { - console.log(`Error occurred in recognition: ${event.error}`); -}; - +if (recognition) { + recognition.onresult = (/** @type {any} */ event) => { + const text = event.results[0][0].transcript; + console.log(`Confidence: ${text} ${event.results[0][0].confidence}`); + webSpeech.onSpeechToTextDetected(text); + }; + + recognition.onnomatch = (/** @type {any} */ event) => { + console.log("I didn't recognize that color."); + }; + + recognition.onerror = (/** @type {any} */ event) => { + console.log(`Error occurred in recognition: ${event.error}`); + }; +} \ No newline at end of file diff --git a/src/routes/chat/[agentId]/[conversationId]/chat-box.svelte b/src/routes/chat/[agentId]/[conversationId]/chat-box.svelte index 260228a0..04aa3a36 100644 --- a/src/routes/chat/[agentId]/[conversationId]/chat-box.svelte +++ b/src/routes/chat/[agentId]/[conversationId]/chat-box.svelte @@ -150,6 +150,7 @@ let autoScrollLog = false; let disableAction = false; let loadChatUtils = false; + let disableSpeech = false; $: { @@ -167,6 +168,7 @@ }); onMount(async () => { + disableSpeech = navigator.userAgent.includes('Firefox'); autoScrollLog = true; dialogs = await GetDialogs(params.conversationId); conversationUser = await getConversationUser(params.conversationId); @@ -532,6 +534,8 @@ } async function startListen() { + if (disableSpeech) return; + microphoneIcon = "microphone"; webSpeech.onSpeechToTextDetected = (transcript) => { if (!!!_.trim(transcript) || isSendingMsg) return; @@ -1269,14 +1273,16 @@
- + {#if !disableSpeech} + + {/if}
diff --git a/src/routes/chat/[agentId]/[conversationId]/rich-content/rc-plain-options.svelte b/src/routes/chat/[agentId]/[conversationId]/rich-content/rc-plain-options.svelte index 81484262..22c1604c 100644 --- a/src/routes/chat/[agentId]/[conversationId]/rich-content/rc-plain-options.svelte +++ b/src/routes/chat/[agentId]/[conversationId]/rich-content/rc-plain-options.svelte @@ -175,7 +175,7 @@ {/if} {#if fileOption} - + diff --git a/src/routes/page/conversation/+page.svelte b/src/routes/page/conversation/+page.svelte index 122d8020..1fb4139a 100644 --- a/src/routes/page/conversation/+page.svelte +++ b/src/routes/page/conversation/+page.svelte @@ -26,7 +26,6 @@ import { utcToLocal } from '$lib/helpers/datetime'; import Swal from 'sweetalert2'; import lodash from "lodash"; - import MultiSelect from '$lib/common/MultiSelect.svelte'; let isLoading = false; let isComplete = false;