Created
April 14, 2020 13:36
-
-
Save aereal/1957305b05198bca34b7259158f4f3cb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const speak = (body) => { | |
const synth = window.speechSynthesis; | |
const allVoices = synth.getVoices(); | |
const jaVoices = allVoices.filter(v=> v.lang === 'ja-JP'); | |
const voice = jaVoices[0]; | |
if (!voice) { | |
throw new Error('voice not found'); | |
} | |
const utter = new SpeechSynthesisUtterance(body); | |
utter.voice=voice; | |
utter.lang = 'ja-JP'; | |
utter.pitch = 1 | |
utter.volume = 1 | |
utter.rate = 1 | |
synth.speak(utter) | |
} | |
const listen = () => { | |
new MutationObserver((mutations, observer) => { | |
for (const m of mutations) { | |
if (m.type!=='childList') { | |
continue | |
} | |
const body = m.target.querySelector('div[lang]>span') | |
if (!body) { | |
continue | |
} | |
speak(body.textContent) | |
} | |
}).observe(document.querySelector('[aria-label="タイムライン: ホームタイムライン"'), { | |
childList: true, | |
subtree: true, | |
}) | |
} | |
listen() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment