Skip to content

Instantly share code, notes, and snippets.

@aereal
Created April 14, 2020 13:36
Show Gist options
  • Save aereal/1957305b05198bca34b7259158f4f3cb to your computer and use it in GitHub Desktop.
Save aereal/1957305b05198bca34b7259158f4f3cb to your computer and use it in GitHub Desktop.
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