3

I am doing signal processing, and using librosa.load to load audio (librosa). But I am confused about the parameters in librosa.load(path, *, sr=22050, mono=True, offset=0.0, duration=None).

My question is the offset parameter, the offset in this reference means starting N seconds into the audio. However, does it actually call onset? Normally, the onset refers to the beginning of a musical note or the sound, and offset means the ending of a musical note.

Or perhaps I misunderstanding it?

skumhest
  • 401
  • 2
  • 10
M.pillow
  • 75
  • 8

1 Answers1

1

You are correct that the offset is just a number of seconds into the clip from which to begin the load. The use of the word "offset" as an argument here is disconnected from the other meaning you are talking about. I think that is just a symptom of "term overloading" in different contexts (I think the true name for this is "semantic overloading").

To detect where a musical note is beginning or ending automatically would require more work than the load method is doing: it is just simply loading the data of the sound file into an array of values. If you set offset to 2.0 (2 seconds) it would just skip the first sample_rate * 2 samples of the sound you are importing.

skumhest
  • 401
  • 2
  • 10
  • Thanks. That's very confusing to set the offset in another meaning! I've already done detecting the beginning and ending of notes, so it's not a big deal to calculate them. By the way, do I need to adjust the sample rate like what you've written? – M.pillow Aug 08 '22 at 02:30
  • You don’t need to adjust the sample rate. The code in my answer that I think you are referring to is not code you need to run. It was just meant to show how many samples would be clipped off the front of the array given a particular `offset` setting as I thought that might clarify exactly what `offset` is doing. It may be worth noting that if you just want the whole sound you can omit the `offset` argument altogether as it defaults to 0.0. In that case, you can also omit the `duration` argument. – skumhest Aug 08 '22 at 09:33
  • Got it! Yeah, I need the offset and duration argument is because I just want the part of the audio, not the whole sound. Also, I posted a new simple Q, do you know this answer? Thanks (https://stackoverflow.com/questions/73274474/whats-the-unit-in-librosa-onset-strength) – M.pillow Aug 08 '22 at 10:11
  • Great! I’ll have a look. If you felt this answer here answered your question sufficiently well there is the option to mark it as accepted. – skumhest Aug 08 '22 at 12:53
  • Sure, I mark it! BTW, did you figure out the answer?(The unit question) Thanks! – M.pillow Aug 08 '22 at 14:23
  • I will definitely have a longer look at that other question later today and see if I can answer it for you. – skumhest Aug 08 '22 at 14:45
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/247134/discussion-between-skumhest-and-m-pillow). – skumhest Aug 08 '22 at 18:48