@remotion/whisper-web 4.0.302 → 4.0.303
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.turbo/turbo-make.log +2 -2
- package/dist/can-use-whisper-web.js +9 -5
- package/dist/constants.js +9 -6
- package/dist/db/delete-object.js +7 -3
- package/dist/db/get-object-from-db.js +12 -6
- package/dist/db/open-db.js +12 -8
- package/dist/db/put-object.js +7 -3
- package/dist/delete-model.js +9 -5
- package/dist/download-model.js +5 -1
- package/dist/download-whisper-model.js +19 -15
- package/dist/esm/index.mjs +88 -69
- package/dist/get-loaded-models.js +13 -9
- package/dist/get-model-url.js +6 -2
- package/dist/index.d.ts +4 -1
- package/dist/index.js +19 -6
- package/dist/load-mod/load-mod.js +39 -2
- package/dist/log.js +12 -8
- package/dist/mod.js +2 -1
- package/dist/print-handler.js +7 -3
- package/dist/resample-to-16khz.js +16 -12
- package/dist/result.js +2 -1
- package/dist/simulate-progress.js +12 -8
- package/dist/to-captions.d.ts +10 -0
- package/dist/to-captions.js +21 -0
- package/dist/transcribe.js +25 -21
- package/dist/transcription-speed.js +9 -4
- package/package.json +5 -3
- package/src/index.module.ts +2 -0
- package/src/index.ts +10 -0
- package/src/to-captions.ts +33 -0
- package/tsconfig.json +3 -4
- package/tsconfig.tsbuildinfo +1 -1
package/.turbo/turbo-make.log
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
|
|
2
2
|
|
|
3
|
-
> @remotion/whisper-web@4.0.
|
|
3
|
+
> @remotion/whisper-web@4.0.303 make /Users/jonathanburger/remotion/packages/whisper-web
|
|
4
4
|
> tsc -d && bun --env-file=../.env.bundle bundle.ts
|
|
5
5
|
|
|
6
|
-
[0m[2m[[
|
|
6
|
+
[0m[2m[[1m7.53ms[0m[2m][0m Generated.
|
|
@@ -1,5 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.canUseWhisperWeb = exports.WhisperWebUnsupportedReason = void 0;
|
|
4
|
+
const constants_1 = require("./constants");
|
|
5
|
+
var WhisperWebUnsupportedReason;
|
|
3
6
|
(function (WhisperWebUnsupportedReason) {
|
|
4
7
|
WhisperWebUnsupportedReason["WindowUndefined"] = "window-undefined";
|
|
5
8
|
WhisperWebUnsupportedReason["IndexedDbUnavailable"] = "indexed-db-unavailable";
|
|
@@ -10,8 +13,8 @@ export var WhisperWebUnsupportedReason;
|
|
|
10
13
|
WhisperWebUnsupportedReason["NotEnoughSpace"] = "not-enough-space";
|
|
11
14
|
WhisperWebUnsupportedReason["ErrorEstimatingStorage"] = "error-estimating-storage";
|
|
12
15
|
WhisperWebUnsupportedReason["NotCrossOriginIsolated"] = "not-cross-origin-isolated";
|
|
13
|
-
})(WhisperWebUnsupportedReason || (WhisperWebUnsupportedReason = {}));
|
|
14
|
-
|
|
16
|
+
})(WhisperWebUnsupportedReason || (exports.WhisperWebUnsupportedReason = WhisperWebUnsupportedReason = {}));
|
|
17
|
+
const canUseWhisperWeb = async (model) => {
|
|
15
18
|
if (typeof window === 'undefined') {
|
|
16
19
|
return {
|
|
17
20
|
supported: false,
|
|
@@ -57,7 +60,7 @@ export const canUseWhisperWeb = async (model) => {
|
|
|
57
60
|
};
|
|
58
61
|
}
|
|
59
62
|
const remaining = estimate.quota - estimate.usage;
|
|
60
|
-
const modelSize = SIZES[model];
|
|
63
|
+
const modelSize = constants_1.SIZES[model];
|
|
61
64
|
if (remaining < modelSize) {
|
|
62
65
|
return {
|
|
63
66
|
supported: false,
|
|
@@ -78,3 +81,4 @@ export const canUseWhisperWeb = async (model) => {
|
|
|
78
81
|
supported: true,
|
|
79
82
|
};
|
|
80
83
|
};
|
|
84
|
+
exports.canUseWhisperWeb = canUseWhisperWeb;
|
package/dist/constants.js
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SIZES = exports.LANGUAGES = exports.MODELS = exports.DB_OBJECT_STORE_NAME = exports.DB_VERSION = exports.DB_NAME = void 0;
|
|
4
|
+
exports.DB_NAME = 'whisper-web';
|
|
5
|
+
exports.DB_VERSION = 1;
|
|
6
|
+
exports.DB_OBJECT_STORE_NAME = 'models';
|
|
7
|
+
exports.MODELS = [
|
|
5
8
|
'tiny',
|
|
6
9
|
'tiny.en',
|
|
7
10
|
'base',
|
|
@@ -9,7 +12,7 @@ export const MODELS = [
|
|
|
9
12
|
'small',
|
|
10
13
|
'small.en',
|
|
11
14
|
];
|
|
12
|
-
|
|
15
|
+
exports.LANGUAGES = [
|
|
13
16
|
// whisper allows passing 'auto' to auto-detect the language
|
|
14
17
|
'auto',
|
|
15
18
|
// short codes
|
|
@@ -215,7 +218,7 @@ export const LANGUAGES = [
|
|
|
215
218
|
'sundanese',
|
|
216
219
|
'cantonese',
|
|
217
220
|
];
|
|
218
|
-
|
|
221
|
+
exports.SIZES = {
|
|
219
222
|
tiny: 77691713,
|
|
220
223
|
'tiny.en': 77704715,
|
|
221
224
|
base: 147951465,
|
package/dist/db/delete-object.js
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.deleteObject = void 0;
|
|
4
|
+
const open_db_1 = require("./open-db");
|
|
5
|
+
const deleteObject = async ({ key }) => {
|
|
6
|
+
const objectStore = await (0, open_db_1.openDb)('readwrite');
|
|
4
7
|
return new Promise((resolve, reject) => {
|
|
5
8
|
const request = objectStore.delete(key);
|
|
6
9
|
request.onsuccess = () => {
|
|
@@ -11,3 +14,4 @@ export const deleteObject = async ({ key }) => {
|
|
|
11
14
|
};
|
|
12
15
|
});
|
|
13
16
|
};
|
|
17
|
+
exports.deleteObject = deleteObject;
|
|
@@ -1,5 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getObject = exports.getKeysFromObjectStore = exports.getObjectFromObjectStore = void 0;
|
|
4
|
+
const open_db_1 = require("./open-db");
|
|
5
|
+
const getObjectFromObjectStore = ({ objectStore, key, }) => {
|
|
3
6
|
return new Promise((resolve, reject) => {
|
|
4
7
|
const request = objectStore.get(key);
|
|
5
8
|
request.onsuccess = () => {
|
|
@@ -10,7 +13,8 @@ export const getObjectFromObjectStore = ({ objectStore, key, }) => {
|
|
|
10
13
|
};
|
|
11
14
|
});
|
|
12
15
|
};
|
|
13
|
-
|
|
16
|
+
exports.getObjectFromObjectStore = getObjectFromObjectStore;
|
|
17
|
+
const getKeysFromObjectStore = ({ objectStore, }) => {
|
|
14
18
|
return new Promise((resolve, reject) => {
|
|
15
19
|
const request = objectStore.getAllKeys();
|
|
16
20
|
request.onsuccess = () => {
|
|
@@ -21,7 +25,9 @@ export const getKeysFromObjectStore = ({ objectStore, }) => {
|
|
|
21
25
|
};
|
|
22
26
|
});
|
|
23
27
|
};
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
28
|
+
exports.getKeysFromObjectStore = getKeysFromObjectStore;
|
|
29
|
+
const getObject = async ({ key }) => {
|
|
30
|
+
const objectStore = await (0, open_db_1.openDb)('readonly');
|
|
31
|
+
return (0, exports.getObjectFromObjectStore)({ objectStore, key });
|
|
27
32
|
};
|
|
33
|
+
exports.getObject = getObject;
|
package/dist/db/open-db.js
CHANGED
|
@@ -1,19 +1,22 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.openDb = void 0;
|
|
4
|
+
const constants_1 = require("../constants");
|
|
5
|
+
const openDb = (transactionMode) => {
|
|
3
6
|
return new Promise((resolve, reject) => {
|
|
4
|
-
const rq = indexedDB.open(DB_NAME, DB_VERSION);
|
|
7
|
+
const rq = indexedDB.open(constants_1.DB_NAME, constants_1.DB_VERSION);
|
|
5
8
|
rq.onupgradeneeded = (event) => {
|
|
6
9
|
try {
|
|
7
10
|
const db = rq.result;
|
|
8
|
-
if (event.oldVersion < DB_VERSION) {
|
|
9
|
-
db.createObjectStore(DB_OBJECT_STORE_NAME, { autoIncrement: false });
|
|
11
|
+
if (event.oldVersion < constants_1.DB_VERSION) {
|
|
12
|
+
db.createObjectStore(constants_1.DB_OBJECT_STORE_NAME, { autoIncrement: false });
|
|
10
13
|
}
|
|
11
14
|
else {
|
|
12
15
|
const { transaction } = event.currentTarget;
|
|
13
16
|
if (!transaction) {
|
|
14
17
|
throw new Error('No transaction available during upgrade');
|
|
15
18
|
}
|
|
16
|
-
const objectStore = transaction.objectStore(DB_OBJECT_STORE_NAME);
|
|
19
|
+
const objectStore = transaction.objectStore(constants_1.DB_OBJECT_STORE_NAME);
|
|
17
20
|
if (!objectStore) {
|
|
18
21
|
throw new Error('Could not access object store during upgrade');
|
|
19
22
|
}
|
|
@@ -27,14 +30,14 @@ export const openDb = (transactionMode) => {
|
|
|
27
30
|
rq.onsuccess = () => {
|
|
28
31
|
try {
|
|
29
32
|
const db = rq.result;
|
|
30
|
-
const transaction = db.transaction([DB_OBJECT_STORE_NAME], transactionMode);
|
|
33
|
+
const transaction = db.transaction([constants_1.DB_OBJECT_STORE_NAME], transactionMode);
|
|
31
34
|
transaction.onerror = () => {
|
|
32
35
|
reject(new Error('Transaction failed'));
|
|
33
36
|
};
|
|
34
37
|
transaction.onabort = () => {
|
|
35
38
|
reject(new Error('Transaction aborted'));
|
|
36
39
|
};
|
|
37
|
-
const objectStore = transaction.objectStore(DB_OBJECT_STORE_NAME);
|
|
40
|
+
const objectStore = transaction.objectStore(constants_1.DB_OBJECT_STORE_NAME);
|
|
38
41
|
resolve(objectStore);
|
|
39
42
|
}
|
|
40
43
|
catch (err) {
|
|
@@ -51,3 +54,4 @@ export const openDb = (transactionMode) => {
|
|
|
51
54
|
};
|
|
52
55
|
});
|
|
53
56
|
};
|
|
57
|
+
exports.openDb = openDb;
|
package/dist/db/put-object.js
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.putObject = void 0;
|
|
4
|
+
const open_db_1 = require("./open-db");
|
|
5
|
+
const putObject = async ({ key, value, }) => {
|
|
6
|
+
const objectStore = await (0, open_db_1.openDb)('readwrite');
|
|
4
7
|
return new Promise((resolve, reject) => {
|
|
5
8
|
try {
|
|
6
9
|
const putRq = objectStore.put(value, key);
|
|
@@ -16,3 +19,4 @@ export const putObject = async ({ key, value, }) => {
|
|
|
16
19
|
}
|
|
17
20
|
});
|
|
18
21
|
};
|
|
22
|
+
exports.putObject = putObject;
|
package/dist/delete-model.js
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.deleteModel = void 0;
|
|
4
|
+
const delete_object_1 = require("./db/delete-object");
|
|
5
|
+
const get_model_url_1 = require("./get-model-url");
|
|
6
|
+
const deleteModel = async (model) => {
|
|
7
|
+
const url = (0, get_model_url_1.getModelUrl)(model);
|
|
8
|
+
await (0, delete_object_1.deleteObject)({ key: url });
|
|
6
9
|
};
|
|
10
|
+
exports.deleteModel = deleteModel;
|
package/dist/download-model.js
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.fetchRemote = void 0;
|
|
4
|
+
const fetchRemote = async ({ url, onProgress, expectedLength, }) => {
|
|
2
5
|
// start the fetch
|
|
3
6
|
const response = await fetch(url, { method: 'get' });
|
|
4
7
|
if (!response.ok || !response.body) {
|
|
@@ -30,3 +33,4 @@ export const fetchRemote = async ({ url, onProgress, expectedLength, }) => {
|
|
|
30
33
|
}
|
|
31
34
|
return chunksAll;
|
|
32
35
|
};
|
|
36
|
+
exports.fetchRemote = fetchRemote;
|
|
@@ -1,20 +1,23 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.downloadWhisperModel = void 0;
|
|
4
|
+
const can_use_whisper_web_1 = require("./can-use-whisper-web");
|
|
5
|
+
const constants_1 = require("./constants");
|
|
6
|
+
const get_object_from_db_1 = require("./db/get-object-from-db");
|
|
7
|
+
const put_object_1 = require("./db/put-object");
|
|
8
|
+
const download_model_1 = require("./download-model");
|
|
9
|
+
const get_model_url_1 = require("./get-model-url");
|
|
10
|
+
const downloadWhisperModel = async ({ model, onProgress, }) => {
|
|
11
|
+
if (!model || !constants_1.MODELS.includes(model)) {
|
|
12
|
+
throw new Error(`Invalid model name: ${model}. Supported models: ${constants_1.MODELS.join(', ')}.`);
|
|
10
13
|
}
|
|
11
|
-
const usabilityCheck = await canUseWhisperWeb(model);
|
|
14
|
+
const usabilityCheck = await (0, can_use_whisper_web_1.canUseWhisperWeb)(model);
|
|
12
15
|
if (!usabilityCheck.supported) {
|
|
13
16
|
return Promise.reject(new Error(`Whisper.wasm is not supported in this environment. Reason: ${usabilityCheck.detailedReason}`));
|
|
14
17
|
}
|
|
15
|
-
const url = getModelUrl(model);
|
|
16
|
-
const modelSize = SIZES[model];
|
|
17
|
-
const existingModel = await getObject({ key: url });
|
|
18
|
+
const url = (0, get_model_url_1.getModelUrl)(model);
|
|
19
|
+
const modelSize = constants_1.SIZES[model];
|
|
20
|
+
const existingModel = await (0, get_object_from_db_1.getObject)({ key: url });
|
|
18
21
|
if (existingModel) {
|
|
19
22
|
onProgress({
|
|
20
23
|
downloadedBytes: modelSize,
|
|
@@ -25,7 +28,7 @@ export const downloadWhisperModel = async ({ model, onProgress, }) => {
|
|
|
25
28
|
alreadyDownloaded: true,
|
|
26
29
|
};
|
|
27
30
|
}
|
|
28
|
-
const data = await fetchRemote({
|
|
31
|
+
const data = await (0, download_model_1.fetchRemote)({
|
|
29
32
|
url,
|
|
30
33
|
onProgress: (bytes) => {
|
|
31
34
|
onProgress({
|
|
@@ -41,8 +44,9 @@ export const downloadWhisperModel = async ({ model, onProgress, }) => {
|
|
|
41
44
|
totalBytes: modelSize,
|
|
42
45
|
progress: 1,
|
|
43
46
|
});
|
|
44
|
-
await putObject({ key: url, value: data });
|
|
47
|
+
await (0, put_object_1.putObject)({ key: url, value: data });
|
|
45
48
|
return {
|
|
46
49
|
alreadyDownloaded: false,
|
|
47
50
|
};
|
|
48
51
|
};
|
|
52
|
+
exports.downloadWhisperModel = downloadWhisperModel;
|
package/dist/esm/index.mjs
CHANGED
|
@@ -43,6 +43,73 @@ var SIZES = {
|
|
|
43
43
|
"small.en": 487614201
|
|
44
44
|
};
|
|
45
45
|
|
|
46
|
+
// src/can-use-whisper-web.ts
|
|
47
|
+
var canUseWhisperWeb = async (model) => {
|
|
48
|
+
if (typeof window === "undefined") {
|
|
49
|
+
return {
|
|
50
|
+
supported: false,
|
|
51
|
+
reason: "window-undefined" /* WindowUndefined */,
|
|
52
|
+
detailedReason: "`window` is not defined. This module can only be used in a browser environment."
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
if (!window.crossOriginIsolated) {
|
|
56
|
+
return {
|
|
57
|
+
supported: false,
|
|
58
|
+
reason: "not-cross-origin-isolated" /* NotCrossOriginIsolated */,
|
|
59
|
+
detailedReason: "The document is not cross-origin isolated (window.crossOriginIsolated = false). This prevents the usage of SharedArrayBuffer, which is required by `@remotion/whisper-web`. Make sure the document is served with the HTTP header `Cross-Origin-Opener-Policy: same-origin` and `Cross-Origin-Embedder-Policy: require-corp`: https://developer.mozilla.org/en-US/docs/Web/API/Window/crossOriginIsolated"
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
if (!window.indexedDB) {
|
|
63
|
+
return {
|
|
64
|
+
supported: false,
|
|
65
|
+
reason: "indexed-db-unavailable" /* IndexedDbUnavailable */,
|
|
66
|
+
detailedReason: "IndexedDB is not available in this environment."
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
if (!navigator?.storage || !navigator?.storage.estimate) {
|
|
70
|
+
return {
|
|
71
|
+
supported: false,
|
|
72
|
+
reason: "navigator-storage-unavailable" /* NavigatorStorageUnavailable */,
|
|
73
|
+
detailedReason: "`navigator.storage.estimate()` API is not available in this environment."
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
try {
|
|
77
|
+
const estimate = await navigator.storage.estimate();
|
|
78
|
+
if (estimate.quota === undefined) {
|
|
79
|
+
return {
|
|
80
|
+
supported: false,
|
|
81
|
+
reason: "quota-undefined" /* QuotaUndefined */,
|
|
82
|
+
detailedReason: "navigator.storage.estimate() API returned undefined quota."
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
if (estimate.usage === undefined) {
|
|
86
|
+
return {
|
|
87
|
+
supported: false,
|
|
88
|
+
reason: "usage-undefined" /* UsageUndefined */,
|
|
89
|
+
detailedReason: "navigator.storage.estimate() API returned undefined usage."
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
const remaining = estimate.quota - estimate.usage;
|
|
93
|
+
const modelSize = SIZES[model];
|
|
94
|
+
if (remaining < modelSize) {
|
|
95
|
+
return {
|
|
96
|
+
supported: false,
|
|
97
|
+
reason: "not-enough-space" /* NotEnoughSpace */,
|
|
98
|
+
detailedReason: `Not enough space to download the model. Required: ${modelSize} bytes, Available: ${remaining} bytes.`
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
} catch (error) {
|
|
102
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
103
|
+
return {
|
|
104
|
+
supported: false,
|
|
105
|
+
reason: "error-estimating-storage" /* ErrorEstimatingStorage */,
|
|
106
|
+
detailedReason: `Error estimating storage: ${errorMessage}`
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
return {
|
|
110
|
+
supported: true
|
|
111
|
+
};
|
|
112
|
+
};
|
|
46
113
|
// src/db/open-db.ts
|
|
47
114
|
var openDb = (transactionMode) => {
|
|
48
115
|
return new Promise((resolve, reject) => {
|
|
@@ -117,74 +184,6 @@ var deleteModel = async (model) => {
|
|
|
117
184
|
const url = getModelUrl(model);
|
|
118
185
|
await deleteObject({ key: url });
|
|
119
186
|
};
|
|
120
|
-
// src/can-use-whisper-web.ts
|
|
121
|
-
var canUseWhisperWeb = async (model) => {
|
|
122
|
-
if (typeof window === "undefined") {
|
|
123
|
-
return {
|
|
124
|
-
supported: false,
|
|
125
|
-
reason: "window-undefined" /* WindowUndefined */,
|
|
126
|
-
detailedReason: "`window` is not defined. This module can only be used in a browser environment."
|
|
127
|
-
};
|
|
128
|
-
}
|
|
129
|
-
if (!window.crossOriginIsolated) {
|
|
130
|
-
return {
|
|
131
|
-
supported: false,
|
|
132
|
-
reason: "not-cross-origin-isolated" /* NotCrossOriginIsolated */,
|
|
133
|
-
detailedReason: "The document is not cross-origin isolated (window.crossOriginIsolated = false). This prevents the usage of SharedArrayBuffer, which is required by `@remotion/whisper-web`. Make sure the document is served with the HTTP header `Cross-Origin-Opener-Policy: same-origin` and `Cross-Origin-Embedder-Policy: require-corp`: https://developer.mozilla.org/en-US/docs/Web/API/Window/crossOriginIsolated"
|
|
134
|
-
};
|
|
135
|
-
}
|
|
136
|
-
if (!window.indexedDB) {
|
|
137
|
-
return {
|
|
138
|
-
supported: false,
|
|
139
|
-
reason: "indexed-db-unavailable" /* IndexedDbUnavailable */,
|
|
140
|
-
detailedReason: "IndexedDB is not available in this environment."
|
|
141
|
-
};
|
|
142
|
-
}
|
|
143
|
-
if (!navigator?.storage || !navigator?.storage.estimate) {
|
|
144
|
-
return {
|
|
145
|
-
supported: false,
|
|
146
|
-
reason: "navigator-storage-unavailable" /* NavigatorStorageUnavailable */,
|
|
147
|
-
detailedReason: "`navigator.storage.estimate()` API is not available in this environment."
|
|
148
|
-
};
|
|
149
|
-
}
|
|
150
|
-
try {
|
|
151
|
-
const estimate = await navigator.storage.estimate();
|
|
152
|
-
if (estimate.quota === undefined) {
|
|
153
|
-
return {
|
|
154
|
-
supported: false,
|
|
155
|
-
reason: "quota-undefined" /* QuotaUndefined */,
|
|
156
|
-
detailedReason: "navigator.storage.estimate() API returned undefined quota."
|
|
157
|
-
};
|
|
158
|
-
}
|
|
159
|
-
if (estimate.usage === undefined) {
|
|
160
|
-
return {
|
|
161
|
-
supported: false,
|
|
162
|
-
reason: "usage-undefined" /* UsageUndefined */,
|
|
163
|
-
detailedReason: "navigator.storage.estimate() API returned undefined usage."
|
|
164
|
-
};
|
|
165
|
-
}
|
|
166
|
-
const remaining = estimate.quota - estimate.usage;
|
|
167
|
-
const modelSize = SIZES[model];
|
|
168
|
-
if (remaining < modelSize) {
|
|
169
|
-
return {
|
|
170
|
-
supported: false,
|
|
171
|
-
reason: "not-enough-space" /* NotEnoughSpace */,
|
|
172
|
-
detailedReason: `Not enough space to download the model. Required: ${modelSize} bytes, Available: ${remaining} bytes.`
|
|
173
|
-
};
|
|
174
|
-
}
|
|
175
|
-
} catch (error) {
|
|
176
|
-
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
177
|
-
return {
|
|
178
|
-
supported: false,
|
|
179
|
-
reason: "error-estimating-storage" /* ErrorEstimatingStorage */,
|
|
180
|
-
detailedReason: `Error estimating storage: ${errorMessage}`
|
|
181
|
-
};
|
|
182
|
-
}
|
|
183
|
-
return {
|
|
184
|
-
supported: true
|
|
185
|
-
};
|
|
186
|
-
};
|
|
187
|
-
|
|
188
187
|
// src/db/get-object-from-db.ts
|
|
189
188
|
var getObjectFromObjectStore = ({
|
|
190
189
|
objectStore,
|
|
@@ -437,6 +436,24 @@ var resampleTo16Khz = async ({
|
|
|
437
436
|
reader.readAsArrayBuffer(file);
|
|
438
437
|
});
|
|
439
438
|
};
|
|
439
|
+
// src/to-captions.ts
|
|
440
|
+
var toCaptions = (input) => {
|
|
441
|
+
const { transcription } = input.whisperWebOutput;
|
|
442
|
+
const captions = [];
|
|
443
|
+
for (const item of transcription) {
|
|
444
|
+
if (item.text === "") {
|
|
445
|
+
continue;
|
|
446
|
+
}
|
|
447
|
+
captions.push({
|
|
448
|
+
text: captions.length === 0 ? item.text.trimStart() : item.text,
|
|
449
|
+
startMs: item.offsets.from,
|
|
450
|
+
endMs: item.offsets.to,
|
|
451
|
+
timestampMs: item.tokens[0].t_dtw === -1 ? null : item.tokens[0].t_dtw * 10,
|
|
452
|
+
confidence: item.tokens[0].p
|
|
453
|
+
});
|
|
454
|
+
}
|
|
455
|
+
return { captions };
|
|
456
|
+
};
|
|
440
457
|
// src/load-mod/load-mod.ts
|
|
441
458
|
var loadMod = async () => {
|
|
442
459
|
const Mod = await import("../../main.js");
|
|
@@ -645,8 +662,10 @@ var transcribe = async ({
|
|
|
645
662
|
};
|
|
646
663
|
export {
|
|
647
664
|
transcribe,
|
|
665
|
+
toCaptions,
|
|
648
666
|
resampleTo16Khz,
|
|
649
667
|
getLoadedModels,
|
|
650
668
|
downloadWhisperModel,
|
|
651
|
-
deleteModel
|
|
669
|
+
deleteModel,
|
|
670
|
+
canUseWhisperWeb
|
|
652
671
|
};
|
|
@@ -1,17 +1,21 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getLoadedModels = void 0;
|
|
4
|
+
const constants_1 = require("./constants");
|
|
5
|
+
const get_object_from_db_1 = require("./db/get-object-from-db");
|
|
6
|
+
const open_db_1 = require("./db/open-db");
|
|
7
|
+
const get_model_url_1 = require("./get-model-url");
|
|
8
|
+
const getLoadedModels = async () => {
|
|
9
|
+
const objectStore = await (0, open_db_1.openDb)('readonly');
|
|
7
10
|
const loadedModels = [];
|
|
8
|
-
const result = await getKeysFromObjectStore({
|
|
11
|
+
const result = await (0, get_object_from_db_1.getKeysFromObjectStore)({
|
|
9
12
|
objectStore,
|
|
10
13
|
});
|
|
11
|
-
for (const model of MODELS) {
|
|
12
|
-
if (result.includes(getModelUrl(model))) {
|
|
14
|
+
for (const model of constants_1.MODELS) {
|
|
15
|
+
if (result.includes((0, get_model_url_1.getModelUrl)(model))) {
|
|
13
16
|
loadedModels.push(model);
|
|
14
17
|
}
|
|
15
18
|
}
|
|
16
19
|
return loadedModels;
|
|
17
20
|
};
|
|
21
|
+
exports.getLoadedModels = getLoadedModels;
|
package/dist/get-model-url.js
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.sizes = exports.getModelUrl = void 0;
|
|
4
|
+
const getModelUrl = (model) => {
|
|
2
5
|
return `https://huggingface.co/ggerganov/whisper.cpp/resolve/main/ggml-${model}.bin`;
|
|
3
6
|
};
|
|
4
|
-
|
|
7
|
+
exports.getModelUrl = getModelUrl;
|
|
8
|
+
exports.sizes = {
|
|
5
9
|
tiny: 74000000,
|
|
6
10
|
base: 244000000,
|
|
7
11
|
small: 769000000,
|
package/dist/index.d.ts
CHANGED
|
@@ -4,6 +4,8 @@ import type { deleteModel as originalDeleteModel } from './delete-model';
|
|
|
4
4
|
import type { DownloadWhisperModelOnProgress, DownloadWhisperModelParams, DownloadWhisperModelProgress, DownloadWhisperModelResult, downloadWhisperModel as originalDownloadWhisperModel } from './download-whisper-model';
|
|
5
5
|
import type { getLoadedModels as originalGetLoadedModels } from './get-loaded-models';
|
|
6
6
|
import type { resampleTo16Khz as originalResampleTo16Khz, ResampleTo16KhzParams } from './resample-to-16khz';
|
|
7
|
+
import type { TranscriptionItemWithTimestamp, TranscriptionJson } from './result';
|
|
8
|
+
import type { toCaptions as originalToCaptions } from './to-captions';
|
|
7
9
|
import type { transcribe as originalTranscribe, TranscribeParams } from './transcribe';
|
|
8
10
|
export declare const transcribe: typeof originalTranscribe;
|
|
9
11
|
export declare const downloadWhisperModel: typeof originalDownloadWhisperModel;
|
|
@@ -11,4 +13,5 @@ export declare const getLoadedModels: typeof originalGetLoadedModels;
|
|
|
11
13
|
export declare const deleteModel: typeof originalDeleteModel;
|
|
12
14
|
export declare const canUseWhisperWeb: typeof originalCanUseWhisperWeb;
|
|
13
15
|
export declare const resampleTo16Khz: typeof originalResampleTo16Khz;
|
|
14
|
-
export
|
|
16
|
+
export declare const toCaptions: typeof originalToCaptions;
|
|
17
|
+
export type { CanUseWhisperWebResult, DownloadWhisperModelOnProgress, DownloadWhisperModelParams, DownloadWhisperModelProgress, DownloadWhisperModelResult, ResampleTo16KhzParams, TranscribeParams, TranscriptionItemWithTimestamp, TranscriptionJson, WhisperWebLanguage, WhisperWebModel, WhisperWebUnsupportedReason, };
|
package/dist/index.js
CHANGED
|
@@ -1,18 +1,31 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.toCaptions = exports.resampleTo16Khz = exports.canUseWhisperWeb = exports.deleteModel = exports.getLoadedModels = exports.downloadWhisperModel = exports.transcribe = void 0;
|
|
4
|
+
const transcribe = () => {
|
|
2
5
|
throw new Error('Loading this module from CommonJS is not supported. Load the ESM version of @remotion/whisper-web.');
|
|
3
6
|
};
|
|
4
|
-
|
|
7
|
+
exports.transcribe = transcribe;
|
|
8
|
+
const downloadWhisperModel = () => {
|
|
5
9
|
throw new Error('Loading this module from CommonJS is not supported. Load the ESM version of @remotion/whisper-web.');
|
|
6
10
|
};
|
|
7
|
-
|
|
11
|
+
exports.downloadWhisperModel = downloadWhisperModel;
|
|
12
|
+
const getLoadedModels = () => {
|
|
8
13
|
throw new Error('Loading this module from CommonJS is not supported. Load the ESM version of @remotion/whisper-web.');
|
|
9
14
|
};
|
|
10
|
-
|
|
15
|
+
exports.getLoadedModels = getLoadedModels;
|
|
16
|
+
const deleteModel = () => {
|
|
11
17
|
throw new Error('Loading this module from CommonJS is not supported. Load the ESM version of @remotion/whisper-web.');
|
|
12
18
|
};
|
|
13
|
-
|
|
19
|
+
exports.deleteModel = deleteModel;
|
|
20
|
+
const canUseWhisperWeb = () => {
|
|
14
21
|
throw new Error('Loading this module from CommonJS is not supported. Load the ESM version of @remotion/whisper-web.');
|
|
15
22
|
};
|
|
16
|
-
|
|
23
|
+
exports.canUseWhisperWeb = canUseWhisperWeb;
|
|
24
|
+
const resampleTo16Khz = () => {
|
|
17
25
|
throw new Error('Loading this module from CommonJS is not supported. Load the ESM version of @remotion/whisper-web.');
|
|
18
26
|
};
|
|
27
|
+
exports.resampleTo16Khz = resampleTo16Khz;
|
|
28
|
+
const toCaptions = () => {
|
|
29
|
+
throw new Error('Loading this module from CommonJS is not supported. Load the ESM version of @remotion/whisper-web.');
|
|
30
|
+
};
|
|
31
|
+
exports.toCaptions = toCaptions;
|
|
@@ -1,6 +1,43 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.loadMod = void 0;
|
|
37
|
+
const loadMod = async () => {
|
|
2
38
|
// According to MDN, this is allowed:
|
|
3
39
|
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/import#module_namespace_object
|
|
4
|
-
const Mod = await
|
|
40
|
+
const Mod = await Promise.resolve().then(() => __importStar(require('../../main.js')));
|
|
5
41
|
return Mod.default;
|
|
6
42
|
};
|
|
43
|
+
exports.loadMod = loadMod;
|