`librosa.load()` silently ignores the `duration` parameter if it is a string
See original GitHub issueDescription
When using soundfile
, librosa.load()
silently ignores the duration
parameter if it is a string.
I haven’t tested other input types, but passing "4"
as the duration
should either work as expected or raise an exception rather than silently being ignored,
Steps/Code to Reproduce
- Ensure you’re loading a format supported by
soundfile
(eg. WAV or FLAC) - Pass a string as the
duration
parameter oflibrosa.load()
:
audio, sr = librosa.load('file.flac', duration="4") # Note that `duration` is a string
print((len(audio) / sr) == 4)
This generally comes out False
since the duration
parameter is ignored and the whole file is loaded.
Expected Results
The duration of the loaded audio should be 4 seconds (if the string is castable to an int), OR a TypeError
(or some other exception) should be raised.
Versions
>>> import platform; print(platform.platform())
Windows-10-10.0.18362-SP0
>>> import sys; print("Python", sys.version)
Python 3.7.3 (default, Apr 24 2019, 15:29:51) [MSC v.1915 64 bit (AMD64)]
>>> import numpy; print("NumPy", numpy.__version__)
NumPy 1.16.4
>>> import scipy; print("SciPy", scipy.__version__)
SciPy 1.3.1
>>> import librosa; print("librosa", librosa.__version__)
librosa 0.7.0
Issue Analytics
- State:
- Created 4 years ago
- Comments:8 (4 by maintainers)
Top Results From Across the Web
librosa.load — librosa 0.10.0.dev0 documentation
Load an audio file as a floating point time series. Audio will be automatically resampled to the given rate (default sr=22050 ). To...
Read more >Source code for librosa.core.audio
def __audioread_load(path, offset, duration, dtype): """Load an audio buffer using audioread. This loads one block at a time, and then concatenates the ...
Read more >Source code for librosa.core.audio
def __soundfile_load(path, offset, duration, dtype): """Load an audio ... path, or file-like If provided, all other parameters are ignored, and the duration ......
Read more >Changelog — librosa 0.9.0 documentation
#1418 librosa.load and librosa.stream can now operate directly on open soundfile ... a bug which ignored weights when step_sizes_sigma did not match length....
Read more >librosa.get_duration — librosa 0.10.0.dev0 documentation
If provided, all other parameters are ignored, and the duration is calculated directly from the audio file. Note that this avoids loading 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
I do not believe that it is being ignored. In fact, there is something more interesting going on. Here’s a part of
load()
:When
duration="4"
is passed, the string is multiplied and results in a frame duration of asr_native
number of 4s. Does that seem right?@konoikon i’m not a big fan of try-catch statements unless absolutely necessary. They are difficult to specify, difficult to test, and difficult to maintain. I am also wary of implicit type conversions at runtime. I would prefer a simple
if
statement on the type and value and duration with a clear error message, thereby deferring the responsibility of supplying the correct type to the user.