create first post
This commit is contained in:
1 parent
089c1345c8
commit
cc517b7333
11 files changed
+112
-21
No files matched your search
+25
@@ -0,0 +1,25 @@
|
||||
import "./disqus";
|
||||
|
||||
window.addEventListener("keydown", (ev) => {
|
||||
if (ev.key === "s") {
|
||||
const s = window.getSelection().toString();
|
||||
if (s) {
|
||||
speak(s);
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
function speak(s: string) {
|
||||
const allVoices = speechSynthesis.getVoices();
|
||||
let vs = allVoices.filter((v) => /zh[-_]cn/i.test(v.lang));
|
||||
if (vs.length === 0) {
|
||||
vs = allVoices.filter((v) => /zh/i.test(v.lang));
|
||||
}
|
||||
|
||||
if (vs.length > 0) {
|
||||
const u = new SpeechSynthesisUtterance(s);
|
||||
u.lang = vs[0].lang;
|
||||
u.rate = 0.8;
|
||||
speechSynthesis.speak(u);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user