Trim and split
See original GitHub issueWould it make sense to add a way of trimming silence when loading audio? Currently I’m doing this silliness, which works alright aside from being performance intensive, but the onset detector surely isn’t built for detecting offsets like this, I’d assume.
path = ... # Path to an audio file with a bunch of leading and trailing silence.
y, sr = librosa.load(path, sr=None)
onsets = librosa.frames_to_time(librosa.onset.onset_detect(y, sr), sr)
offsets = librosa.frames_to_time(librosa.onset.onset_detect(y[::-1], sr), sr) # Suboptimal!
leading_silence = onsets[0]
trailing_silence = offsets[0]
total_duration = librosa.get_duration(y, sr)
y, _ = librosa.load(path, sr, offset=leading_silence, duration=total_duration-leading_silence-trailing_silence)
Also, perhaps if loading with a set duration longer than the actual file, then there should be the option of padding the sequence to the set length, or at least provide a user warning that less than duration
was loaded.
Issue Analytics
- State:
- Created 7 years ago
- Comments:6 (6 by maintainers)
Top Results From Across the Web
How can I split and trim a string into parts all on one line?
Try List<string> parts = line.Split(';').Select(p => p.Trim()).ToList();. FYI, the Foreach method takes an Action (takes T and returns void) ...
Read more >Jargon Defined: Trim, Cut, Split, and Splice | Fun + Easy Video ...
Trim, Cut, Split, and Splice are all done by cutting your video clips. When you trim your video, you remove the head and/or...
Read more >Split String and Trim surrounding Spaces in JavaScript
To split a string and trim the surrounding spaces call the `split()` method on the string. Then call the `map()` method to iterate...
Read more >Cut, Trim, Split Video Editor 4+ - App Store
Cut/Delete unwanted parts of a video. Trim your video Clips with accurate frames. Split movie clips into two and save as smaller parts....
Read more >How to Split, Cut and Trim Videos - Corel Discovery Center
In this tutorial, you will learn how to split, cut, and trim your video clips to remove segments of a video from the...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
We could have trim accept a dB threshold input, and a flag to choose between interpreting that relative to the largest energy in the file, or full-scale. Maybe default to 60 dB below full-scale (rms sample value < 32 in 16 bit ints). It accepts n_fft (in lieu of window_length) and hop_length like the underlying rmse.
(I just noticed that rmse uses spectrogram under the hood. That’s quite extravagant compared to simply summing squared sample values.)
DAn.
On Mon, May 16, 2016 at 1:32 PM, Carl Thomé notifications@github.com wrote:
On a similar note (https://github.com/librosa/librosa/issues/373) I think it would be neat to also have a padding built into
load()
whenduration
andoffset
exceed the audio file’s duration. Perhaps together with a warning in the weirder case when offset is larger than the duration.