| | |
| | | import ( |
| | | "encoding/json" |
| | | "os" |
| | | "runtime" |
| | | "voicesnap/internal/logger" |
| | | "voicesnap/internal/model" |
| | | "voicesnap/internal/paths" |
| | | ) |
| | | |
| | | const ( |
| | | LegacyDefaultHotkeyVK = 0xA5 |
| | | RightModifierDefaultVK = 0x5C |
| | | HotkeyModeTap = "tap" |
| | | HotkeyModeHold = "hold" |
| | | LanguageModeAuto = "auto" |
| | |
| | | |
| | | // Default returns a default configuration. |
| | | func Default() *Config { |
| | | return defaultWithHotkey(defaultHotkeyVKForNewConfig(runtime.GOOS)) |
| | | } |
| | | |
| | | func legacyDefaultForExistingConfig() *Config { |
| | | return defaultWithHotkey(LegacyDefaultHotkeyVK) |
| | | } |
| | | |
| | | // ExistingConfigFallback returns a legacy-safe fallback for cases where a |
| | | // config file exists but cannot be read or parsed. |
| | | func ExistingConfigFallback() *Config { |
| | | return legacyDefaultForExistingConfig() |
| | | } |
| | | |
| | | func defaultWithHotkey(hotkeyVK int) *Config { |
| | | return &Config{ |
| | | HotkeyVK: 0xA5, // Right Alt |
| | | HotkeyVK: hotkeyVK, |
| | | HotkeyMode: HotkeyModeHold, |
| | | AutoHide: true, |
| | | SoundFeedback: true, |
| | |
| | | LanguageID: model.DefaultLanguageID, |
| | | ModelDownloadUrl: "http://www.maikami.com/voicesnap/sensevoice.zip", |
| | | FallbackModelDownloadUrl: "https://modelscope.cn/models/sherpa-onnx/sherpa-onnx-sense-voice-zh-en-ja-ko-yue/resolve/master/sherpa-onnx-sense-voice-zh-en-ja-ko-yue-int8-2024-07-17.tar.bz2", |
| | | } |
| | | } |
| | | |
| | | func defaultHotkeyVKForNewConfig(goos string) int { |
| | | switch goos { |
| | | case "darwin", "windows": |
| | | return RightModifierDefaultVK |
| | | default: |
| | | return LegacyDefaultHotkeyVK |
| | | } |
| | | } |
| | | |
| | |
| | | return nil, err |
| | | } |
| | | |
| | | cfg := Default() |
| | | cfg := legacyDefaultForExistingConfig() |
| | | if err := json.Unmarshal(data, cfg); err != nil { |
| | | return nil, err |
| | | } |