Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# Changelog

## Unreleased

- Local providers no longer fail every recording when the model saved in
config.json belongs to a different engine; they fall back to their own default

## v0.4.0

- Recording overlay wnd
Expand Down
37 changes: 27 additions & 10 deletions transcriber/local.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,11 @@ type localProvider struct {
loadErr error
lang string

name string // provider name, e.g. "parakeet"
hints bool // engine can bias decoding toward a vocabulary
open func(localmodel.Model) (localEngine, error) // load a model with this engine
langsFor func(localmodel.Model) []Language
name string // provider name, e.g. "parakeet"
defaultID string // this engine's model, used when modelID belongs to another
hints bool // engine can bias decoding toward a vocabulary
open func(localmodel.Model) (localEngine, error) // load a model with this engine
langsFor func(localmodel.Model) []Language
}

// newLocalProvider builds a provider around one engine and warms its default
Expand All @@ -54,12 +55,13 @@ func newLocalProvider(name, defaultID, defaultLang string, hints bool,
langsFor func(localmodel.Model) []Language) *localProvider {

p := &localProvider{
modelID: defaultID,
lang: defaultLang,
name: name,
hints: hints,
open: open,
langsFor: langsFor,
modelID: defaultID,
defaultID: defaultID,
lang: defaultLang,
name: name,
hints: hints,
open: open,
langsFor: langsFor,
}
go p.load()
return p
Expand Down Expand Up @@ -156,6 +158,21 @@ func (p *localProvider) load() {
eng localEngine
err error
)
// A model ID belonging to another engine is not an error, it is the normal
// state right after a provider switch: the ID persisted in config.json is
// whatever the PREVIOUS provider had selected, and it arrives here via
// SetModel before the tray ever offers this engine's own list. Fall back to
// this engine's default instead of failing every recording until the user
// happens to open the model menu. Falling back is safe because the default
// is by construction the right engine's file — what must never happen is
// loading another engine's weights, which is a hang, not an error.
if m, ok := localmodel.ByID(want); !ok || m.Engine != p.name {
want = p.defaultID
p.mu.Lock()
p.modelID = want
Comment thread
sumerc marked this conversation as resolved.
p.mu.Unlock()
}
Comment thread
sumerc marked this conversation as resolved.

if m, ok := localmodel.ByID(want); !ok || m.Engine != p.name {
err = fmt.Errorf("unknown %s model %q", p.name, want)
} else if !localmodel.Present(m) {
Expand Down
Loading