Repository navigation
fix: AudioArrayClip() cannot process mono audio correctly - #2598
AdairLi2504 wants to merge 1 commit into
Conversation
|
I checked this with a synthetic one-second, 440 Hz mono tone at 8 kHz. On master it exports as two seconds at 220 Hz; at 3ff5f1c the timing and pitch are correct. One detail I noticed: the exported WAV now has two channels, while the input is Nx1 and documented as mono. Would you be open to preserving mono output by allocating the vectorized frame result with the input channel width instead of duplicating the input array? result = np.zeros((len(t), self.array.shape[1]))For that approach, the existing chunk assembly in to_soundarray also needs to concatenate along the time axis. Its mono hstack branch turns nine samples with buffersize=4 into shape (3, 3), while eight or ten samples raise a dimension mismatch. Using np.concatenate(chunks, axis=0) preserves Nx1 arrays and also handles function-generated one-dimensional mono and stereo. A small regression worth keeping: samples = np.arange(9, dtype=float).reshape(-1, 1) / 10
clip = AudioArrayClip(samples, fps=10)
assert clip.nchannels == 1
np.testing.assert_array_equal(clip.to_soundarray(buffersize=4), samples)I tested the channel-preserving variant locally with mono/stereo frame reads, equal and unequal chunk sizes, and PCM export sample/channel counts. All 13 focused checks and the 16 existing AudioClips tests pass. I have not run the full MoviePy suite for this review. Checked on macOS, Python 3.11 and NumPy 2.4.6. |
3ff5f1c to
537801b
Compare
Thank you. I have pushed a new commit to fix that by this way |
|
Thanks for updating it! I reran the checks at 537801b. Mono frame reads and PCM export now preserve the single channel. There’s one remaining case in to_soundarray: its mono branch still uses horizontal stacking when joining chunks. This returns (3, 3) rather than (9, 1): import numpy as np
from moviepy import AudioArrayClip
samples = np.arange(9, dtype=float).reshape(-1, 1) / 10
clip = AudioArrayClip(samples, fps=10)
np.testing.assert_array_equal(clip.to_soundarray(buffersize=4), samples)With 8 or 10 samples, the same call raises a dimension mismatch. Could you also concatenate those chunks along axis 0 and keep these three lengths as regressions? That preserves the time axis for both Nx1 arrays and one-dimensional function-generated mono. The unchanged focused checks give 10 passes and those 3 failures on this revision. Tested with Python 3.11.15 and NumPy 2.4.6 on macOS; I haven’t run the full suite. |
It fixes the #2597 by the first way, and I've tested it by
pytestand the original code in #2597tests/