Skip to content

Commit

Permalink
Merge branch 'main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
Oceania2018 authored Sep 30, 2024
2 parents e4b7787 + f891700 commit 63688c4
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 33 deletions.
4 changes: 4 additions & 0 deletions src/lib/scss/custom/pages/_chat.scss
Original file line number Diff line number Diff line change
Expand Up @@ -709,6 +709,10 @@
.link-option:hover {
text-decoration: underline;
}

.chat-uploader {
font-size: 18px;
}
}

.complex-option-container {
Expand Down
51 changes: 28 additions & 23 deletions src/lib/services/web-speech.js
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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 */
Expand Down Expand Up @@ -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}`);
};
}
24 changes: 16 additions & 8 deletions src/routes/chat/[agentId]/[conversationId]/chat-box.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@
let autoScrollLog = false;
let disableAction = false;
let loadChatUtils = false;
let disableSpeech = false;
$: {
Expand All @@ -171,6 +172,7 @@
});
onMount(async () => {
disableSpeech = navigator.userAgent.includes('Firefox');
autoScrollLog = true;
dialogs = await GetDialogs(params.conversationId);
conversationUser = await getConversationUser(params.conversationId);
Expand Down Expand Up @@ -536,6 +538,8 @@
}
async function startListen() {
if (disableSpeech) return;
microphoneIcon = "microphone";
webSpeech.onSpeechToTextDetected = (transcript) => {
if (!!!_.trim(transcript) || isSendingMsg) return;
Expand Down Expand Up @@ -1273,14 +1277,18 @@
<div class={`chat-input-section css-animation ${!loadEditor ? 'chat-input-hide' : 'fade-in-from-none'}`}>
<div class="row">
<div class="col-auto">
<button
type="submit"
class={`btn btn-rounded waves-effect waves-light ${mode === TRAINING_MODE ? 'btn-danger' : 'btn-primary'}`}
disabled={isSendingMsg || isThinking || disableAction || PUBLIC_LIVECHAT_VOICE_ENABLED}
on:click={() => startListen()}
>
<i class="mdi mdi-{microphoneIcon} md-36" />
</button>
{#if !disableSpeech}
<button
type="submit"
class={`btn btn-rounded waves-effect waves-light ${mode === TRAINING_MODE ? 'btn-danger' : 'btn-primary'}`}
disabled={isSendingMsg || isThinking || disableAction || PUBLIC_LIVECHAT_VOICE_ENABLED}
on:click={() => startListen()}
>
<i class="mdi mdi-{microphoneIcon} md-36" />
</button>
{/if}
</div>
<div class="col">
<div class="position-relative">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@
</button>
{/if}
{#if fileOption}
<ChatFileUploader accept=".png,.jpg,.jpeg">
<ChatFileUploader accept=".png,.jpg,.jpeg" containerClasses={'line-align-center text-primary chat-uploader'}>
<span style="position: relative; top: 3px;" in:fade={{ duration: duration }}>
<i class="bx bx-image-add" />
</span>
Expand Down
1 change: 0 additions & 1 deletion src/routes/page/conversation/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 63688c4

Please sign in to comment.