Skip to content

Commit cf2add8

Browse files
authored
Merge pull request #931 from th-ch/th-ch/skip-silences-beginning
Add option in skip-silences plugin to only skip at the beginning
2 parents 453fe3f + 43c501b commit cf2add8

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

config/defaults.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,9 @@ const defaultConfig = {
9191
"saveSize": false,
9292
"hotkey": "P"
9393
},
94+
"skip-silences": {
95+
onlySkipBeginning: false,
96+
},
9497
},
9598
};
9699

plugins/skip-silences/front.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
const hark = require("hark/hark.bundle.js");
22

3-
module.exports = () => {
3+
module.exports = (options) => {
44
let isSilent = false;
5+
let hasAudioStarted = false;
56

67
document.addEventListener("apiLoaded", () => {
78
const video = document.querySelector("video");
@@ -10,13 +11,18 @@ module.exports = () => {
1011
interval: 2, // ms
1112
});
1213
const skipSilence = () => {
14+
if (options.onlySkipBeginning && hasAudioStarted) {
15+
return;
16+
}
17+
1318
if (isSilent && !video.paused) {
1419
video.currentTime += 0.2; // in s
1520
}
1621
};
1722

1823
speechEvents.on("speaking", function () {
1924
isSilent = false;
25+
hasAudioStarted = true;
2026
});
2127

2228
speechEvents.on("stopped_speaking", function () {
@@ -35,10 +41,12 @@ module.exports = () => {
3541
});
3642

3743
video.addEventListener("play", function () {
44+
hasAudioStarted = false;
3845
skipSilence();
3946
});
4047

4148
video.addEventListener("seeked", function () {
49+
hasAudioStarted = false;
4250
skipSilence();
4351
});
4452
});

0 commit comments

Comments
 (0)