mirror of
https://github.com/Equicord/Equicord.git
synced 2025-06-14 09:03:03 -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
|
// 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
|
// 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;
|
if (text.trim().length === 0) return;
|
||||||
|
|
||||||
// Create a unique cache key using the voice setting and the text.
|
// 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)
|
// 1. Check the in-memory cache (fast check)
|
||||||
if (ttsCache.has(cacheKey)) {
|
if (ttsCache.has(cacheKey)) {
|
||||||
const cachedUrl = ttsCache.get(cacheKey)!;
|
const cachedUrl = ttsCache.get(cacheKey)!;
|
||||||
const audio = new Audio(cachedUrl);
|
const audio = new Audio(cachedUrl);
|
||||||
audio.volume = settings.store.volume;
|
audio.volume = volume;
|
||||||
audio.playbackRate = settings.store.rate;
|
audio.playbackRate = rate;
|
||||||
audio.play();
|
audio.play();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -111,8 +111,8 @@ async function speak(text: string) {
|
||||||
// Save it in the in-memory cache for next time.
|
// Save it in the in-memory cache for next time.
|
||||||
ttsCache.set(cacheKey, url);
|
ttsCache.set(cacheKey, url);
|
||||||
const audio = new Audio(url);
|
const audio = new Audio(url);
|
||||||
audio.volume = settings.store.volume;
|
audio.volume = volume;
|
||||||
audio.playbackRate = settings.store.rate;
|
audio.playbackRate = rate;
|
||||||
audio.play();
|
audio.play();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -134,7 +134,7 @@ async function speak(text: string) {
|
||||||
referrerPolicy: "no-referrer",
|
referrerPolicy: "no-referrer",
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
text: text,
|
text: text,
|
||||||
voice: settings.store.customVoice,
|
voice: customVoice,
|
||||||
}),
|
}),
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
@ -161,8 +161,8 @@ async function speak(text: string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
const audio = new Audio(url);
|
const audio = new Audio(url);
|
||||||
audio.volume = settings.store.volume;
|
audio.volume = volume;
|
||||||
audio.playbackRate = settings.store.rate;
|
audio.playbackRate = rate;
|
||||||
audio.play();
|
audio.play();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -220,23 +220,20 @@ function getTypeAndChannelId(
|
||||||
}
|
}
|
||||||
|
|
||||||
function playSample(tempSettings: any, type: string) {
|
function playSample(tempSettings: any, type: string) {
|
||||||
const settingsobj = Object.assign(
|
const s = Object.assign({}, settings.plain, tempSettings);
|
||||||
{},
|
|
||||||
settings.store,
|
|
||||||
tempSettings
|
|
||||||
);
|
|
||||||
const currentUser = UserStore.getCurrentUser();
|
const currentUser = UserStore.getCurrentUser();
|
||||||
const myGuildId = SelectedGuildStore.getGuildId();
|
const myGuildId = SelectedGuildStore.getGuildId();
|
||||||
|
|
||||||
speak(
|
speak(
|
||||||
formatText(
|
formatText(
|
||||||
settingsobj[type + "Message"],
|
s[type + "Message"],
|
||||||
currentUser.username,
|
currentUser.username,
|
||||||
"general",
|
"general",
|
||||||
(currentUser as any).globalName ?? currentUser.username,
|
(currentUser as any).globalName ?? currentUser.username,
|
||||||
GuildMemberStore.getNick(myGuildId, currentUser.id) ??
|
GuildMemberStore.getNick(myGuildId, currentUser.id) ??
|
||||||
currentUser.username
|
currentUser.username
|
||||||
)
|
),
|
||||||
|
s
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -382,7 +379,7 @@ export default definePlugin({
|
||||||
settingsAboutComponent({ tempSettings: s }) {
|
settingsAboutComponent({ tempSettings: s }) {
|
||||||
const types = useMemo(
|
const types = useMemo(
|
||||||
() =>
|
() =>
|
||||||
Object.keys(settings.store!)
|
Object.keys(settings.def)
|
||||||
.filter(k => k.endsWith("Message"))
|
.filter(k => k.endsWith("Message"))
|
||||||
.map(k => k.slice(0, -7)),
|
.map(k => k.slice(0, -7)),
|
||||||
[]
|
[]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue