diff --git a/package.json b/package.json index 7d21523a..2a0dc519 100644 --- a/package.json +++ b/package.json @@ -68,8 +68,8 @@ "@ffmpeg/ffmpeg": "^0.10.0", "async-mutex": "^0.3.2", "browser-id3-writer": "^4.4.0", - "custom-electron-prompt": "^1.3.1", "chokidar": "^3.5.2", + "custom-electron-prompt": "^1.3.1", "custom-electron-titlebar": "^3.2.7", "discord-rpc": "^3.2.0", "electron-better-web-request": "^1.0.1", @@ -80,6 +80,7 @@ "electron-unhandled": "^3.0.2", "electron-updater": "^4.6.1", "filenamify": "^4.3.0", + "hark": "^1.2.3", "md5": "^2.3.0", "mpris-service": "^2.1.2", "node-fetch": "^2.6.6", diff --git a/plugins/skip-silences/front.js b/plugins/skip-silences/front.js new file mode 100644 index 00000000..792851c2 --- /dev/null +++ b/plugins/skip-silences/front.js @@ -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(); + }); + }); +}; diff --git a/yarn.lock b/yarn.lock index 1ca05e7f..19f566db 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4575,6 +4575,13 @@ hard-rejection@^2.1.0: resolved "https://registry.yarnpkg.com/hard-rejection/-/hard-rejection-2.1.0.tgz#1c6eda5c1685c63942766d79bb40ae773cecd883" integrity sha512-VIZB+ibDhx7ObhAe7OVtoEbuP4h/MuOTHJ+J8h/eBXotJYl0fBgR72xDFCKgIh22OJZIOVNxBMWuhAr10r8HdA== +hark@^1.2.3: + version "1.2.3" + resolved "https://registry.yarnpkg.com/hark/-/hark-1.2.3.tgz#959981400f561be5580ecd4321a9f55b16bacbd0" + integrity sha512-u68vz9SCa38ESiFJSDjqK8XbXqWzyot7Cj6Y2b6jk2NJ+II3MY2dIrLMg/kjtIAun4Y1DHF/20hfx4rq1G5GMg== + dependencies: + wildemitter "^1.2.0" + has-ansi@^2.0.0: version "2.0.0" resolved "https://registry.yarnpkg.com/has-ansi/-/has-ansi-2.0.0.tgz#34f5049ce1ecdf2b0649af3ef24e45ed35416d91" @@ -8614,6 +8621,11 @@ widest-line@^3.1.0: dependencies: string-width "^4.0.0" +wildemitter@^1.2.0: + version "1.2.1" + resolved "https://registry.yarnpkg.com/wildemitter/-/wildemitter-1.2.1.tgz#9da3b5ca498e4378628d1783145493c70a10b774" + integrity sha512-UMmSUoIQSir+XbBpTxOTS53uJ8s/lVhADCkEbhfRjUGFDPme/XGOb0sBWLx5sTz7Wx/2+TlAw1eK9O5lw5PiEw== + word-wrap@^1.2.3, word-wrap@~1.2.3: version "1.2.3" resolved "https://registry.yarnpkg.com/word-wrap/-/word-wrap-1.2.3.tgz#610636f6b1f703891bd34771ccb17fb93b47079c"