From 62b01c5f8e62d75934c9389a1138658b4cde167e Mon Sep 17 00:00:00 2001 From: Zohaib Rauf Date: Mon, 9 Sep 2024 21:57:53 -0700 Subject: [PATCH] Cleaned up --- .../chat/MessageInput/CallOverlay.svelte | 54 ++++++++----------- 1 file changed, 23 insertions(+), 31 deletions(-) diff --git a/src/lib/components/chat/MessageInput/CallOverlay.svelte b/src/lib/components/chat/MessageInput/CallOverlay.svelte index 59e0549b9..ddd892413 100644 --- a/src/lib/components/chat/MessageInput/CallOverlay.svelte +++ b/src/lib/components/chat/MessageInput/CallOverlay.svelte @@ -7,12 +7,7 @@ const dispatch = createEventDispatcher(); - import { - blobToFile, - calculateSHA256, - extractSentencesForAudio, - findWordIndices - } from '$lib/utils'; + import { blobToFile } from '$lib/utils'; import { generateEmoji } from '$lib/apis'; import { synthesizeOpenAISpeech, transcribeAudio } from '$lib/apis/audio'; @@ -55,31 +50,6 @@ let videoInputDevices = []; let selectedVideoInputDeviceId = null; - let speechRate = 1; - let showSpeedMenu = false; - - const speedOptions = [2, 1.75, 1.5, 1.25, 1, 0.75, 0.5]; - - const toggleSpeedMenu = () => { - showSpeedMenu = !showSpeedMenu; - }; - - const setSpeedRate = (rate: number) => { - speechRate = rate; - showSpeedMenu = false; - updateAudioSpeed(); - }; - - const updateAudioSpeed = () => { - if (currentUtterance) { - currentUtterance.rate = speechRate; - } - const audioElement = document.getElementById('audioElement') as HTMLAudioElement; - if (audioElement) { - audioElement.playbackRate = speechRate; - } - }; - const getVideoInputDevices = async () => { const devices = await navigator.mediaDevices.enumerateDevices(); videoInputDevices = devices.filter((device) => device.kind === 'videoinput'); @@ -460,6 +430,28 @@ let audioAbortController = new AbortController(); + // Audio speed control + let speechRate = 1; + let showSpeedMenu = false; + + const speedOptions = [2, 1.75, 1.5, 1.25, 1, 0.75, 0.5]; + + const setSpeedRate = (rate: number) => { + speechRate = rate; + showSpeedMenu = false; + updateAudioSpeed(); + }; + + const updateAudioSpeed = () => { + if (currentUtterance) { + currentUtterance.rate = speechRate; + } + const audioElement = document.getElementById('audioElement') as HTMLAudioElement; + if (audioElement) { + audioElement.playbackRate = speechRate; + } + }; + // Audio cache map where key is the content and value is the Audio object. const audioCache = new Map(); const emojiCache = new Map();