Created
December 14, 2020 18:09
-
-
Save freehuntx/d5285bfb3bdd1a0a9e1f43a7105a6758 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
(() => { | |
if (!window.speechSynthesis || !window.SpeechSynthesisUtterance) { | |
return alert('Nicht unterstützt!') | |
} | |
const say = text => { | |
if (!text) return | |
window.speechSynthesis.cancel() | |
const msg = new SpeechSynthesisUtterance(text) | |
msg.lang = 'de' | |
msg.rate = 2.5 | |
window.speechSynthesis.speak(msg) | |
} | |
let lastText = '' | |
setInterval(() => { | |
const segments = document.querySelectorAll('.ytp-caption-window-bottom .ytp-caption-segment') | |
const lastSegment = segments[segments.length-1] | |
if (!lastSegment) return | |
const text = lastSegment.innerText | |
if (text === lastText) return | |
else if (text.length < lastText.length) lastText = '' | |
const newText = text.slice(lastText.length).trim() | |
lastText = text | |
say(newText) | |
}, 10) | |
})() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment