From a76106644ab95d0feba7820d70dcd89ae2c57aad Mon Sep 17 00:00:00 2001 From: mattisssa Date: Mon, 16 Dec 2024 20:05:28 +0000 Subject: [PATCH] Audio: Fix taking a suffix of negative length from a collection --- Sources/WhisperKit/Core/Audio/AudioProcessor.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/WhisperKit/Core/Audio/AudioProcessor.swift b/Sources/WhisperKit/Core/Audio/AudioProcessor.swift index a9dfe632..1e8ae4ab 100644 --- a/Sources/WhisperKit/Core/Audio/AudioProcessor.swift +++ b/Sources/WhisperKit/Core/Audio/AudioProcessor.swift @@ -469,7 +469,7 @@ public class AudioProcessor: NSObject, AudioProcessing { ) -> Bool { // Calculate the number of energy values to consider based on the duration of the next buffer // Each energy value corresponds to 1 buffer length (100ms of audio), hence we divide by 0.1 - let energyValuesToConsider = Int(nextBufferInSeconds / 0.1) + let energyValuesToConsider = max(0, Int(nextBufferInSeconds / 0.1)) // Extract the relevant portion of energy values from the currentRelativeEnergy array let nextBufferEnergies = relativeEnergy.suffix(energyValuesToConsider)