Add plugin to skip silences

This commit is contained in:
TC
2021-12-14 23:16:41 +01:00
parent 5483f0ee36
commit 11429978c9
3 changed files with 48 additions and 0 deletions

View File

@ -0,0 +1,35 @@
const hark = require("hark/hark.bundle.js");
module.exports = () => {
let isSilent = false;
document.addEventListener("apiLoaded", (apiEvent) => {
const video = document.querySelector("video");
const speechEvents = hark(video, {
threshold: -90, // dB (-100 = absolute silence, 0 = loudest)
interval: 2, // ms
});
const skipSilence = () => {
if (isSilent && !video.paused) {
video.currentTime += 0.2; // in s
}
};
speechEvents.on("speaking", function () {
isSilent = false;
});
speechEvents.on("stopped_speaking", function () {
isSilent = true;
skipSilence();
});
video.addEventListener("play", function () {
skipSilence();
});
video.addEventListener("seeked", function () {
skipSilence();
});
});
};