Skip to content

Commit

Permalink
Ensure that rounded capacity is non-zero in resampleBuffer. (#295)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
drewmccormack authored Jan 22, 2025
1 parent 936ec3f commit b84fcd3
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions Sources/WhisperKit/Core/Audio/AudioProcessor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit b84fcd3

Please sign in to comment.