Skip to content

Commit

Permalink
Merge pull request #616 from kitzeslab/issue_614_1channel
Browse files Browse the repository at this point in the history
resolves #614 - avoid bug in load channels of mono
  • Loading branch information
sammlapp authored Dec 20, 2022
2 parents 81dd85d + b491f0e commit 005389b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
2 changes: 2 additions & 0 deletions opensoundscape/audio.py
Original file line number Diff line number Diff line change
Expand Up @@ -652,6 +652,8 @@ def load_channels_as_audio(
duration=duration,
)
warnings.resetwarnings()
if len(np.shape(samples)) == 1:
samples = [samples]
audio_objects = [
Audio(samples=samples_channel, sample_rate=sr, resample_type=resample_type)
for samples_channel in samples
Expand Down
8 changes: 8 additions & 0 deletions tests/test_audio.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,14 @@ def test_load_channels_as_audio(stereo_wav_str):
s = load_channels_as_audio(stereo_wav_str)
assert max(s[0].samples) == 0 # channel 1 of stereo.wav is all 0
assert max(s[1].samples) == 1 # channel 2 of stereo.wav is all 1
assert len(s) == 2
assert type(s[0]) == Audio


def test_load_channels_as_audio_from_mono(veryshort_wav_str):
s = load_channels_as_audio(veryshort_wav_str)
assert len(s) == 1
assert type(s[0]) == Audio


def test_load_incorrect_timestamp(onemin_wav_str):
Expand Down

0 comments on commit 005389b

Please sign in to comment.