Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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