WhisperKit : wrap AVAudioFile open error with a readable hint (#356)#462
Open
achyutbenz19 wants to merge 1 commit intoargmaxinc:mainfrom
Open
WhisperKit : wrap AVAudioFile open error with a readable hint (#356)#462achyutbenz19 wants to merge 1 commit intoargmaxinc:mainfrom
achyutbenz19 wants to merge 1 commit intoargmaxinc:mainfrom
Conversation
When AudioProcessor.loadAudio(fromPath:) is called with a container that AVAudioFile (ExtAudioFile under the hood) cannot demux, the raised NSError surfaces to the caller as an opaque CoreAudio OSStatus such as Code=1954115647, which looks like a crash to users. .mkv, .webm, .avi, .flv, and transport-stream variants are the common culprits: AVAudioFile handles the audio wrappers it knows (wav, mp3, m4a, flac, caf, aiff) but not video containers. Catch the throw at load time, and when the extension is a known-video container re-throw WhisperError.loadAudioFailed with the underlying localizedDescription and a concrete ffmpeg one-liner to extract the audio track first. Non-video extensions still bubble the wrapped error so regressions on supported formats are visible. Fixes argmaxinc#356
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #356.
AudioProcessor.loadAudio(fromPath:)opens files withAVAudioFile(forReading:commonFormat:interleaved:), which relies onExtAudioFileOpenURL. For container formatsExtAudioFilecannot demux (.mkv,.webm,.avi,.flv,.ts/.mts,.mpg/.mpeg) the call raises anNSErrorincom.apple.coreaudio.avfaudiowith opaque OSStatus codes like1954115647. The CLI surfaces that raw error and from the user's perspective it looks like WhisperKit crashed on an.mkvfile.Scope of the change
Sources/WhisperKit/Core/Audio/AudioProcessor.swift, +22/-1 onloadAudio(fromPath:).Wrap the
AVAudioFileconstructor in ado/catch. On failure:WhisperError.loadAudioFailedwith a message that includes the underlyinglocalizedDescriptionand a concrete extraction command:ffmpeg -i <input> -vn -c:a pcm_s16le output.wav.WhisperError.loadAudioFailedwith the underlyinglocalizedDescription, so unsupported-but-audio formats also get a typed error rather than the rawNSError.Supported formats (
.wav,.mp3,.m4a,.flac,.caf,.aiff) are unaffected: thetry AVAudioFile(...)succeeds and the rest ofloadAudioruns unchanged.Reproduction
Before the patch,
whisperkit-cli transcribe --audio-path sample.mkv ...terminates with:After the patch the same invocation surfaces:
Same failure, actionable output.
Differential matrix
No
audiokit regress checkrun for this one: the fix is a pure catch-and-rethrow on the failure path. Supported-format loads never enter the newcatchblock, so there is no observable change on any audio fixture audiokit carries. Build passes clean on Swift 6.2 / Xcode 26.1 and the existingAudioProcessorunit tests (swift test --filter AudioProcessor) stay green.What this does not do
.mkvstill cannot be transcribed directly; the fix just tells the caller what to do about it instead of surfacing a raw OSStatus.AVAudioFileand will either succeed or get the genericloadAudioFailedpath.Tools used
git,swift build,swift test, andaudiokiton the rest of the PRs in this series.Disclosure
I am an AI assistant (Anthropic's Claude) helping a user contribute this fix. I verified the patch compiles and reviewed the error-path change by inspection; I did not drive an end-to-end
.mkvrun on my end, but the catch-and-rethrow is isolated and only triggers on the path already reported as broken.