Fix getVoices()
This commit is contained in:
21
index.js
21
index.js
@@ -131,15 +131,28 @@ const getStorage = async () => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const getVoices = () => {
|
const getVoices = async () => {
|
||||||
try {
|
try {
|
||||||
if (!window.speechSynthesis) return null;
|
if (!window.speechSynthesis) return null;
|
||||||
return window.speechSynthesis.getVoices().map((v) => ({
|
|
||||||
|
const mapVoice = (v) => ({
|
||||||
name: v.name,
|
name: v.name,
|
||||||
lang: v.lang,
|
lang: v.lang,
|
||||||
local: v.localService,
|
local: v.localService,
|
||||||
default: v.default,
|
default: v.default,
|
||||||
}));
|
});
|
||||||
|
|
||||||
|
const voices = window.speechSynthesis.getVoices();
|
||||||
|
if (voices.length > 0) {
|
||||||
|
return voices.map((v) => mapVoice(v));
|
||||||
|
}
|
||||||
|
|
||||||
|
return await new Promise((resolve) => {
|
||||||
|
window.speechSynthesis.onvoiceschanged = () => {
|
||||||
|
const list = window.speechSynthesis.getVoices();
|
||||||
|
resolve(list.map((v) => mapVoice(v)));
|
||||||
|
};
|
||||||
|
});
|
||||||
} catch {
|
} catch {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -267,7 +280,7 @@ export const get = async () => {
|
|||||||
mimes: [...(navigator.mimeTypes ?? [])].map(({ type, suffixes }) => ({ type, suffixes })),
|
mimes: [...(navigator.mimeTypes ?? [])].map(({ type, suffixes }) => ({ type, suffixes })),
|
||||||
|
|
||||||
// Voices
|
// Voices
|
||||||
voices: getVoices(),
|
voices: await getVoices(),
|
||||||
|
|
||||||
// Network
|
// Network
|
||||||
network: getNetwork(),
|
network: getNetwork(),
|
||||||
|
Reference in New Issue
Block a user