From b8d3f54a01bb1023ef05d7c151ee48f0974abee3 Mon Sep 17 00:00:00 2001 From: UsernamesLame <156965854+UsernamesLame@users.noreply.github.com> Date: Thu, 29 Aug 2024 13:41:17 -0700 Subject: [PATCH] Removed uncessary channel crushing Calling ```set_channels(1) already converts the audio to one channel, so there was no need to call ```split_to_mono```, instead we can just call ```get_array_of_samples``` This should have a negligible positive impact on performance --- pywhispercpp/model.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/pywhispercpp/model.py b/pywhispercpp/model.py index 882b7e3..be73b94 100644 --- a/pywhispercpp/model.py +++ b/pywhispercpp/model.py @@ -272,9 +272,7 @@ def _load_audio(media_file_path: str) -> np.array: """ sound = AudioSegment.from_file(media_file_path) sound = sound.set_frame_rate(constants.WHISPER_SAMPLE_RATE).set_channels(1) - channel_sounds = sound.split_to_mono() - samples = [s.get_array_of_samples() for s in channel_sounds] - arr = np.array(samples).T.astype(np.float32) + arr = np.array(sound.get_array_of_samples()).T.astype(np.float32) arr /= np.iinfo(samples[0].typecode).max return arr