Skip to content

Commit

Permalink
Fix: Changed clip loading behaviour so that it fills missing data wit…
Browse files Browse the repository at this point in the history
…h 0s
  • Loading branch information
mbsantiago committed Sep 14, 2023
1 parent 19c98b1 commit 878cccf
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/soundevent/audio/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ def load_audio(
subtype=subformat,
samplerate=media_info.samplerate,
channels=media_info.channels,
fill_value=0,
)


Expand Down
23 changes: 23 additions & 0 deletions tests/test_audio/test_audio.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,3 +169,26 @@ def test_can_load_clip_from_24_bit_depth_wav():
wav = load_clip(clip)

assert wav.shape == (recording.samplerate * duration, recording.channels)


def test_loading_clip_after_end_time_will_pad_with_zeros(
random_wav,
):
"""Test loading a clip that is out of bounds."""
# Arrange
path = random_wav(
samplerate=16_000,
duration=1,
channels=1,
)

recording = data.Recording.from_file(path)
clip = data.Clip(
recording=recording,
start_time=0.5,
end_time=1.5,
)

# Act
wav = load_clip(clip)
assert wav.shape == (recording.samplerate * 1, recording.channels)

0 comments on commit 878cccf

Please sign in to comment.