From 12a7137e8b26ec92aaa64a44fe5e765a8a8632bc Mon Sep 17 00:00:00 2001 From: Drew McCormack Date: Tue, 21 Jan 2025 14:27:07 +0100 Subject: [PATCH] Ensure that rounded capacity is non-zero in resampleBuffer. Round off in resampling can lead to a rounded capacity of zero, causing AVAudioPCMBuffer to fail, and thereby causing transcription to fail entirely. (#224) This is a simple fix, simply requiring the buffer to have a non-zero capacity. --- Sources/WhisperKit/Core/Audio/AudioProcessor.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Sources/WhisperKit/Core/Audio/AudioProcessor.swift b/Sources/WhisperKit/Core/Audio/AudioProcessor.swift index 689d07b..052ba20 100644 --- a/Sources/WhisperKit/Core/Audio/AudioProcessor.swift +++ b/Sources/WhisperKit/Core/Audio/AudioProcessor.swift @@ -423,8 +423,8 @@ public class AudioProcessor: NSObject, AudioProcessing { // Check if the capacity is a whole number if capacity.truncatingRemainder(dividingBy: 1) != 0 { - // Round to the nearest whole number - let roundedCapacity = capacity.rounded(.toNearestOrEven) + // Round to the nearest whole number, which is non-zero + let roundedCapacity = max(1, capacity.rounded(.toNearestOrEven)) Logging.debug("Rounding buffer frame capacity from \(capacity) to \(roundedCapacity) to better fit new sample rate") capacity = roundedCapacity }