| | |
| | | package model |
| | | |
| | | import "fmt" |
| | | import ( |
| | | "fmt" |
| | | "sort" |
| | | ) |
| | | |
| | | const ( |
| | | BackendSenseVoice = "sensevoice" |
| | | BackendSenseVoice = "sensevoice" |
| | | BackendMoonshine = "moonshine" |
| | | BackendNemoTransducer = "nemo_transducer" |
| | | BackendQwen3ASR = "qwen3_asr" |
| | | BackendXASRStreaming = "x_asr_streaming" |
| | | ) |
| | | |
| | | var modelProfiles = map[string]ModelProfile{ |
| | |
| | | }, |
| | | RecommendedFor: []string{"zh-CN"}, |
| | | Description: "轻量中文模型,适合中文和中英混输。", |
| | | DownloadURLs: []string{ |
| | | "http://www.maikami.com/voicesnap/sensevoice.zip", |
| | | "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", |
| | | }, |
| | | InstallDirName: "sensevoice-zh", |
| | | LegacyDirNames: []string{"sensevoice"}, |
| | | RequiredFiles: []RequiredFileRule{ |
| | |
| | | ProviderOrder: []string{"coreml", "cpu"}, |
| | | NumThreads: 4, |
| | | }, |
| | | MoonshineModelID: { |
| | | ID: MoonshineModelID, |
| | | DisplayName: "Moonshine English", |
| | | BackendKind: BackendMoonshine, |
| | | Tier: "default", |
| | | SupportedLanguageIDs: []string{EnglishLanguageID}, |
| | | RecommendedFor: []string{EnglishLanguageID}, |
| | | Description: "轻量英文离线模型,适合英文听写和英文日常输入。", |
| | | ApproxSize: "约 239 MiB 下载包,解压后约 270-280 MiB", |
| | | DownloadURLs: []string{ |
| | | "https://github.com/k2-fsa/sherpa-onnx/releases/download/asr-models/sherpa-onnx-moonshine-base-en-int8.tar.bz2", |
| | | }, |
| | | InstallDirName: "moonshine-en", |
| | | RequiredFiles: []RequiredFileRule{ |
| | | { |
| | | Role: "preprocessor", |
| | | AllOf: []string{"preprocess.onnx"}, |
| | | Required: true, |
| | | }, |
| | | { |
| | | Role: "encoder", |
| | | AllOf: []string{"encode.int8.onnx"}, |
| | | Required: true, |
| | | }, |
| | | { |
| | | Role: "uncached_decoder", |
| | | AllOf: []string{"uncached_decode.int8.onnx"}, |
| | | Required: true, |
| | | }, |
| | | { |
| | | Role: "cached_decoder", |
| | | AllOf: []string{"cached_decode.int8.onnx"}, |
| | | Required: true, |
| | | }, |
| | | { |
| | | Role: "tokens", |
| | | AllOf: []string{"tokens.txt"}, |
| | | Required: true, |
| | | }, |
| | | }, |
| | | ProviderOrder: []string{"cpu"}, |
| | | NumThreads: 4, |
| | | }, |
| | | ParakeetModelID: { |
| | | ID: ParakeetModelID, |
| | | DisplayName: "Parakeet English", |
| | | BackendKind: BackendNemoTransducer, |
| | | Tier: "advanced", |
| | | SupportedLanguageIDs: []string{EnglishLanguageID}, |
| | | RecommendedFor: []string{EnglishLanguageID}, |
| | | Description: "高质量英文离线模型,适合英文长句、技术词和更高准确率需求。", |
| | | ApproxSize: "约 478 MiB 下载包", |
| | | DownloadURLs: []string{ |
| | | "https://github.com/k2-fsa/sherpa-onnx/releases/download/asr-models/sherpa-onnx-nemo-parakeet-unified-en-0.6b-int8-non-streaming.tar.bz2", |
| | | }, |
| | | InstallDirName: "parakeet-en", |
| | | RequiredFiles: []RequiredFileRule{ |
| | | { |
| | | Role: "encoder", |
| | | AllOf: []string{"encoder.int8.onnx"}, |
| | | Required: true, |
| | | }, |
| | | { |
| | | Role: "decoder", |
| | | AllOf: []string{"decoder.int8.onnx"}, |
| | | Required: true, |
| | | }, |
| | | { |
| | | Role: "joiner", |
| | | AllOf: []string{"joiner.int8.onnx"}, |
| | | Required: true, |
| | | }, |
| | | { |
| | | Role: "tokens", |
| | | AllOf: []string{"tokens.txt"}, |
| | | Required: true, |
| | | }, |
| | | }, |
| | | ProviderOrder: []string{"cpu"}, |
| | | NumThreads: 4, |
| | | }, |
| | | Qwen3ASRModelID: { |
| | | ID: Qwen3ASRModelID, |
| | | DisplayName: "Qwen3-ASR", |
| | | BackendKind: BackendQwen3ASR, |
| | | Tier: "advanced", |
| | | SupportedLanguageIDs: []string{DefaultLanguageID, "zh-Hans", "zh-Hant", "yue"}, |
| | | RecommendedFor: []string{DefaultLanguageID}, |
| | | Description: "高质量中文离线模型,适合中文长句、技术词和中英混输准确率需求。", |
| | | ApproxSize: "约 838 MiB 下载包,解压后约 1.9 GiB", |
| | | DownloadURLs: []string{ |
| | | "https://github.com/k2-fsa/sherpa-onnx/releases/download/asr-models/sherpa-onnx-qwen3-asr-0.6B-int8-2026-03-25.tar.bz2", |
| | | }, |
| | | InstallDirName: "qwen3-asr-0.6b", |
| | | RequiredFiles: []RequiredFileRule{ |
| | | { |
| | | Role: "conv_frontend", |
| | | AllOf: []string{"conv_frontend.onnx"}, |
| | | Required: true, |
| | | }, |
| | | { |
| | | Role: "encoder", |
| | | AllOf: []string{"encoder.int8.onnx"}, |
| | | Required: true, |
| | | }, |
| | | { |
| | | Role: "decoder", |
| | | AllOf: []string{"decoder.int8.onnx"}, |
| | | Required: true, |
| | | }, |
| | | { |
| | | Role: "tokenizer", |
| | | AllOf: []string{"tokenizer"}, |
| | | Required: true, |
| | | Directory: true, |
| | | }, |
| | | { |
| | | Role: "tokenizer_merges", |
| | | AllOf: []string{"tokenizer/merges.txt"}, |
| | | Required: true, |
| | | }, |
| | | { |
| | | Role: "tokenizer_vocab", |
| | | AllOf: []string{"tokenizer/vocab.json"}, |
| | | Required: true, |
| | | }, |
| | | }, |
| | | ProviderOrder: []string{"cpu"}, |
| | | NumThreads: 4, |
| | | }, |
| | | XASRZhEn960ModelID: { |
| | | ID: XASRZhEn960ModelID, |
| | | DisplayName: "X-ASR zh-en 960ms", |
| | | BackendKind: BackendXASRStreaming, |
| | | Tier: "experimental", |
| | | SupportedLanguageIDs: []string{DefaultLanguageID, "zh-Hans", "zh-Hant", "yue", EnglishLanguageID}, |
| | | RecommendedFor: []string{DefaultLanguageID, EnglishLanguageID}, |
| | | Description: "实验性中英流式模型,适合评估中英混输和未来边说边出字体验。", |
| | | ApproxSize: "单个 960 ms 模型目录约 586 MiB", |
| | | InstallDirName: "x-asr-zh-en-960ms", |
| | | RequiredFiles: []RequiredFileRule{ |
| | | { |
| | | Role: "encoder", |
| | | AllOf: []string{"encoder-960ms.onnx"}, |
| | | Required: true, |
| | | }, |
| | | { |
| | | Role: "decoder", |
| | | AllOf: []string{"decoder-960ms.onnx"}, |
| | | Required: true, |
| | | }, |
| | | { |
| | | Role: "joiner", |
| | | AllOf: []string{"joiner-960ms.onnx"}, |
| | | Required: true, |
| | | }, |
| | | { |
| | | Role: "tokens", |
| | | AllOf: []string{"tokens.txt"}, |
| | | Required: true, |
| | | }, |
| | | }, |
| | | ProviderOrder: []string{"cpu"}, |
| | | NumThreads: 1, |
| | | }, |
| | | } |
| | | |
| | | var languageProfiles = map[string]LanguageProfile{ |
| | | "zh-CN": { |
| | | ID: "zh-CN", |
| | | DisplayName: "中文", |
| | | UILocale: "zh-CN", |
| | | SystemMatchers: []string{"zh", "zh-CN", "zh-Hans", "zh-Hant"}, |
| | | DefaultModelID: DefaultModelID, |
| | | DefaultLanguageID: { |
| | | ID: DefaultLanguageID, |
| | | DisplayName: "Chinese", |
| | | NativeName: "中文", |
| | | UILocale: "zh", |
| | | SystemMatchers: []string{"zh", "zh-CN", "zh-Hans", "zh-Hant"}, |
| | | DefaultModelID: DefaultModelID, |
| | | UpgradeModelIDs: []string{Qwen3ASRModelID, XASRZhEn960ModelID}, |
| | | }, |
| | | EnglishLanguageID: { |
| | | ID: EnglishLanguageID, |
| | | DisplayName: "English", |
| | | NativeName: "English", |
| | | UILocale: "en", |
| | | SystemMatchers: []string{"en", "en-US", "en-GB", "en-AU", "en-CA"}, |
| | | DefaultModelID: MoonshineModelID, |
| | | UpgradeModelIDs: []string{ParakeetModelID, XASRZhEn960ModelID}, |
| | | }, |
| | | } |
| | | |
| | |
| | | for _, profile := range languageProfiles { |
| | | profiles = append(profiles, profile) |
| | | } |
| | | sort.Slice(profiles, func(i, j int) bool { |
| | | if profiles[i].ID == DefaultLanguageID { |
| | | return true |
| | | } |
| | | if profiles[j].ID == DefaultLanguageID { |
| | | return false |
| | | } |
| | | return profiles[i].ID < profiles[j].ID |
| | | }) |
| | | return profiles |
| | | } |
| | | |
| | | func NormalizeLanguageID(id string) string { |
| | | if _, err := GetLanguageProfile(id); err != nil { |
| | | return DefaultLanguageID |
| | | } |
| | | return id |
| | | } |