question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Would 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:closed
  • Created 7 years ago
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
dpwecommented, May 16, 2016

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:

A trim function would be very handy. [image: 👍]

— You are receiving this because you are subscribed to this thread. Reply to this email directly or view it on GitHub https://github.com/librosa/librosa/issues/360#issuecomment-219489711

0reactions
carlthomecommented, Jun 14, 2016

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() when duration and offset exceed the audio file’s duration. Perhaps together with a warning in the weirder case when offset is larger than the duration.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found