wire whisper-cpp into transcriber factory
This commit is contained in:
@@ -5,6 +5,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/leonardotrapani/hyprvoice/internal/models/whisper"
|
||||||
"github.com/leonardotrapani/hyprvoice/internal/provider"
|
"github.com/leonardotrapani/hyprvoice/internal/provider"
|
||||||
"github.com/leonardotrapani/hyprvoice/internal/recording"
|
"github.com/leonardotrapani/hyprvoice/internal/recording"
|
||||||
)
|
)
|
||||||
@@ -106,6 +107,12 @@ func NewTranscriber(config Config) (Transcriber, error) {
|
|||||||
adapter = NewOpenAIAdapter(model.Endpoint, config.APIKey, model.ID, config.Language, config.Keywords, registryProvider)
|
adapter = NewOpenAIAdapter(model.Endpoint, config.APIKey, model.ID, config.Language, config.Keywords, registryProvider)
|
||||||
case "elevenlabs":
|
case "elevenlabs":
|
||||||
adapter = NewElevenLabsAdapter(model.Endpoint, config.APIKey, model.ID, config.Language)
|
adapter = NewElevenLabsAdapter(model.Endpoint, config.APIKey, model.ID, config.Language)
|
||||||
|
case "whisper-cpp":
|
||||||
|
modelPath := whisper.GetModelPath(config.Model)
|
||||||
|
if modelPath == "" {
|
||||||
|
return nil, fmt.Errorf("unknown whisper model: %s", config.Model)
|
||||||
|
}
|
||||||
|
adapter = NewWhisperCppAdapter(modelPath, config.Language, config.Threads)
|
||||||
default:
|
default:
|
||||||
return nil, fmt.Errorf("unsupported adapter type: %s", model.AdapterType)
|
return nil, fmt.Errorf("unsupported adapter type: %s", model.AdapterType)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -174,6 +174,35 @@ func TestNewTranscriber(t *testing.T) {
|
|||||||
},
|
},
|
||||||
wantErr: true,
|
wantErr: true,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "valid whisper-cpp config creates adapter",
|
||||||
|
config: Config{
|
||||||
|
Provider: "whisper-cpp",
|
||||||
|
Language: "en",
|
||||||
|
Model: "base.en",
|
||||||
|
Threads: 4,
|
||||||
|
},
|
||||||
|
wantErr: false, // creates adapter even if model file doesn't exist (runtime check)
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "whisper-cpp without api key is valid",
|
||||||
|
config: Config{
|
||||||
|
Provider: "whisper-cpp",
|
||||||
|
APIKey: "", // no api key required
|
||||||
|
Language: "en",
|
||||||
|
Model: "tiny.en",
|
||||||
|
},
|
||||||
|
wantErr: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "whisper-cpp with unknown model returns error",
|
||||||
|
config: Config{
|
||||||
|
Provider: "whisper-cpp",
|
||||||
|
Language: "en",
|
||||||
|
Model: "nonexistent-whisper-model",
|
||||||
|
},
|
||||||
|
wantErr: true,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
|
|||||||
@@ -218,3 +218,11 @@ Started: Sun Feb 1 12:22:47 AM CET 2026
|
|||||||
- Registered in provider.init()
|
- Registered in provider.init()
|
||||||
- Comprehensive test file created: whisper_cpp_test.go
|
- Comprehensive test file created: whisper_cpp_test.go
|
||||||
- All tests passing, typecheck passes
|
- All tests passing, typecheck passes
|
||||||
|
|
||||||
|
### Task 22: Wire whisper-cpp into transcriber factory
|
||||||
|
- Added `case "whisper-cpp"` to NewTranscriber() switch on model.AdapterType
|
||||||
|
- Imports whisper package to get model path via `whisper.GetModelPath(config.Model)`
|
||||||
|
- Creates `NewWhisperCppAdapter(modelPath, config.Language, config.Threads)`
|
||||||
|
- Returns error if whisper model ID is unknown
|
||||||
|
- Added tests for whisper-cpp factory cases: valid config, no API key required, unknown model error
|
||||||
|
- All tests passing, typecheck passes
|
||||||
+1
-1
@@ -530,7 +530,7 @@
|
|||||||
"Full flow works: config -> factory -> adapter -> transcription",
|
"Full flow works: config -> factory -> adapter -> transcription",
|
||||||
"Typecheck passes"
|
"Typecheck passes"
|
||||||
],
|
],
|
||||||
"passes": false
|
"passes": true
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"title": "Update config for local transcription",
|
"title": "Update config for local transcription",
|
||||||
|
|||||||
Reference in New Issue
Block a user