Skip to content

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

Fix empty MP3 file tests on Linux and Windows.

Peter Sobot366b9ceae626
diff --git a/pedalboard/io/WriteableAudioFile.h b/pedalboard/io/WriteableAudioFile.h
index 8f650fa..06d0087 100644
--- a/pedalboard/io/WriteableAudioFile.h
+++ b/pedalboard/io/WriteableAudioFile.h
@@ -894,33 +894,6 @@ inline void init_writeable_audio_file(py::module &m) {
"The quality setting used to write this file. For many "
"formats, this may be None.");
- m.def("get_supported_read_formats", []() {
- juce::AudioFormatManager manager;
- manager.registerBasicFormats();
-
- std::vector<std::string> formatNames(manager.getNumKnownFormats());
- juce::StringArray extensions;
- for (int i = 0; i < manager.getNumKnownFormats(); i++) {
- auto *format = manager.getKnownFormat(i);
- extensions.addArray(format->getFileExtensions());
- }
-
- extensions.trim();
- extensions.removeEmptyStrings();
- extensions.removeDuplicates(true);
-
- std::vector<std::string> output;
- for (juce::String s : extensions) {
- output.push_back(s.toStdString());
- }
-
- std::sort(
- output.begin(), output.end(),
- [](const std::string lhs, const std::string rhs) { return lhs < rhs; });
-
- return output;
- });
-
m.def("get_supported_write_formats", []() {
// JUCE doesn't support writing other formats out-of-the-box on all
// platforms, and there's no easy way to tell which formats are supported
diff --git a/tests/test_io.py b/tests/test_io.py
index 7f67249..0fa78bd 100644
--- a/tests/test_io.py
+++ b/tests/test_io.py
@@ -752,11 +752,14 @@ def test_write_empty_file(extension: str, samplerate: float, num_channels: int):
with pedalboard.io.AudioFile(stream) as af:
assert af.samplerate == samplerate
assert af.num_channels == num_channels
- try:
+ # The built-in JUCE MP3 reader (only used on Linux and Windows)
+ # reads zero-length MP3 files as having exactly one frame.
+ if 'mp3' in extension and platform.system() != "Darwin":
+ assert af.frames <= 1152
+ contents = af.read(af.frames)
+ np.testing.assert_allclose(np.zeros_like(contents), contents)
+ else:
assert af.frames == 0
- finally:
- with open("should_be_empty.mp3", "wb") as f:
- f.write(stream.getvalue())
@pytest.mark.parametrize(