jiaaro/pydub

Option to return offsets with audio segments when splitting on silence

JakeBamrah opened this issue · 0 comments

Feature request

At the moment split_on_silence() returns separate non-silent audio segments only. I think it would be useful to provide an option to return the starting offsets (in ms) for each audio segment that is created at each split.

For example, a 20s audio clip that is split into three non-silent segments at 3s, 9s and 15s would be accompanied by their starting offsets (3s, 9s and 15s). Such a feature would allow you to keep track of where the split segment sits in relation to the original audio clip (pre-splitting).

Implementation ideas

This could be done by returning a separate array of starting offsets with each AudioSegment or possibly returning a tuple of (AudioSegment, start_offset) by passing a keyword argument to split_on_silence(provide_starting_offsets=True). Another option would be to consider adding an offset property to AudioSegment itself which can be assigned to when split.

Note: This would not be the default behaviour for split_on_silence() because it would create backwards incompatibility but an option specified.

This is something that I have ran into personally at work and thought it was worth opening a discussion about to see if others would find this useful. I would be happy to submit a PR if this would be considered useful to others. If not, feel free to disregard and close this issue.

Finally, thank you very much for your efforts, this library is incredibly useful and a joy to use.