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.

Librosa Trim vs SOX Trim

See original GitHub issue

Description

Help with Librosa trim and understanding it.

Steps/Code to Reproduce

import librosa

trimmed, _ = librosa.effects.trim(signal)
plot_waveform([trimmed[:1000]])
print(librosa.get_duration(signal), librosa.get_duration(trimmed))

Expected Results

Expecting the first ~400 samples to be trimmed.

Actual Results

image 6.195238095238095 6.195238095238095

Versions

Darwin-17.5.0-x86_64-i386-64bit Python 3.6.5 (default, May 15 2018, 11:11:58) [GCC 4.2.1 Compatible Apple LLVM 9.1.0 (clang-902.0.39.1)] NumPy 1.14.3 SciPy 1.1.0 librosa 0.6.0

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
bmcfeecommented, Jun 1, 2018

This is a bit difficult to diagnose without access to the original signal.

For clarification, what trim does is clip off frames at the beginning or end of the clip where the rmse is significantly below the reference value. By default, the reference value is the max over all frames, and the threshold for “significant” is 60dB. The framing parameters are aligned to the library defaults (n=2048, hop=512). In your case, it looks like there’s enough energy in the first frame (2048 samples) to keep it above the threshold. If you want to narrow the analysis, you can drop the frame length (say, 512) and hop length (say 128) and that should give your expected behavior.

0reactions
PetrochukMcommented, Jun 5, 2018

@bmcfee Thank you! That worked well. Appreciate your time.

Read more comments on GitHub >

github_iconTop Results From Across the Web

librosa.effects.trim — librosa 0.10.0.dev0 documentation
Trim leading and trailing silence from an audio signal. Parameters. ynp.ndarray, shape=(…, n). Audio signal. Multi-channel is supported.
Read more >
Use Python to trim and pad wav file using sox without saving ...
Save this question. Show activity on this post. I found that the best way to trim and pad wav files is to use...
Read more >
What are some python packages I can use to cut audio files
The librosa library is usually used. ... The most basic approach probably would be to use scipy 's read and write functions for...
Read more >
librosa.effects.trim — librosa 0.6.0 documentation
Trim leading and trailing silence from an audio signal. Parameters: y : np.ndarray, shape=(n,) or (2, ...
Read more >
Basic Audio Handling - Medium
1st part: how to use ffmpeg and sox to handle audio files ... To trim an audio file, e.g. from the 60th to...
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