Skip to content

Commit 3bc936a

Browse files
authored
Audio: Fix taking a suffix of negative length from a collection (#278)
1 parent 2b8737c commit 3bc936a

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

Sources/WhisperKit/Core/Audio/AudioProcessor.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -469,7 +469,7 @@ public class AudioProcessor: NSObject, AudioProcessing {
469469
) -> Bool {
470470
// Calculate the number of energy values to consider based on the duration of the next buffer
471471
// Each energy value corresponds to 1 buffer length (100ms of audio), hence we divide by 0.1
472-
let energyValuesToConsider = Int(nextBufferInSeconds / 0.1)
472+
let energyValuesToConsider = max(0, Int(nextBufferInSeconds / 0.1))
473473

474474
// Extract the relevant portion of energy values from the currentRelativeEnergy array
475475
let nextBufferEnergies = relativeEnergy.suffix(energyValuesToConsider)

0 commit comments

Comments
 (0)