Skip to content

fix: save_audio does not validate 1D input shape - #29

Open
andrewwhitecdw wants to merge 1 commit into
NVIDIA:mainfrom
andrewwhitecdw:codequality/utils-save-audio-does-not-validate-1d-input
Open

fix: save_audio does not validate 1D input shape#29
andrewwhitecdw wants to merge 1 commit into
NVIDIA:mainfrom
andrewwhitecdw:codequality/utils-save-audio-does-not-validate-1d-input

Conversation

@andrewwhitecdw

Copy link
Copy Markdown

This PR addresses the following issue in utils.py: save_audio does not validate 1D input shape.

Changes

  • utils.py: save_audio does not validate 1D input shape.

Details

--- a/utils.py
+++ b/utils.py
@@ -1,3 +1,5 @@
-def save_audio(audio, path, sr):
-    # wav: torch with 1d shape
-    audio = audio * MAX_WAV_VALUE
+def save_audio(audio, path, sr):
+    # wav: torch with 1d shape
+    if audio.dim() != 1:
+        raise ValueError(f"save_audio expects 1D audio, got shape {audio.shape}")
+    audio = audio * MAX_WAV_VALUE

Tests

  • tests/test_save_audio_validation.py
--- /dev/null
+++ b/tests/test_save_audio_validation.py
@@ -0,0 +1,12 @@
+import os
+import tempfile
+import pytest
+import torch
+from utils import save_audio
+
+
+def test_save_audio_rejects_non_1d_input():
+    with tempfile.TemporaryDirectory() as tmpdir:
+        path = os.path.join(tmpdir, "audio.wav")
+        two_d = torch.zeros(2, 100)
+        with pytest.raises(ValueError, match="expects 1D audio"):
+            save_audio(two_d, path, sr=22050)

@andrewwhitecdw

Copy link
Copy Markdown
Author

Closing after multiple repair attempts: original patch no longer applies or auditor feedback remains unaddressed.

@andrewwhitecdw
andrewwhitecdw deleted the codequality/utils-save-audio-does-not-validate-1d-input branch August 2, 2026 23:57
@andrewwhitecdw
andrewwhitecdw restored the codequality/utils-save-audio-does-not-validate-1d-input branch August 17, 2026 20:31
@andrewwhitecdw

Copy link
Copy Markdown
Author

script closed on accident

Signed-off-by: Andrew White <andrewwhitecdw@users.noreply.github.com>
Signed-off-by: andrewwhitecdw <andrewwhitecdw@users.noreply.github.com>
@andrewwhitecdw
andrewwhitecdw force-pushed the codequality/utils-save-audio-does-not-validate-1d-input branch from 2e817f4 to 7b2ecb1 Compare August 18, 2026 00:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant