mirror of
https://github.com/Equicord/Equicord.git
synced 2025-06-14 00:53:04 -04:00
This commit is contained in:
parent
38b0b39699
commit
2a98a52f1d
1 changed files with 14 additions and 17 deletions
|
@ -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)),
|
||||
[]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue