Open History to see the last commit
1import type { EnvironmentSpeechModel } from "@t3tools/contracts";
2import { expect, it } from "vite-plus/test";
3
4import { filterSpeechModels } from "./speechModelBrowser";
5
6const model: EnvironmentSpeechModel = {
7 id: "active",
8 name: "Active",
9 description: "Local transcription",
10 size: 300,
11 languages: ["en", "fr"],
12 accuracy: 1,
13 speed: 1,
14 recommended: false,
15 supportsStreaming: false,
16 supportsLanguageDetection: false,
17 supportsTranslation: false,
18 active: true,
19 state: "installed",
20};
21const models: readonly EnvironmentSpeechModel[] = [
22 model,
23 {
24 ...model,
25 id: "small",
26 name: "Small",
27 size: 100,
28 active: false,
29 state: "downloadable",
30 recommended: true,
31 benchmark: {
32 accuracy: {
33 en: { grade: "A", errorPercent: 3.8 },
34 fr: { grade: "B", errorPercent: 8 },
35 },
36 secondsPer30s: 2,
37 },
38 },
39 {
40 ...model,
41 id: "fast",
42 name: "Fast",
43 size: 200,
44 active: false,
45 benchmark: {
46 accuracy: {
47 en: { grade: "A", errorPercent: 3.2 },
48 fr: { grade: "B", errorPercent: 9 },
49 },
50 secondsPer30s: 1,
51 },
52 },
53 {
54 ...model,
55 id: "pending",
56 name: "Pending",
57 size: 400,
58 active: false,
59 state: "verifying",
60 languages: ["en"],
61 benchmark: { accuracy: {}, secondsPer30s: null },
62 },
63];
64
65it.each([
66 ["recommended", "en", ["active", "fast", "pending", "small"]],
67 ["size", "en", ["small", "fast", "active", "pending"]],
68 ["speed", "en", ["fast", "small", "active", "pending"]],
69 ["accuracy", "en", ["fast", "small", "active", "pending"]],
70 ["accuracy", "fr", ["small", "fast", "active", "pending"]],
71] as const)(
72 "sorts by %s for %s with missing benchmarks last",
73 (sort, accuracyLanguage, expected) => {
74 expect(
75 filterSpeechModels(models, {
76 search: "",
77 languages: [],
78 downloadedOnly: false,
79 sort,
80 accuracyLanguage,
81 }).map((entry) => entry.id),
82 ).toEqual(expected);
83 expect(models[0]?.id).toBe("active");
84 },
85);
86
87it("combines text, all selected languages, and completed downloads without retaining the active model", () => {
88 const options = {
89 search: " LOCAL ",
90 languages: ["en", "fr"],
91 downloadedOnly: true,
92 sort: "size",
93 accuracyLanguage: "en",
94 } as const;
95 expect(filterSpeechModels(models, options).map((entry) => entry.id)).toEqual(["fast", "active"]);
96 expect(
97 filterSpeechModels(models, { ...options, search: "fast" }).map((entry) => entry.id),
98 ).toEqual(["fast"]);
99 expect(filterSpeechModels(models, { ...options, search: "small" })).toEqual([]);
100});