add play all button
This commit is contained in:
1 parent
e0a6ddcafc
commit
e5023e7709
4 files changed
+74
-2
No files matched your search
+20
@@ -0,0 +1,20 @@
|
||||
import { state } from "./store/play";
|
||||
|
||||
|
||||
function play() {
|
||||
const synth = window.speechSynthesis;
|
||||
|
||||
const a = document.querySelector("article")
|
||||
if (!a || !a.textContent) {
|
||||
return
|
||||
}
|
||||
|
||||
const u = new SpeechSynthesisUtterance(a.textContent)
|
||||
const voice = synth.getVoices().find((v) => v.name === state.voice);
|
||||
if (voice) {
|
||||
u.voice = voice
|
||||
}
|
||||
synth.speak(u)
|
||||
}
|
||||
|
||||
export default play
|
||||
Reference in new issue
Block a user