Skip to content

Commit 42a25b6

Browse files
committed
feat: Add more models
1 parent 46efa87 commit 42a25b6

File tree

4 files changed

+39
-7
lines changed

4 files changed

+39
-7
lines changed

src/screens/editor/Editor.res

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,6 @@ let make = React.memo((
209209
<div className="flex justify-center w-full flex-1 min-h-0 overflow-hidden">
210210
{layout.mediaControls
211211
->Belt.Option.map(size => {
212-
Js.Console.log(size)
213212
let showSideBySide = size.width >= 770.0
214213

215214
<div

src/screens/editor/Editor.res.mjs

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/transcriber/Constants.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,14 @@ export const MODELS = {
2929
"onnx-community/whisper-tiny_timestamped": "Tiny (152 Mb)",
3030
"onnx-community/whisper-base_timestamped": "Base (291 Mb)",
3131
"onnx-community/whisper-small_timestamped": "Small (586 Mb)",
32+
"onnx-community/whisper-medium_timestamped": "Medium (769 Mb)",
33+
"onnx-community/whisper-large-v3-turbo_timestamped": "Turbo (561 Mb)",
3234
} as const;
3335

3436
export type Model = keyof typeof MODELS;
3537

3638
export const ALL_MODELS = Object.keys(MODELS) as Array<Model>;
37-
const DEFAULT_MODEL: Model = "onnx-community/whisper-base_timestamped";
39+
const DEFAULT_MODEL: Model = "onnx-community/whisper-large-v3-turbo_timestamped";
3840

3941
export const modelSerde: serde<Model> = {
4042
parse: function(input: string): Model {

src/transcriber/whisper-worker.js

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,45 @@ async function isWebGPUAvailable() {
1616
return !!adapter;
1717
}
1818

19+
function isMobileOrTablet() {
20+
if (typeof navigator === 'undefined') return false;
21+
const ua = navigator.userAgent || "";
22+
return /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(ua) ||
23+
(navigator.maxTouchPoints > 0 && /Macintosh/.test(ua));
24+
}
25+
1926
// Specify a custom location for models (defaults to '/models/').
2027
// env.localModelPath = "/models/";
2128
// env.allowRemoteModels = true;
2229

30+
// Large models that need aggressive quantization to fit in browser memory
31+
const LARGE_MODELS = [
32+
"onnx-community/whisper-large-v3-turbo",
33+
"onnx-community/whisper-large-v3-turbo_timestamped",
34+
"distil-whisper/distil-large-v3",
35+
];
36+
37+
function getDtypeConfig(modelName) {
38+
if (LARGE_MODELS.some(m => modelName.includes(m.replace("onnx-community/", "").replace("distil-whisper/", "")))) {
39+
return {
40+
encoder_model: "q4f16",
41+
decoder_model_merged: "q4f16",
42+
};
43+
}
44+
45+
if (isMobileOrTablet()) {
46+
return {
47+
encoder_model: "q4",
48+
decoder_model_merged: "q4",
49+
};
50+
}
51+
52+
return {
53+
encoder_model: "fp32",
54+
decoder_model_merged: "q4",
55+
};
56+
}
57+
2358
// Define model factories
2459
// Ensures only one model is created of each type
2560
class PipelineFactory {
@@ -39,10 +74,7 @@ class PipelineFactory {
3974
this.instance = pipeline(this.task, this.model, {
4075
quantized: this.quantized,
4176
progress_callback,
42-
dtype: {
43-
encoder_model: "fp32",
44-
decoder_model_merged: "q4", // or 'fp32' ('fp16' is broken)
45-
},
77+
dtype: getDtypeConfig(this.model),
4678
device: await isWebGPUAvailable() ? "webgpu" : "wasm",
4779
});
4880
}

0 commit comments

Comments
 (0)