Closed cgfarmer4 closed 8 months ago
Nice idea with the delete and retry! This is probably a good time to handle canceling the previous download task in resetState() because it's a static method. As-is, if you are in the middle of a download and tap the restart button, the previous download will continue and a new one will start. It may require something like this:
let downloadTask = Task {
folder = try await WhisperKit.download(variant: model, from: repoName, progressCallback: { progress in
DispatchQueue.main.async {
loadingProgressValue = Float(progress.fractionCompleted) * specializationProgressRatio
modelState = .downloading
}
// Check for cancellation here
try Task.checkCancellation()
})
}
or something similar to how the progressbar task gets cancelled:
let progressBarTask = Task {
await updateProgressBar(targetProgress: 0.9, maxTime: 240)
}
// Prewarm models
do {
try await whisperKit.prewarmModels()
progressBarTask.cancel()
} catch {
print("Error prewarming models, retrying: \(error.localizedDescription)")
progressBarTask.cancel()
if !redownload {
loadModel(model, redownload: true)
return
} else {
// Redownloading failed, error out
modelState = .unloaded
return
}
}
What do you think? This would also solve a few edge cases with the model selection, like if you select a new model while the previous one is downloading.
Also played around with the mic selector placement, what do you think of this setup? Added a PR to your repo: https://github.com/cgfarmer4/WhisperKit/pull/1
Beautiful, merged your PR and will take a look at cancelling the download tonight.
I removed the retry, getting downloads to cancel is going to require a larger refactor of this function.
let downloadTask = Task {
folder = try await WhisperKit.download(variant: model, from: repoName, progressCallback: { progress in
DispatchQueue.main.async {
loadingProgressValue = Float(progress.fractionCompleted) * specializationProgressRatio
modelState = .downloading
}
// Check for cancellation here
try Task.checkCancellation()
})
}
Going for this path, you get an error that Mutation of captured var 'folder' in concurrently-executing code
.
Then I tried this which fixes the warning: Mutation of captured var 'folder' in concurrently-executing code; this is an error in Swift 6
but doesnt properly cancel the download.
DispatchQueue.main.async {
folder = downloadFolder
}
Next approach I tried was assigning the main Task
similar to how transcriptionTask
is assigned but that requires another refactor around the do/catch
statements.
How about I leave in the delete + your update and call it on this one? The download cancellation needs a rethink or Im totally missing something.
No problem! We can get to that later on, but this is a good addition as-is 👍
Addresses #13 + adds audio device view in both sections.
New delete model button
Restart download of model if connection lost
Move audio input selection between the buttons on transcribe.