@devries-cameron20 / t3code Mirror · read-only
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 03:37 UTC

main
ts 139 lines 4.56 KB
Raw
1 import {
2 accuracyGrade,
3 canonicalLanguage,
4 compareEngineVersions,
5 BENCHMARK_DICTATION_SECONDS,
6 languageIdentity,
7 modelFile,
8 type CatalogData,
9 } from "@handy-computer/models";
10 import { format } from "vite-plus/fmt";
11
12 // ASR architectures registered in transcribe.cpp v0.4.1's src/transcribe-arch.cpp.
13 const ASR_FAMILIES = new Set([
14 "parakeet",
15 "cohere_asr",
16 "canary",
17 "qwen3_asr",
18 "moss",
19 "voxtral",
20 "voxtral_realtime",
21 "canary_qwen",
22 "whisper",
23 "moonshine",
24 "moonshine_streaming",
25 "sensevoice",
26 "funasr_nano",
27 "gigaam",
28 "granite_speech",
29 "granite_speech_nar",
30 "granite5_ctc",
31 "medasr",
32 ]);
33
34 // Older clients rank and pick setup models by this flag; current clients use language recommendations.
35 const RECOMMENDED = new Set([
36 "parakeet-unified-en-0.6b",
37 "nemotron-3.5-asr-streaming-0.6b",
38 "canary-180m-flash",
39 "cohere-transcribe-03-2026",
40 "whisper-medium",
41 ]);
42
43 // Handy labels these weights MIT; Moonshine lists them under its Community License at https://huggingface.co/moonshine-ai/moonshine-models.
44 const COMMUNITY_LICENSED_MOONSHINE = /^moonshine-(?:(?:base|tiny)-(?:ar|ja|ko|uk|vi|zh)|base-es)$/;
45
46 export function generateSpeechCatalog(
47 data: CatalogData,
48 sourceVersion: string,
49 engineVersion: string,
50 ) {
51 if (data.schema !== 2) throw new Error("Unsupported speech catalog schema.");
52 if (engineVersion !== "0.4.1")
53 throw new Error("Review speech catalog loader support for this engine.");
54 const ids = new Set<string>();
55 const filenames = new Set<string>();
56 const models = data.models.flatMap((model) => {
57 if (
58 model.role !== "asr" ||
59 /(?:^|[^a-z0-9])nc(?:$|[^a-z0-9])/i.test(model.license) ||
60 COMMUNITY_LICENSED_MOONSHINE.test(model.id) ||
61 !ASR_FAMILIES.has(model.family) ||
62 compareEngineVersions(model.minEngine ?? data.transcribeCpp, engineVersion) > 0
63 )
64 return [];
65
66 const file = modelFile(model);
67 // The store and native loader accept one root-level GGUF per model.
68 if (!/^[^/\\:]+\.gguf$/.test(file.filename) || file.filename.startsWith(".")) return [];
69 if (
70 !/^\w[\w.-]*\/\w[\w.-]*$/.test(model.repository) ||
71 !/^[a-f0-9]{40}$/.test(model.revision) ||
72 !/^[a-f0-9]{64}$/.test(file.sha256) ||
73 !Number.isSafeInteger(file.size) ||
74 file.size <= 0 ||
75 model.languages.length === 0
76 )
77 throw new Error(`Invalid speech catalog metadata: ${model.id}`);
78 if (ids.has(model.repository) || filenames.has(file.filename)) {
79 throw new Error(`Duplicate speech catalog model or filename: ${model.id}`);
80 }
81 ids.add(model.repository);
82 filenames.add(file.filename);
83 const languages = [...new Set(model.languages.map(canonicalLanguage))];
84 const realtimeFactor = data.results[model.id]?.performance.accelerated;
85 const cpuFactor = data.results[model.id]?.performance.cpu;
86 const accuracy = Object.fromEntries(
87 languages.flatMap((language) => {
88 const cell = data.results[model.id]?.accuracy[languageIdentity(language)];
89 return cell
90 ? [
91 [
92 language,
93 { grade: accuracyGrade(cell.error).label, errorPercent: cell.error },
94 ] as const,
95 ]
96 : [];
97 }),
98 );
99 return [
100 {
101 id: model.repository,
102 revision: model.revision,
103 name: model.name,
104 description: model.description || `${model.name} speech-to-text.`,
105 filename: file.filename,
106 size: file.size,
107 sha256: file.sha256,
108 license: model.license,
109 // T3 selects base languages; the engine's prompt dictionary accepts their short aliases.
110 languages,
111 benchmark: {
112 accuracy,
113 secondsPer30s: {
114 cpu: cpuFactor ? BENCHMARK_DICTATION_SECONDS / cpuFactor : null,
115 accelerated: realtimeFactor ? BENCHMARK_DICTATION_SECONDS / realtimeFactor : null,
116 },
117 },
118 recommended: RECOMMENDED.has(model.id),
119 supportsStreaming: model.capabilities.streaming,
120 supportsLanguageDetection: model.capabilities.languageDetection,
121 supportsTranslation: model.capabilities.translate,
122 },
123 ];
124 });
125 return { source: "@handy-computer/models", sourceVersion, engineVersion, models };
126 }
127
128 export async function renderSpeechCatalog(
129 data: CatalogData,
130 sourceVersion: string,
131 engineVersion: string,
132 ) {
133 const result = await format(
134 "catalog.json",
135 JSON.stringify(generateSpeechCatalog(data, sourceVersion, engineVersion)),
136 );
137 if (result.errors.length > 0) throw new Error("Could not format speech catalog.");
138 return result.code;
139 }