Skip to content

πŸŽ› πŸ”Š A Python library for audio.

Add tests for empty file writing.

Peter Sobotaac48728c197
diff --git a/pedalboard/io/LameMP3AudioFormat.h b/pedalboard/io/LameMP3AudioFormat.h
index a8f604c..463ee8e 100644
--- a/pedalboard/io/LameMP3AudioFormat.h
+++ b/pedalboard/io/LameMP3AudioFormat.h
@@ -227,6 +227,10 @@ public:
return;
}
+ if (!output->setPosition(0)) {
+ return;
+ }
+
if (!output->write(buffer, frameTagSize)) {
return;
}
diff --git a/tests/test_io.py b/tests/test_io.py
index 4171541..8f1d858 100644
--- a/tests/test_io.py
+++ b/tests/test_io.py
@@ -729,6 +729,33 @@ def test_mp3_write(samplerate: float, num_channels: int, qualities):
assert len(set(file_sizes)) <= len(file_sizes)
[email protected]("extension", pedalboard.io.get_supported_write_formats())
[email protected]("samplerate", [32000, 44100, 48000])
[email protected]("num_channels", [1, 2])
+def test_write_empty_file(extension: str, samplerate: float, num_channels: int):
+ stream = io.BytesIO()
+
+ with pedalboard.io.WriteableAudioFile(
+ stream,
+ samplerate=samplerate,
+ num_channels=num_channels,
+ format=extension,
+ ) as af:
+ pass
+
+ assert len(stream.getvalue()) > 0
+ stream.seek(0)
+
+ with pedalboard.io.AudioFile(stream) as af:
+ assert af.samplerate == samplerate
+ assert af.num_channels == num_channels
+ try:
+ assert af.frames == 0
+ finally:
+ with open("should_be_empty.mp3", "wb") as f:
+ f.write(stream.getvalue())
+
+
@pytest.mark.parametrize(
"extension,quality,expected",
[