Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/osekit/core/audio_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,8 @@ def stream(self, chunk_size: int = 8192) -> Generator[np.ndarray, None, None]:
remaining_samples=total_samples - produced_samples,
)
yield flush
produced_samples += len(flush[0])
if flush.size > 0:
produced_samples += len(flush[0])
input_sr = item.sample_rate
quality = resample_quality_settings[
"downsample" if input_sr > self.sample_rate else "upsample"
Expand Down
23 changes: 23 additions & 0 deletions tests/test_audio.py
Original file line number Diff line number Diff line change
Expand Up @@ -2120,3 +2120,26 @@ def test_audio_data_equality(

# AudioDataset equality should account for sample rate
assert ads1 != ads2


def test_resampling_from_different_origin_frequencies(tmp_path: Path) -> None:
sf.write(
tmp_path / "a1.wav",
data=[0.5] * 48_000,
samplerate=48_000,
)
sf.write(
tmp_path / "a2.wav",
data=[0.5] * 48_000,
samplerate=24_000,
)
af1 = AudioFile(tmp_path / "a1.wav", begin=Timestamp("2024-01-01 12:00:00"))
af2 = AudioFile(tmp_path / "a2.wav", begin=Timestamp("2024-01-01 12:00:01"))

ad = AudioData.from_files(
[af1, af2],
sample_rate=12_000,
)

vs = ad.get_value()
assert vs.size == int(ad.duration.total_seconds()) * ad.sample_rate