skip-silence icon indicating copy to clipboard operation
skip-silence copied to clipboard

Adaptive Volume Threshold and speed like NewPipe does, or even better.

Open 1nd1g0 opened this issue 4 years ago • 6 comments

Hello there, Bennett. Right to the point.

Would you be so kind to add an adaptive (dynamic) threshold option? It's a part of software adaptive noise gates and dynamic range compressors in real-time digital signal processing for decades. Our task is also "real-time" processing. Presumably, no large preload or buffering needed yet.

The basic idea is to start with zero (silence) threshold and x1 speed gradually integrate the volume level of incoming samples , calculating the whole volume scale of the already played part: the highest integral level, the lowest integral level (noise/music) etc. The threshold gradually moves up to the calculated noise/music level during the whole playback. Moving back towards safe (0%) threshold has to be accelerated so no audio is lost when music/noise level dramatically decreased. Also the next trick with quiet audio speed slowdown comes handy.

Adaptive speed option can be very useful. Generally - the lower highest integral volume or (option) the higher the threshold over time is, the less FF speed is used for the user to hear better what was said.

Thanks in advance for your consideration.

1nd1g0 avatar Nov 15 '20 18:11 1nd1g0

Hello there, sorry for only now coming back to you on this. Do you have any further resources, maybe even code samples, for such an algorithm or would be willing to try to implement this?

I have created a new branch "dynamic-threshold" that holds the code needed around the dynamic threshold calculating code (adding a new setting, saving previous sample volumes etc.) but I don't really understand how your described algorithm should work. As a placeholder, I added a script that simply that uses 30% of the average volume of the last 500 samples (at ca. 60Hz) as the threshold: https://github.com/vantezzen/skip-silence/blob/88d70980b14cfb5754d181a1cd50c50872308393/src/pages/content/lib/DynamicThresholdCalculator.ts#L34-L38

This would need to get replaced with a real implementation of your described algorithm.

vantezzen avatar Jul 01 '21 13:07 vantezzen

I've updated the implementation to be closer to what you've described. It will now slowly get to the volume of the lowest 10th percentile. This will be released as "beta" in Skip Silence 4

https://github.com/vantezzen/skip-silence/blob/cc5b15540cf54a9907c60e8be48bb8fc5b858aea/src/pages/content/lib/DynamicThresholdCalculator.ts#L39-L49

vantezzen avatar Jul 23 '21 13:07 vantezzen

Wow, thanks a lot, man. I've also lost your message within a sea of other notifications. I'll test the implementation in the wild. Meanwhile lurking through NewPipe source I've learned, that android's ExoPlayer(2) with built-in silence skipping is used. Here is the last commit that introduces silence skipping parameterization.

https://github.com/google/ExoPlayer/commit/ad1dffcae8e3ff73a32716a47d0b837c7d4ffe59

1nd1g0 avatar Jul 25 '21 17:07 1nd1g0

It looks like ExoPlayer implements its Skip Silence functionality in https://github.com/google/ExoPlayer/blob/bd54394391/library/core/src/main/java/com/google/android/exoplayer2/audio/SilenceSkippingAudioProcessor.java, but I can't really find adaptive threshold code there.

The code uses silenceThresholdLevel to determine if audio is SILENCE, NOISY or MAYBE_SILENT (the transition state between the two) but I can't find the code where this threshold is changed - in fact, the threshold is set as final so it can't be changed unless the complete class is re-initialized.

Maybe I'm overseeing something, NewPipe is implementing the dynamic threshold itself or its simply using a static threshold instead of dynamically updating the threshold based on the current volume.

vantezzen avatar Aug 07 '21 08:08 vantezzen

I have an error when installing in the Google Chrome browser: Unrecognized manifest key 'browser_specific_settings'. {"description":"Skip silent parts in videos and audio files","version":"4.0.0","name":"Skip Silence","background":{"page":"background.html"},"page_action":{"default_icon":{"32":"assets/img/disabled.png"},"default_popup":"popup.html"},"icons":{"128":"assets/img/icon-128.png"},"permissions":["activeTab","storage"],"browser_specific_settings":{"gecko":{"strict_min_version":"91.0"}},"content_scripts":[{"all_frames":true,"matches":["http:///","https:///","<all_urls>"],"js":["contentScript.bundle.js"],"css":["content.styles.css"]}],"web_accessible_resources":["content.styles.css","assets/img/icon-128.png","assets/img/icon-34.png","assets/img/close.svg"],"commands":{"toggle-enable":{"suggested_key":{"default":"Ctrl+Shift+S"},"description":"Enable/disable Skip Silence for the current tab"},"toggle-command-bar":{"suggested_key":{"default":"Alt+Shift+S"},"description":"Show/hide the command bar"}},"manifest_version":2,"content_security_policy":"script-src 'self' 'unsafe-eval' https://scripts.simpleanalyticscdn.com https://a.vantezzen.io; object-src 'self'"}

AlexLev59 avatar Dec 22 '21 19:12 AlexLev59

@AlexLev59 Wrong topic. And I believe this is not an error but just a warning that doesn't prevent you from using the extension. Right?

WofWca avatar Dec 25 '21 08:12 WofWca