Ariver
2026-05-18 6a74e8e739c3d2db2db737b1ecb0117eb88a4129
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package services
 
import (
    "voicesnap/internal/engine"
    "voicesnap/internal/model"
    "voicesnap/internal/paths"
 
    "github.com/wailsapp/wails/v3/pkg/application"
)
 
// EngineService provides engine status and model management to the frontend.
type EngineService struct {
    app          *application.App
    initCallback func()
}
 
func NewEngineService() *EngineService {
    return &EngineService{}
}
 
// ModelExists returns true if the ASR model files are present.
func (s *EngineService) ModelExists() bool {
    return engine.ModelExists()
}
 
// DownloadModel downloads the ASR model with progress events.
func (s *EngineService) DownloadModel(primaryURL, fallbackURL string) error {
    err := model.Download(primaryURL, fallbackURL, paths.ModelsRoot(), func(percent float64, downloaded, total int64) {
        if s.app != nil {
            s.app.Event.Emit("model:download-progress", map[string]interface{}{
                "percent":    percent,
                "downloaded": downloaded,
                "total":      total,
            })
        }
    })
    if err != nil {
        return err
    }
 
    if s.initCallback != nil {
        go s.initCallback()
    }
    return nil
}
 
// SetInitCallback sets the callback to re-initialize the engine after model download.
func (s *EngineService) SetInitCallback(cb func()) {
    s.initCallback = cb
}
 
// SetApp sets the Wails app reference for event emission.
func (s *EngineService) SetApp(app *application.App) {
    s.app = app
}