From 2a98a52f1d6f896142a88f859b4ab9e2cbbee7d6 Mon Sep 17 00:00:00 2001 From: thororen1234 <78185467+thororen1234@users.noreply.github.com> Date: Tue, 8 Apr 2025 09:15:47 -0400 Subject: [PATCH] Fix Up VcNarratorCustom --- .../vcNarratorCustom/index.tsx | 31 +++++++++---------- 1 file changed, 14 insertions(+), 17 deletions(-) diff --git a/src/equicordplugins/vcNarratorCustom/index.tsx b/src/equicordplugins/vcNarratorCustom/index.tsx index 3c38abe8..471974ca 100644 --- a/src/equicordplugins/vcNarratorCustom/index.tsx +++ b/src/equicordplugins/vcNarratorCustom/index.tsx @@ -86,18 +86,18 @@ const VoiceStateStore = findByPropsLazy( // Filtering out events is not as simple as just dropping duplicates, as otherwise mute, unmute, mute would // not say the second mute, which would lead you to believe they're unmuted -async function speak(text: string) { +async function speak(text: string, { volume, rate, customVoice } = settings.store) { if (text.trim().length === 0) return; // Create a unique cache key using the voice setting and the text. - const cacheKey = `${settings.store.customVoice}_${text}`; + const cacheKey = `${customVoice}_${text}`; // 1. Check the in-memory cache (fast check) if (ttsCache.has(cacheKey)) { const cachedUrl = ttsCache.get(cacheKey)!; const audio = new Audio(cachedUrl); - audio.volume = settings.store.volume; - audio.playbackRate = settings.store.rate; + audio.volume = volume; + audio.playbackRate = rate; audio.play(); return; } @@ -111,8 +111,8 @@ async function speak(text: string) { // Save it in the in-memory cache for next time. ttsCache.set(cacheKey, url); const audio = new Audio(url); - audio.volume = settings.store.volume; - audio.playbackRate = settings.store.rate; + audio.volume = volume; + audio.playbackRate = rate; audio.play(); return; } @@ -134,7 +134,7 @@ async function speak(text: string) { referrerPolicy: "no-referrer", body: JSON.stringify({ text: text, - voice: settings.store.customVoice, + voice: customVoice, }), } ); @@ -161,8 +161,8 @@ async function speak(text: string) { } const audio = new Audio(url); - audio.volume = settings.store.volume; - audio.playbackRate = settings.store.rate; + audio.volume = volume; + audio.playbackRate = rate; audio.play(); } @@ -220,23 +220,20 @@ function getTypeAndChannelId( } function playSample(tempSettings: any, type: string) { - const settingsobj = Object.assign( - {}, - settings.store, - tempSettings - ); + const s = Object.assign({}, settings.plain, tempSettings); const currentUser = UserStore.getCurrentUser(); const myGuildId = SelectedGuildStore.getGuildId(); speak( formatText( - settingsobj[type + "Message"], + s[type + "Message"], currentUser.username, "general", (currentUser as any).globalName ?? currentUser.username, GuildMemberStore.getNick(myGuildId, currentUser.id) ?? currentUser.username - ) + ), + s ); } @@ -382,7 +379,7 @@ export default definePlugin({ settingsAboutComponent({ tempSettings: s }) { const types = useMemo( () => - Object.keys(settings.store!) + Object.keys(settings.def) .filter(k => k.endsWith("Message")) .map(k => k.slice(0, -7)), []