librosa load with float offset value and float duration

57 views
Skip to first unread message

Ishwara Bhat A

unread,
May 7, 2020, 11:40:27 AM5/7/20
to librosa
Hi,
I'm trying to load a .WAV file with offset as float value (ex: 1.6 seconds) and duration also being float value.

X, sample_rate = librosa.load(audioFile, res_type='kaiser_fast',offset = start_time, duration=duration_seconds,sr=22050*2)


It (correctly?) fails at 
# Construct the stream if offset: start = int(offset * sr) else: start = 0 if duration: frames = int(duration * sr)
in


But as per documentation I can use float value for both. I'm using python 3. 


Please confirm if I can use float offset and duration while loading WAV file.

Thanks
Ishwar




Vincent Lostanlen

unread,
May 7, 2020, 11:49:19 AM5/7/20
to Ishwara Bhat A, librosa
Dear Ishwara,

No issue on my end with:

ogg_path = librosa.util.example_audio_file()
librosa.load(ogg_path, res_type="kaiser_fast", offset=1.5, duration=4.5, sr=44100)

Perhaps you have chosen an offset that exceeds the duration of the input file?


Sincerely,
Vincent.

--
You received this message because you are subscribed to the Google Groups "librosa" group.
To unsubscribe from this group and stop receiving emails from it, send an email to librosa+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/librosa/7284861b-6822-415b-a162-79198807db83%40googlegroups.com.

Brian McFee

unread,
May 7, 2020, 12:46:02 PM5/7/20
to librosa
The code here is correct.  Offsets and durations are specified in units of seconds, which may be fractional (floating-point).  For slicing on load, these numbers are converted to sample indices, which must be integer-valued.

Ishwara Bhat A

unread,
May 9, 2020, 1:58:28 PM5/9/20
to Vincent Lostanlen, librosa
Thanks a lot.
My issue was that the float value I passed was actually a string "3.33", not 3.33. This came from REST service and I simply overlooked. My bad. The hint helped!

Thanks 



--
Thanks and Regards,
Ishwara Bhat
Co-Founder & CTO
IKnowItMOM Private Limited,

This message and its contents are confidential. If you are not intended recipient, please inform the sender and then delete it. Thank you.
Reply all
Reply to author
Forward
0 new messages