@remotion/whisper-web 4.0.302
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 +6 -0
- package/LICENSE.md +49 -0
- package/README.md +18 -0
- package/build-wasm.ts +117 -0
- package/bundle.ts +15 -0
- package/dist/can-use-whisper-web.d.ts +18 -0
- package/dist/can-use-whisper-web.js +80 -0
- package/dist/constants.d.ts +10 -0
- package/dist/constants.js +225 -0
- package/dist/db/delete-object.d.ts +3 -0
- package/dist/db/delete-object.js +13 -0
- package/dist/db/get-object-from-db.d.ts +10 -0
- package/dist/db/get-object-from-db.js +27 -0
- package/dist/db/open-db.d.ts +1 -0
- package/dist/db/open-db.js +53 -0
- package/dist/db/put-object.d.ts +4 -0
- package/dist/db/put-object.js +18 -0
- package/dist/delete-model.d.ts +2 -0
- package/dist/delete-model.js +6 -0
- package/dist/download-model.d.ts +5 -0
- package/dist/download-model.js +32 -0
- package/dist/download-whisper-model.d.ts +15 -0
- package/dist/download-whisper-model.js +48 -0
- package/dist/esm/index.mjs +652 -0
- package/dist/get-loaded-models.d.ts +2 -0
- package/dist/get-loaded-models.js +17 -0
- package/dist/get-model-url.d.ts +9 -0
- package/dist/get-model-url.js +10 -0
- package/dist/index.d.ts +14 -0
- package/dist/index.js +18 -0
- package/dist/load-mod/load-mod.d.ts +2 -0
- package/dist/load-mod/load-mod.js +6 -0
- package/dist/log.d.ts +10 -0
- package/dist/log.js +33 -0
- package/dist/mod.d.ts +6 -0
- package/dist/mod.js +1 -0
- package/dist/print-handler.d.ts +9 -0
- package/dist/print-handler.js +25 -0
- package/dist/resample-to-16khz.d.ts +8 -0
- package/dist/resample-to-16khz.js +66 -0
- package/dist/result.d.ts +53 -0
- package/dist/result.js +1 -0
- package/dist/simulate-progress.d.ts +9 -0
- package/dist/simulate-progress.js +53 -0
- package/dist/transcribe.d.ts +18 -0
- package/dist/transcribe.js +97 -0
- package/dist/transcription-speed.d.ts +3 -0
- package/dist/transcription-speed.js +13 -0
- package/emscripten.cpp +303 -0
- package/eslint.config.mjs +5 -0
- package/main.d.ts +46 -0
- package/main.js +3 -0
- package/package.json +52 -0
- package/src/can-use-whisper-web.ts +103 -0
- package/src/constants.ts +232 -0
- package/src/db/delete-object.ts +16 -0
- package/src/db/get-object-from-db.ts +43 -0
- package/src/db/open-db.ts +62 -0
- package/src/db/put-object.ts +27 -0
- package/src/delete-model.ts +8 -0
- package/src/download-model.ts +52 -0
- package/src/download-whisper-model.ts +86 -0
- package/src/get-loaded-models.ts +22 -0
- package/src/get-model-url.ts +13 -0
- package/src/index.module.ts +9 -0
- package/src/index.ts +72 -0
- package/src/load-mod/load-mod.ts +11 -0
- package/src/log.ts +41 -0
- package/src/mod.ts +13 -0
- package/src/print-handler.ts +39 -0
- package/src/resample-to-16khz.ts +105 -0
- package/src/result.ts +59 -0
- package/src/simulate-progress.ts +74 -0
- package/src/transcribe.ts +184 -0
- package/src/transcription-speed.ts +21 -0
- package/tsconfig.json +11 -0
- package/tsconfig.tsbuildinfo +1 -0
- package/worker.js +3 -0
package/LICENSE.md
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
# Remotion License
|
|
2
|
+
|
|
3
|
+
In Remotion 5.0, the license will slightly change. [View the changes here](https://github.com/remotion-dev/remotion/pull/3750).
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
Depending on the type of your legal entity, you are granted permission to use Remotion for your project. Individuals and small companies are allowed to use Remotion to create videos for free (even commercial), while a company license is required for for-profit organizations of a certain size. This two-tier system was designed to ensure funding for this project while still allowing the source code to be available and the program to be free for most. Read below for the exact terms of use.
|
|
8
|
+
|
|
9
|
+
- [Free license](#free-license)
|
|
10
|
+
- [Company license](#company-license)
|
|
11
|
+
|
|
12
|
+
## Free license
|
|
13
|
+
|
|
14
|
+
Copyright © 2025 [Remotion](https://www.remotion.dev)
|
|
15
|
+
|
|
16
|
+
### Eligibility
|
|
17
|
+
|
|
18
|
+
You are eligible to use Remotion for free if you are:
|
|
19
|
+
|
|
20
|
+
- an individual
|
|
21
|
+
- a for-profit organization with up to 3 employees
|
|
22
|
+
- a non-profit or not-for-profit organization
|
|
23
|
+
- evaluating whether Remotion is a good fit, and are not yet using it in a commercial way
|
|
24
|
+
|
|
25
|
+
### Allowed use cases
|
|
26
|
+
|
|
27
|
+
Permission is hereby granted, free of charge, to any person eligible for the "Free license", to use the software non-commercially or commercially for the purpose of creating videos and images and to modify the software to their own liking, for the purpose of fulfilling their custom use case or to contribute bug fixes or improvements back to Remotion.
|
|
28
|
+
|
|
29
|
+
### Disallowed use cases
|
|
30
|
+
|
|
31
|
+
It is not allowed to copy or modify Remotion code for the purpose of selling, renting, licensing, relicensing, or sublicensing your own derivate of Remotion.
|
|
32
|
+
|
|
33
|
+
### Warranty notice
|
|
34
|
+
|
|
35
|
+
The software is provided "as is", without warranty of any kind, express or implied, including but not limited to the warranties of merchantability, fitness for a particular purpose, and non-infringement. In no event shall the author or copyright holders be liable for any claim, damages or other liability, whether in an action of contract, tort or otherwise, arising from, out of or in connection with the software or the use or other dealings in the software.
|
|
36
|
+
|
|
37
|
+
### Support
|
|
38
|
+
|
|
39
|
+
Support is provided on a best-we-can-do basis via GitHub Issues and Discord.
|
|
40
|
+
|
|
41
|
+
## Company license
|
|
42
|
+
|
|
43
|
+
You are required to obtain a company license to use Remotion if you are not within the group of entities eligible for a free license. This license will enable you to use Remotion for the allowed use cases specified in the free license, and give you access to prioritized support (read the [Support Policy](https://www.remotion.dev/docs/support)).
|
|
44
|
+
|
|
45
|
+
Visit [remotion.pro](https://www.remotion.pro/license) for pricing and to buy a license.
|
|
46
|
+
|
|
47
|
+
### FAQs
|
|
48
|
+
|
|
49
|
+
Are you not sure whether you need a company license because of an edge case? Here are some [frequently asked questions](https://www.remotion.pro/faq).
|
package/README.md
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# @remotion/whisper-web
|
|
2
|
+
|
|
3
|
+
Helpers for using Whisper.cpp in browser using WASM
|
|
4
|
+
|
|
5
|
+
[](https://npmcharts.com/compare/@remotion/whisper-web?minimal=true)
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install @remotion/whisper-web --save-exact
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
When installing a Remotion package, make sure to align the version of all `remotion` and `@remotion/*` packages to the same version.
|
|
14
|
+
Remove the `^` character from the version number to use the exact version.
|
|
15
|
+
|
|
16
|
+
## Usage
|
|
17
|
+
|
|
18
|
+
See the [documentation](https://www.remotion.dev/docs/whisper-web) for more information.
|
package/build-wasm.ts
ADDED
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import {$} from 'bun';
|
|
2
|
+
import fs from 'fs';
|
|
3
|
+
import os from 'os';
|
|
4
|
+
import path from 'path';
|
|
5
|
+
|
|
6
|
+
const randomDir = os.tmpdir();
|
|
7
|
+
|
|
8
|
+
const wasmDir = path.join(randomDir, 'whisper-web');
|
|
9
|
+
|
|
10
|
+
if (fs.existsSync(wasmDir)) {
|
|
11
|
+
fs.rmSync(wasmDir, {recursive: true});
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
fs.mkdirSync(wasmDir, {recursive: true});
|
|
15
|
+
|
|
16
|
+
const cwd = path.join(wasmDir, 'build-em');
|
|
17
|
+
|
|
18
|
+
await $`git clone https://github.com/ggerganov/whisper.cpp ${wasmDir}`;
|
|
19
|
+
await $`git checkout v1.7.4`.cwd(wasmDir);
|
|
20
|
+
|
|
21
|
+
fs.mkdirSync(cwd);
|
|
22
|
+
|
|
23
|
+
const cmakeListsFile = path.join(
|
|
24
|
+
wasmDir,
|
|
25
|
+
'examples',
|
|
26
|
+
'whisper.wasm',
|
|
27
|
+
'CMakeLists.txt',
|
|
28
|
+
);
|
|
29
|
+
|
|
30
|
+
const file = fs.readFileSync(cmakeListsFile, 'utf8');
|
|
31
|
+
|
|
32
|
+
// Disable Node.JS target, compile with assertions to get stack trace
|
|
33
|
+
const lines = file.split('\n').map((line) => {
|
|
34
|
+
if (line.includes('-s FORCE_FILESYSTEM=1 \\')) {
|
|
35
|
+
return `-s FORCE_FILESYSTEM=1 -s ENVIRONMENT='web,worker' -s ASSERTIONS=1 \\`;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
return line;
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
fs.writeFileSync(
|
|
42
|
+
cmakeListsFile,
|
|
43
|
+
[
|
|
44
|
+
...lines,
|
|
45
|
+
// Generate a .d.ts file
|
|
46
|
+
`set(CMAKE_CXX_FLAGS "$\{CMAKE_CXX_FLAGS\} -lembind --emit-tsd $\{CMAKE_CURRENT_BINARY_DIR\}/interface.d.ts")`,
|
|
47
|
+
].join('\n'),
|
|
48
|
+
);
|
|
49
|
+
|
|
50
|
+
const emscriptenFilePath = path.join(
|
|
51
|
+
wasmDir,
|
|
52
|
+
'examples',
|
|
53
|
+
'whisper.wasm',
|
|
54
|
+
'emscripten.cpp',
|
|
55
|
+
);
|
|
56
|
+
//now get our version
|
|
57
|
+
const modifiedVersion = fs.readFileSync('./emscripten.cpp', 'utf8');
|
|
58
|
+
fs.writeFileSync(emscriptenFilePath, modifiedVersion);
|
|
59
|
+
|
|
60
|
+
// brew install emscripten if necessary
|
|
61
|
+
await $`emcmake cmake ..`.cwd(cwd);
|
|
62
|
+
await $`make -j`.cwd(cwd);
|
|
63
|
+
|
|
64
|
+
const mainJsFile = path.join(cwd, 'bin', 'whisper.wasm', 'main.js');
|
|
65
|
+
|
|
66
|
+
let content = fs.readFileSync(mainJsFile, 'utf8');
|
|
67
|
+
|
|
68
|
+
// pass our handlers
|
|
69
|
+
content = content.replace(
|
|
70
|
+
'var moduleOverrides=Object.assign({},Module);',
|
|
71
|
+
'var moduleOverrides=Object.assign({},Module);if (typeof window !== "undefined") {Object.assign(Module, window.remotion_wasm_moduleOverrides);};',
|
|
72
|
+
);
|
|
73
|
+
|
|
74
|
+
// assert changes have been made
|
|
75
|
+
if (!content.includes('window.remotion_wasm_moduleOverrides')) {
|
|
76
|
+
throw new Error('Changes have not been made');
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
// Modify the Worker path
|
|
80
|
+
const mainContent =
|
|
81
|
+
content.replace(
|
|
82
|
+
'new Worker(pthreadMainJs',
|
|
83
|
+
`new Worker(new URL('./worker.js', import.meta.url)`,
|
|
84
|
+
) +
|
|
85
|
+
'\n' +
|
|
86
|
+
'export default Module;' +
|
|
87
|
+
'\n';
|
|
88
|
+
|
|
89
|
+
// assert changes have been made
|
|
90
|
+
if (!mainContent.includes('new Worker(new URL(')) {
|
|
91
|
+
throw new Error('Changes have not been made');
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
const workerContent =
|
|
95
|
+
content.replace(
|
|
96
|
+
'worker=new Worker(pthreadMainJs)',
|
|
97
|
+
`throw new Error('Already is in worker')`,
|
|
98
|
+
) +
|
|
99
|
+
'\n' +
|
|
100
|
+
'export default Module;' +
|
|
101
|
+
'\n';
|
|
102
|
+
|
|
103
|
+
// Write the modified content directly to the destination
|
|
104
|
+
fs.writeFileSync(path.join(__dirname, 'main.js'), mainContent, 'utf8');
|
|
105
|
+
fs.writeFileSync(path.join(__dirname, 'worker.js'), workerContent, 'utf8');
|
|
106
|
+
|
|
107
|
+
const dTsFile = path.join(
|
|
108
|
+
wasmDir,
|
|
109
|
+
'build-em',
|
|
110
|
+
'examples',
|
|
111
|
+
'whisper.wasm',
|
|
112
|
+
'interface.d.ts',
|
|
113
|
+
);
|
|
114
|
+
|
|
115
|
+
fs.copyFileSync(dTsFile, path.join(__dirname, 'main.d.ts'));
|
|
116
|
+
|
|
117
|
+
fs.rmSync(wasmDir, {recursive: true});
|
package/bundle.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import {buildPackage} from '../.monorepo/builder';
|
|
2
|
+
|
|
3
|
+
await buildPackage({
|
|
4
|
+
formats: {
|
|
5
|
+
cjs: 'use-tsc',
|
|
6
|
+
esm: 'build',
|
|
7
|
+
},
|
|
8
|
+
external: ['./main.js', './worker.js'],
|
|
9
|
+
entrypoints: [
|
|
10
|
+
{
|
|
11
|
+
path: 'src/index.module.ts',
|
|
12
|
+
target: 'browser',
|
|
13
|
+
},
|
|
14
|
+
],
|
|
15
|
+
});
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { WhisperWebModel } from './constants';
|
|
2
|
+
export declare enum WhisperWebUnsupportedReason {
|
|
3
|
+
WindowUndefined = "window-undefined",
|
|
4
|
+
IndexedDbUnavailable = "indexed-db-unavailable",
|
|
5
|
+
NavigatorStorageUnavailable = "navigator-storage-unavailable",
|
|
6
|
+
StorageEstimationApiUnavailable = "storage-estimation-api-unavailable",
|
|
7
|
+
QuotaUndefined = "quota-undefined",
|
|
8
|
+
UsageUndefined = "usage-undefined",
|
|
9
|
+
NotEnoughSpace = "not-enough-space",
|
|
10
|
+
ErrorEstimatingStorage = "error-estimating-storage",
|
|
11
|
+
NotCrossOriginIsolated = "not-cross-origin-isolated"
|
|
12
|
+
}
|
|
13
|
+
export interface CanUseWhisperWebResult {
|
|
14
|
+
supported: boolean;
|
|
15
|
+
reason?: WhisperWebUnsupportedReason;
|
|
16
|
+
detailedReason?: string;
|
|
17
|
+
}
|
|
18
|
+
export declare const canUseWhisperWeb: (model: WhisperWebModel) => Promise<CanUseWhisperWebResult>;
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { SIZES } from './constants';
|
|
2
|
+
export var WhisperWebUnsupportedReason;
|
|
3
|
+
(function (WhisperWebUnsupportedReason) {
|
|
4
|
+
WhisperWebUnsupportedReason["WindowUndefined"] = "window-undefined";
|
|
5
|
+
WhisperWebUnsupportedReason["IndexedDbUnavailable"] = "indexed-db-unavailable";
|
|
6
|
+
WhisperWebUnsupportedReason["NavigatorStorageUnavailable"] = "navigator-storage-unavailable";
|
|
7
|
+
WhisperWebUnsupportedReason["StorageEstimationApiUnavailable"] = "storage-estimation-api-unavailable";
|
|
8
|
+
WhisperWebUnsupportedReason["QuotaUndefined"] = "quota-undefined";
|
|
9
|
+
WhisperWebUnsupportedReason["UsageUndefined"] = "usage-undefined";
|
|
10
|
+
WhisperWebUnsupportedReason["NotEnoughSpace"] = "not-enough-space";
|
|
11
|
+
WhisperWebUnsupportedReason["ErrorEstimatingStorage"] = "error-estimating-storage";
|
|
12
|
+
WhisperWebUnsupportedReason["NotCrossOriginIsolated"] = "not-cross-origin-isolated";
|
|
13
|
+
})(WhisperWebUnsupportedReason || (WhisperWebUnsupportedReason = {}));
|
|
14
|
+
export const canUseWhisperWeb = async (model) => {
|
|
15
|
+
if (typeof window === 'undefined') {
|
|
16
|
+
return {
|
|
17
|
+
supported: false,
|
|
18
|
+
reason: WhisperWebUnsupportedReason.WindowUndefined,
|
|
19
|
+
detailedReason: '`window` is not defined. This module can only be used in a browser environment.',
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
if (!window.crossOriginIsolated) {
|
|
23
|
+
return {
|
|
24
|
+
supported: false,
|
|
25
|
+
reason: WhisperWebUnsupportedReason.NotCrossOriginIsolated,
|
|
26
|
+
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',
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
if (!window.indexedDB) {
|
|
30
|
+
return {
|
|
31
|
+
supported: false,
|
|
32
|
+
reason: WhisperWebUnsupportedReason.IndexedDbUnavailable,
|
|
33
|
+
detailedReason: 'IndexedDB is not available in this environment.',
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
if (!(navigator === null || navigator === void 0 ? void 0 : navigator.storage) || !(navigator === null || navigator === void 0 ? void 0 : navigator.storage.estimate)) {
|
|
37
|
+
return {
|
|
38
|
+
supported: false,
|
|
39
|
+
reason: WhisperWebUnsupportedReason.NavigatorStorageUnavailable,
|
|
40
|
+
detailedReason: '`navigator.storage.estimate()` API is not available in this environment.',
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
try {
|
|
44
|
+
const estimate = await navigator.storage.estimate();
|
|
45
|
+
if (estimate.quota === undefined) {
|
|
46
|
+
return {
|
|
47
|
+
supported: false,
|
|
48
|
+
reason: WhisperWebUnsupportedReason.QuotaUndefined,
|
|
49
|
+
detailedReason: 'navigator.storage.estimate() API returned undefined quota.',
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
if (estimate.usage === undefined) {
|
|
53
|
+
return {
|
|
54
|
+
supported: false,
|
|
55
|
+
reason: WhisperWebUnsupportedReason.UsageUndefined,
|
|
56
|
+
detailedReason: 'navigator.storage.estimate() API returned undefined usage.',
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
const remaining = estimate.quota - estimate.usage;
|
|
60
|
+
const modelSize = SIZES[model];
|
|
61
|
+
if (remaining < modelSize) {
|
|
62
|
+
return {
|
|
63
|
+
supported: false,
|
|
64
|
+
reason: WhisperWebUnsupportedReason.NotEnoughSpace,
|
|
65
|
+
detailedReason: `Not enough space to download the model. Required: ${modelSize} bytes, Available: ${remaining} bytes.`,
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
catch (error) {
|
|
70
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
71
|
+
return {
|
|
72
|
+
supported: false,
|
|
73
|
+
reason: WhisperWebUnsupportedReason.ErrorEstimatingStorage,
|
|
74
|
+
detailedReason: `Error estimating storage: ${errorMessage}`,
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
return {
|
|
78
|
+
supported: true,
|
|
79
|
+
};
|
|
80
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export declare const DB_NAME = "whisper-web";
|
|
2
|
+
export declare const DB_VERSION = 1;
|
|
3
|
+
export declare const DB_OBJECT_STORE_NAME = "models";
|
|
4
|
+
export declare const MODELS: readonly ["tiny", "tiny.en", "base", "base.en", "small", "small.en"];
|
|
5
|
+
export type WhisperWebModel = (typeof MODELS)[number];
|
|
6
|
+
export declare const LANGUAGES: readonly ["auto", "en", "zh", "de", "es", "ru", "ko", "fr", "ja", "pt", "tr", "pl", "ca", "nl", "ar", "sv", "it", "id", "hi", "fi", "vi", "he", "uk", "el", "ms", "cs", "ro", "da", "hu", "ta", "no", "th", "ur", "hr", "bg", "lt", "la", "mi", "ml", "cy", "sk", "te", "fa", "lv", "bn", "sr", "az", "sl", "kn", "et", "mk", "br", "eu", "is", "hy", "ne", "mn", "bs", "kk", "sq", "sw", "gl", "mr", "pa", "si", "km", "sn", "yo", "so", "af", "oc", "ka", "be", "tg", "sd", "gu", "am", "yi", "lo", "uz", "fo", "ht", "ps", "tk", "nn", "mt", "sa", "lb", "my", "bo", "tl", "mg", "as", "tt", "haw", "ln", "ha", "ba", "jw", "su", "yue", "english", "chinese", "german", "spanish", "russian", "korean", "french", "japanese", "portuguese", "turkish", "polish", "catalan", "dutch", "arabic", "swedish", "italian", "indonesian", "hindi", "finnish", "vietnamese", "hebrew", "ukrainian", "greek", "malay", "czech", "romanian", "danish", "hungarian", "tamil", "norwegian", "thai", "urdu", "croatian", "bulgarian", "lithuanian", "latin", "maori", "malayalam", "welsh", "slovak", "telugu", "persian", "latvian", "bengali", "serbian", "azerbaijani", "slovenian", "kannada", "estonian", "macedonian", "breton", "basque", "icelandic", "armenian", "nepali", "mongolian", "bosnian", "kazakh", "albanian", "swahili", "galician", "marathi", "punjabi", "sinhala", "khmer", "shona", "yoruba", "somali", "afrikaans", "occitan", "georgian", "belarusian", "tajik", "sindhi", "gujarati", "amharic", "yiddish", "lao", "uzbek", "faroese", "haitian creole", "pashto", "turkmen", "nynorsk", "maltese", "sanskrit", "luxembourgish", "myanmar", "tibetan", "tagalog", "malagasy", "assamese", "tatar", "hawaiian", "lingala", "hausa", "bashkir", "javanese", "sundanese", "cantonese"];
|
|
7
|
+
export type WhisperWebLanguage = (typeof LANGUAGES)[number];
|
|
8
|
+
export declare const SIZES: {
|
|
9
|
+
[key in WhisperWebModel]: number;
|
|
10
|
+
};
|
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
export const DB_NAME = 'whisper-web';
|
|
2
|
+
export const DB_VERSION = 1;
|
|
3
|
+
export const DB_OBJECT_STORE_NAME = 'models';
|
|
4
|
+
export const MODELS = [
|
|
5
|
+
'tiny',
|
|
6
|
+
'tiny.en',
|
|
7
|
+
'base',
|
|
8
|
+
'base.en',
|
|
9
|
+
'small',
|
|
10
|
+
'small.en',
|
|
11
|
+
];
|
|
12
|
+
export const LANGUAGES = [
|
|
13
|
+
// whisper allows passing 'auto' to auto-detect the language
|
|
14
|
+
'auto',
|
|
15
|
+
// short codes
|
|
16
|
+
'en',
|
|
17
|
+
'zh',
|
|
18
|
+
'de',
|
|
19
|
+
'es',
|
|
20
|
+
'ru',
|
|
21
|
+
'ko',
|
|
22
|
+
'fr',
|
|
23
|
+
'ja',
|
|
24
|
+
'pt',
|
|
25
|
+
'tr',
|
|
26
|
+
'pl',
|
|
27
|
+
'ca',
|
|
28
|
+
'nl',
|
|
29
|
+
'ar',
|
|
30
|
+
'sv',
|
|
31
|
+
'it',
|
|
32
|
+
'id',
|
|
33
|
+
'hi',
|
|
34
|
+
'fi',
|
|
35
|
+
'vi',
|
|
36
|
+
'he',
|
|
37
|
+
'uk',
|
|
38
|
+
'el',
|
|
39
|
+
'ms',
|
|
40
|
+
'cs',
|
|
41
|
+
'ro',
|
|
42
|
+
'da',
|
|
43
|
+
'hu',
|
|
44
|
+
'ta',
|
|
45
|
+
'no',
|
|
46
|
+
'th',
|
|
47
|
+
'ur',
|
|
48
|
+
'hr',
|
|
49
|
+
'bg',
|
|
50
|
+
'lt',
|
|
51
|
+
'la',
|
|
52
|
+
'mi',
|
|
53
|
+
'ml',
|
|
54
|
+
'cy',
|
|
55
|
+
'sk',
|
|
56
|
+
'te',
|
|
57
|
+
'fa',
|
|
58
|
+
'lv',
|
|
59
|
+
'bn',
|
|
60
|
+
'sr',
|
|
61
|
+
'az',
|
|
62
|
+
'sl',
|
|
63
|
+
'kn',
|
|
64
|
+
'et',
|
|
65
|
+
'mk',
|
|
66
|
+
'br',
|
|
67
|
+
'eu',
|
|
68
|
+
'is',
|
|
69
|
+
'hy',
|
|
70
|
+
'ne',
|
|
71
|
+
'mn',
|
|
72
|
+
'bs',
|
|
73
|
+
'kk',
|
|
74
|
+
'sq',
|
|
75
|
+
'sw',
|
|
76
|
+
'gl',
|
|
77
|
+
'mr',
|
|
78
|
+
'pa',
|
|
79
|
+
'si',
|
|
80
|
+
'km',
|
|
81
|
+
'sn',
|
|
82
|
+
'yo',
|
|
83
|
+
'so',
|
|
84
|
+
'af',
|
|
85
|
+
'oc',
|
|
86
|
+
'ka',
|
|
87
|
+
'be',
|
|
88
|
+
'tg',
|
|
89
|
+
'sd',
|
|
90
|
+
'gu',
|
|
91
|
+
'am',
|
|
92
|
+
'yi',
|
|
93
|
+
'lo',
|
|
94
|
+
'uz',
|
|
95
|
+
'fo',
|
|
96
|
+
'ht',
|
|
97
|
+
'ps',
|
|
98
|
+
'tk',
|
|
99
|
+
'nn',
|
|
100
|
+
'mt',
|
|
101
|
+
'sa',
|
|
102
|
+
'lb',
|
|
103
|
+
'my',
|
|
104
|
+
'bo',
|
|
105
|
+
'tl',
|
|
106
|
+
'mg',
|
|
107
|
+
'as',
|
|
108
|
+
'tt',
|
|
109
|
+
'haw',
|
|
110
|
+
'ln',
|
|
111
|
+
'ha',
|
|
112
|
+
'ba',
|
|
113
|
+
'jw',
|
|
114
|
+
'su',
|
|
115
|
+
'yue',
|
|
116
|
+
// aliases
|
|
117
|
+
'english',
|
|
118
|
+
'chinese',
|
|
119
|
+
'german',
|
|
120
|
+
'spanish',
|
|
121
|
+
'russian',
|
|
122
|
+
'korean',
|
|
123
|
+
'french',
|
|
124
|
+
'japanese',
|
|
125
|
+
'portuguese',
|
|
126
|
+
'turkish',
|
|
127
|
+
'polish',
|
|
128
|
+
'catalan',
|
|
129
|
+
'dutch',
|
|
130
|
+
'arabic',
|
|
131
|
+
'swedish',
|
|
132
|
+
'italian',
|
|
133
|
+
'indonesian',
|
|
134
|
+
'hindi',
|
|
135
|
+
'finnish',
|
|
136
|
+
'vietnamese',
|
|
137
|
+
'hebrew',
|
|
138
|
+
'ukrainian',
|
|
139
|
+
'greek',
|
|
140
|
+
'malay',
|
|
141
|
+
'czech',
|
|
142
|
+
'romanian',
|
|
143
|
+
'danish',
|
|
144
|
+
'hungarian',
|
|
145
|
+
'tamil',
|
|
146
|
+
'norwegian',
|
|
147
|
+
'thai',
|
|
148
|
+
'urdu',
|
|
149
|
+
'croatian',
|
|
150
|
+
'bulgarian',
|
|
151
|
+
'lithuanian',
|
|
152
|
+
'latin',
|
|
153
|
+
'maori',
|
|
154
|
+
'malayalam',
|
|
155
|
+
'welsh',
|
|
156
|
+
'slovak',
|
|
157
|
+
'telugu',
|
|
158
|
+
'persian',
|
|
159
|
+
'latvian',
|
|
160
|
+
'bengali',
|
|
161
|
+
'serbian',
|
|
162
|
+
'azerbaijani',
|
|
163
|
+
'slovenian',
|
|
164
|
+
'kannada',
|
|
165
|
+
'estonian',
|
|
166
|
+
'macedonian',
|
|
167
|
+
'breton',
|
|
168
|
+
'basque',
|
|
169
|
+
'icelandic',
|
|
170
|
+
'armenian',
|
|
171
|
+
'nepali',
|
|
172
|
+
'mongolian',
|
|
173
|
+
'bosnian',
|
|
174
|
+
'kazakh',
|
|
175
|
+
'albanian',
|
|
176
|
+
'swahili',
|
|
177
|
+
'galician',
|
|
178
|
+
'marathi',
|
|
179
|
+
'punjabi',
|
|
180
|
+
'sinhala',
|
|
181
|
+
'khmer',
|
|
182
|
+
'shona',
|
|
183
|
+
'yoruba',
|
|
184
|
+
'somali',
|
|
185
|
+
'afrikaans',
|
|
186
|
+
'occitan',
|
|
187
|
+
'georgian',
|
|
188
|
+
'belarusian',
|
|
189
|
+
'tajik',
|
|
190
|
+
'sindhi',
|
|
191
|
+
'gujarati',
|
|
192
|
+
'amharic',
|
|
193
|
+
'yiddish',
|
|
194
|
+
'lao',
|
|
195
|
+
'uzbek',
|
|
196
|
+
'faroese',
|
|
197
|
+
'haitian creole',
|
|
198
|
+
'pashto',
|
|
199
|
+
'turkmen',
|
|
200
|
+
'nynorsk',
|
|
201
|
+
'maltese',
|
|
202
|
+
'sanskrit',
|
|
203
|
+
'luxembourgish',
|
|
204
|
+
'myanmar',
|
|
205
|
+
'tibetan',
|
|
206
|
+
'tagalog',
|
|
207
|
+
'malagasy',
|
|
208
|
+
'assamese',
|
|
209
|
+
'tatar',
|
|
210
|
+
'hawaiian',
|
|
211
|
+
'lingala',
|
|
212
|
+
'hausa',
|
|
213
|
+
'bashkir',
|
|
214
|
+
'javanese',
|
|
215
|
+
'sundanese',
|
|
216
|
+
'cantonese',
|
|
217
|
+
];
|
|
218
|
+
export const SIZES = {
|
|
219
|
+
tiny: 77691713,
|
|
220
|
+
'tiny.en': 77704715,
|
|
221
|
+
base: 147951465,
|
|
222
|
+
'base.en': 147964211,
|
|
223
|
+
small: 487601967,
|
|
224
|
+
'small.en': 487614201,
|
|
225
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { openDb } from './open-db';
|
|
2
|
+
export const deleteObject = async ({ key }) => {
|
|
3
|
+
const objectStore = await openDb('readwrite');
|
|
4
|
+
return new Promise((resolve, reject) => {
|
|
5
|
+
const request = objectStore.delete(key);
|
|
6
|
+
request.onsuccess = () => {
|
|
7
|
+
resolve();
|
|
8
|
+
};
|
|
9
|
+
request.onerror = () => {
|
|
10
|
+
reject(request.error);
|
|
11
|
+
};
|
|
12
|
+
});
|
|
13
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export declare const getObjectFromObjectStore: ({ objectStore, key, }: {
|
|
2
|
+
objectStore: IDBObjectStore;
|
|
3
|
+
key: string;
|
|
4
|
+
}) => Promise<Uint8Array<ArrayBufferLike>>;
|
|
5
|
+
export declare const getKeysFromObjectStore: ({ objectStore, }: {
|
|
6
|
+
objectStore: IDBObjectStore;
|
|
7
|
+
}) => Promise<IDBValidKey[]>;
|
|
8
|
+
export declare const getObject: ({ key }: {
|
|
9
|
+
key: string;
|
|
10
|
+
}) => Promise<Uint8Array<ArrayBufferLike>>;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { openDb } from './open-db';
|
|
2
|
+
export const getObjectFromObjectStore = ({ objectStore, key, }) => {
|
|
3
|
+
return new Promise((resolve, reject) => {
|
|
4
|
+
const request = objectStore.get(key);
|
|
5
|
+
request.onsuccess = () => {
|
|
6
|
+
resolve(request.result);
|
|
7
|
+
};
|
|
8
|
+
request.onerror = () => {
|
|
9
|
+
reject(request.error);
|
|
10
|
+
};
|
|
11
|
+
});
|
|
12
|
+
};
|
|
13
|
+
export const getKeysFromObjectStore = ({ objectStore, }) => {
|
|
14
|
+
return new Promise((resolve, reject) => {
|
|
15
|
+
const request = objectStore.getAllKeys();
|
|
16
|
+
request.onsuccess = () => {
|
|
17
|
+
resolve(request.result);
|
|
18
|
+
};
|
|
19
|
+
request.onerror = () => {
|
|
20
|
+
reject(request.error);
|
|
21
|
+
};
|
|
22
|
+
});
|
|
23
|
+
};
|
|
24
|
+
export const getObject = async ({ key }) => {
|
|
25
|
+
const objectStore = await openDb('readonly');
|
|
26
|
+
return getObjectFromObjectStore({ objectStore, key });
|
|
27
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const openDb: (transactionMode: IDBTransactionMode) => Promise<IDBObjectStore>;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { DB_NAME, DB_OBJECT_STORE_NAME, DB_VERSION } from '../constants';
|
|
2
|
+
export const openDb = (transactionMode) => {
|
|
3
|
+
return new Promise((resolve, reject) => {
|
|
4
|
+
const rq = indexedDB.open(DB_NAME, DB_VERSION);
|
|
5
|
+
rq.onupgradeneeded = (event) => {
|
|
6
|
+
try {
|
|
7
|
+
const db = rq.result;
|
|
8
|
+
if (event.oldVersion < DB_VERSION) {
|
|
9
|
+
db.createObjectStore(DB_OBJECT_STORE_NAME, { autoIncrement: false });
|
|
10
|
+
}
|
|
11
|
+
else {
|
|
12
|
+
const { transaction } = event.currentTarget;
|
|
13
|
+
if (!transaction) {
|
|
14
|
+
throw new Error('No transaction available during upgrade');
|
|
15
|
+
}
|
|
16
|
+
const objectStore = transaction.objectStore(DB_OBJECT_STORE_NAME);
|
|
17
|
+
if (!objectStore) {
|
|
18
|
+
throw new Error('Could not access object store during upgrade');
|
|
19
|
+
}
|
|
20
|
+
objectStore.clear();
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
catch (err) {
|
|
24
|
+
reject(new Error(`Failed to upgrade database: ${err}`));
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
rq.onsuccess = () => {
|
|
28
|
+
try {
|
|
29
|
+
const db = rq.result;
|
|
30
|
+
const transaction = db.transaction([DB_OBJECT_STORE_NAME], transactionMode);
|
|
31
|
+
transaction.onerror = () => {
|
|
32
|
+
reject(new Error('Transaction failed'));
|
|
33
|
+
};
|
|
34
|
+
transaction.onabort = () => {
|
|
35
|
+
reject(new Error('Transaction aborted'));
|
|
36
|
+
};
|
|
37
|
+
const objectStore = transaction.objectStore(DB_OBJECT_STORE_NAME);
|
|
38
|
+
resolve(objectStore);
|
|
39
|
+
}
|
|
40
|
+
catch (err) {
|
|
41
|
+
reject(new Error(`Failed to open database: ${err}`));
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
rq.onerror = () => {
|
|
45
|
+
var _a, _b;
|
|
46
|
+
const error = (_b = (_a = rq.error) === null || _a === void 0 ? void 0 : _a.message) !== null && _b !== void 0 ? _b : 'Unknown error';
|
|
47
|
+
reject(new Error(`Failed to open IndexedDB: ${error}`));
|
|
48
|
+
};
|
|
49
|
+
rq.onblocked = () => {
|
|
50
|
+
reject(new Error('Database is blocked by another connection'));
|
|
51
|
+
};
|
|
52
|
+
});
|
|
53
|
+
};
|