@remotion/whisper-web 4.0.364 → 4.0.366

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/src/constants.ts DELETED
@@ -1,232 +0,0 @@
1
- export const DB_NAME = 'whisper-web';
2
- export const DB_VERSION = 1;
3
- export const DB_OBJECT_STORE_NAME = 'models';
4
-
5
- export const MODELS = [
6
- 'tiny',
7
- 'tiny.en',
8
- 'base',
9
- 'base.en',
10
- 'small',
11
- 'small.en',
12
- ] as const;
13
-
14
- export type WhisperWebModel = (typeof MODELS)[number];
15
-
16
- export const LANGUAGES = [
17
- // whisper allows passing 'auto' to auto-detect the language
18
- 'auto',
19
- // short codes
20
- 'en',
21
- 'zh',
22
- 'de',
23
- 'es',
24
- 'ru',
25
- 'ko',
26
- 'fr',
27
- 'ja',
28
- 'pt',
29
- 'tr',
30
- 'pl',
31
- 'ca',
32
- 'nl',
33
- 'ar',
34
- 'sv',
35
- 'it',
36
- 'id',
37
- 'hi',
38
- 'fi',
39
- 'vi',
40
- 'he',
41
- 'uk',
42
- 'el',
43
- 'ms',
44
- 'cs',
45
- 'ro',
46
- 'da',
47
- 'hu',
48
- 'ta',
49
- 'no',
50
- 'th',
51
- 'ur',
52
- 'hr',
53
- 'bg',
54
- 'lt',
55
- 'la',
56
- 'mi',
57
- 'ml',
58
- 'cy',
59
- 'sk',
60
- 'te',
61
- 'fa',
62
- 'lv',
63
- 'bn',
64
- 'sr',
65
- 'az',
66
- 'sl',
67
- 'kn',
68
- 'et',
69
- 'mk',
70
- 'br',
71
- 'eu',
72
- 'is',
73
- 'hy',
74
- 'ne',
75
- 'mn',
76
- 'bs',
77
- 'kk',
78
- 'sq',
79
- 'sw',
80
- 'gl',
81
- 'mr',
82
- 'pa',
83
- 'si',
84
- 'km',
85
- 'sn',
86
- 'yo',
87
- 'so',
88
- 'af',
89
- 'oc',
90
- 'ka',
91
- 'be',
92
- 'tg',
93
- 'sd',
94
- 'gu',
95
- 'am',
96
- 'yi',
97
- 'lo',
98
- 'uz',
99
- 'fo',
100
- 'ht',
101
- 'ps',
102
- 'tk',
103
- 'nn',
104
- 'mt',
105
- 'sa',
106
- 'lb',
107
- 'my',
108
- 'bo',
109
- 'tl',
110
- 'mg',
111
- 'as',
112
- 'tt',
113
- 'haw',
114
- 'ln',
115
- 'ha',
116
- 'ba',
117
- 'jw',
118
- 'su',
119
- 'yue',
120
- // aliases
121
- 'english',
122
- 'chinese',
123
- 'german',
124
- 'spanish',
125
- 'russian',
126
- 'korean',
127
- 'french',
128
- 'japanese',
129
- 'portuguese',
130
- 'turkish',
131
- 'polish',
132
- 'catalan',
133
- 'dutch',
134
- 'arabic',
135
- 'swedish',
136
- 'italian',
137
- 'indonesian',
138
- 'hindi',
139
- 'finnish',
140
- 'vietnamese',
141
- 'hebrew',
142
- 'ukrainian',
143
- 'greek',
144
- 'malay',
145
- 'czech',
146
- 'romanian',
147
- 'danish',
148
- 'hungarian',
149
- 'tamil',
150
- 'norwegian',
151
- 'thai',
152
- 'urdu',
153
- 'croatian',
154
- 'bulgarian',
155
- 'lithuanian',
156
- 'latin',
157
- 'maori',
158
- 'malayalam',
159
- 'welsh',
160
- 'slovak',
161
- 'telugu',
162
- 'persian',
163
- 'latvian',
164
- 'bengali',
165
- 'serbian',
166
- 'azerbaijani',
167
- 'slovenian',
168
- 'kannada',
169
- 'estonian',
170
- 'macedonian',
171
- 'breton',
172
- 'basque',
173
- 'icelandic',
174
- 'armenian',
175
- 'nepali',
176
- 'mongolian',
177
- 'bosnian',
178
- 'kazakh',
179
- 'albanian',
180
- 'swahili',
181
- 'galician',
182
- 'marathi',
183
- 'punjabi',
184
- 'sinhala',
185
- 'khmer',
186
- 'shona',
187
- 'yoruba',
188
- 'somali',
189
- 'afrikaans',
190
- 'occitan',
191
- 'georgian',
192
- 'belarusian',
193
- 'tajik',
194
- 'sindhi',
195
- 'gujarati',
196
- 'amharic',
197
- 'yiddish',
198
- 'lao',
199
- 'uzbek',
200
- 'faroese',
201
- 'haitian creole',
202
- 'pashto',
203
- 'turkmen',
204
- 'nynorsk',
205
- 'maltese',
206
- 'sanskrit',
207
- 'luxembourgish',
208
- 'myanmar',
209
- 'tibetan',
210
- 'tagalog',
211
- 'malagasy',
212
- 'assamese',
213
- 'tatar',
214
- 'hawaiian',
215
- 'lingala',
216
- 'hausa',
217
- 'bashkir',
218
- 'javanese',
219
- 'sundanese',
220
- 'cantonese',
221
- ] as const;
222
-
223
- export type WhisperWebLanguage = (typeof LANGUAGES)[number];
224
-
225
- export const SIZES: {[key in WhisperWebModel]: number} = {
226
- tiny: 77691713,
227
- 'tiny.en': 77704715,
228
- base: 147951465,
229
- 'base.en': 147964211,
230
- small: 487601967,
231
- 'small.en': 487614201,
232
- };
@@ -1,16 +0,0 @@
1
- import {openDb} from './open-db';
2
-
3
- export const deleteObject = async ({key}: {key: string}) => {
4
- const objectStore = await openDb('readwrite');
5
-
6
- return new Promise<void>((resolve, reject) => {
7
- const request = objectStore.delete(key);
8
- request.onsuccess = () => {
9
- resolve();
10
- };
11
-
12
- request.onerror = () => {
13
- reject(request.error);
14
- };
15
- });
16
- };
@@ -1,43 +0,0 @@
1
- import {openDb} from './open-db';
2
-
3
- export const getObjectFromObjectStore = ({
4
- objectStore,
5
- key,
6
- }: {
7
- objectStore: IDBObjectStore;
8
- key: string;
9
- }) => {
10
- return new Promise<Uint8Array>((resolve, reject) => {
11
- const request = objectStore.get(key);
12
- request.onsuccess = () => {
13
- resolve(request.result as Uint8Array);
14
- };
15
-
16
- request.onerror = () => {
17
- reject(request.error);
18
- };
19
- });
20
- };
21
-
22
- export const getKeysFromObjectStore = ({
23
- objectStore,
24
- }: {
25
- objectStore: IDBObjectStore;
26
- }) => {
27
- return new Promise<IDBValidKey[]>((resolve, reject) => {
28
- const request = objectStore.getAllKeys();
29
- request.onsuccess = () => {
30
- resolve(request.result as IDBValidKey[]);
31
- };
32
-
33
- request.onerror = () => {
34
- reject(request.error);
35
- };
36
- });
37
- };
38
-
39
- export const getObject = async ({key}: {key: string}) => {
40
- const objectStore = await openDb('readonly');
41
-
42
- return getObjectFromObjectStore({objectStore, key});
43
- };
package/src/db/open-db.ts DELETED
@@ -1,62 +0,0 @@
1
- import {DB_NAME, DB_OBJECT_STORE_NAME, DB_VERSION} from '../constants';
2
-
3
- export const openDb = (transactionMode: IDBTransactionMode) => {
4
- return new Promise<IDBObjectStore>((resolve, reject) => {
5
- const rq = indexedDB.open(DB_NAME, DB_VERSION);
6
-
7
- rq.onupgradeneeded = (event) => {
8
- try {
9
- const db = rq.result;
10
- if (event.oldVersion < DB_VERSION) {
11
- db.createObjectStore(DB_OBJECT_STORE_NAME, {autoIncrement: false});
12
- } else {
13
- const {transaction} = event.currentTarget as IDBOpenDBRequest;
14
- if (!transaction) {
15
- throw new Error('No transaction available during upgrade');
16
- }
17
-
18
- const objectStore = transaction.objectStore(DB_OBJECT_STORE_NAME);
19
- if (!objectStore) {
20
- throw new Error('Could not access object store during upgrade');
21
- }
22
-
23
- objectStore.clear();
24
- }
25
- } catch (err) {
26
- reject(new Error(`Failed to upgrade database: ${err}`));
27
- }
28
- };
29
-
30
- rq.onsuccess = () => {
31
- try {
32
- const db = rq.result;
33
- const transaction = db.transaction(
34
- [DB_OBJECT_STORE_NAME],
35
- transactionMode,
36
- );
37
-
38
- transaction.onerror = () => {
39
- reject(new Error('Transaction failed'));
40
- };
41
-
42
- transaction.onabort = () => {
43
- reject(new Error('Transaction aborted'));
44
- };
45
-
46
- const objectStore = transaction.objectStore(DB_OBJECT_STORE_NAME);
47
- resolve(objectStore);
48
- } catch (err) {
49
- reject(new Error(`Failed to open database: ${err}`));
50
- }
51
- };
52
-
53
- rq.onerror = () => {
54
- const error = rq.error?.message ?? 'Unknown error';
55
- reject(new Error(`Failed to open IndexedDB: ${error}`));
56
- };
57
-
58
- rq.onblocked = () => {
59
- reject(new Error('Database is blocked by another connection'));
60
- };
61
- });
62
- };
@@ -1,27 +0,0 @@
1
- import {openDb} from './open-db';
2
-
3
- export const putObject = async ({
4
- key,
5
- value,
6
- }: {
7
- key: string;
8
- value: Uint8Array;
9
- }) => {
10
- const objectStore = await openDb('readwrite');
11
-
12
- return new Promise<void>((resolve, reject) => {
13
- try {
14
- const putRq = objectStore.put(value, key);
15
-
16
- putRq.onsuccess = () => {
17
- resolve();
18
- };
19
-
20
- putRq.onerror = () => {
21
- reject(new Error(`Failed to store "${key}" in IndexedDB`));
22
- };
23
- } catch (e) {
24
- reject(new Error(`Failed to store "${key}" in IndexedDB: ${e}`));
25
- }
26
- });
27
- };
@@ -1,8 +0,0 @@
1
- import type {WhisperWebModel} from './constants';
2
- import {deleteObject} from './db/delete-object';
3
- import {getModelUrl} from './get-model-url';
4
-
5
- export const deleteModel = async (model: WhisperWebModel) => {
6
- const url = getModelUrl(model);
7
- await deleteObject({key: url});
8
- };
@@ -1,52 +0,0 @@
1
- export const fetchRemote = async ({
2
- url,
3
- onProgress,
4
- expectedLength,
5
- }: {
6
- url: string;
7
- onProgress: (progress: number) => void;
8
- expectedLength: number;
9
- }) => {
10
- // start the fetch
11
- const response = await fetch(url, {method: 'get'});
12
- if (!response.ok || !response.body) {
13
- throw new Error(`failed to fetch: ${url}`);
14
- }
15
-
16
- const contentLength = response.headers.get('content-length') as string;
17
- // hugging face servers do include this header
18
- const total = parseInt(contentLength, 10);
19
- if (total !== expectedLength) {
20
- throw new Error(
21
- `Content-Length header is ${total} for ${url} but expected ${expectedLength}`,
22
- );
23
- }
24
-
25
- const reader = response.body.getReader();
26
-
27
- const chunks: Uint8Array[] = [];
28
- let receivedLength = 0;
29
-
30
- while (true) {
31
- const {done, value} = await reader.read();
32
-
33
- if (done) {
34
- break;
35
- }
36
-
37
- chunks.push(value);
38
- receivedLength += value.length;
39
-
40
- onProgress(receivedLength);
41
- }
42
-
43
- let position = 0;
44
- const chunksAll = new Uint8Array(receivedLength);
45
-
46
- for (const chunk of chunks) {
47
- chunksAll.set(chunk, position);
48
- position += chunk.length;
49
- }
50
-
51
- return chunksAll;
52
- };
@@ -1,86 +0,0 @@
1
- import {canUseWhisperWeb} from './can-use-whisper-web';
2
- import {MODELS, SIZES, type WhisperWebModel} from './constants';
3
- import {getObject} from './db/get-object-from-db';
4
- import {putObject} from './db/put-object';
5
- import {fetchRemote} from './download-model';
6
- import {getModelUrl} from './get-model-url';
7
-
8
- export type DownloadWhisperModelProgress = {
9
- downloadedBytes: number;
10
- totalBytes: number;
11
- progress: number;
12
- };
13
-
14
- export type DownloadWhisperModelOnProgress = (
15
- progress: DownloadWhisperModelProgress,
16
- ) => void;
17
-
18
- export interface DownloadWhisperModelParams {
19
- model: WhisperWebModel;
20
- onProgress: DownloadWhisperModelOnProgress;
21
- }
22
-
23
- export type DownloadWhisperModelResult = {
24
- alreadyDownloaded: boolean;
25
- };
26
-
27
- export const downloadWhisperModel = async ({
28
- model,
29
- onProgress,
30
- }: DownloadWhisperModelParams): Promise<DownloadWhisperModelResult> => {
31
- if (!model || !MODELS.includes(model)) {
32
- throw new Error(
33
- `Invalid model name: ${model}. Supported models: ${MODELS.join(', ')}.`,
34
- );
35
- }
36
-
37
- const usabilityCheck = await canUseWhisperWeb(model);
38
-
39
- if (!usabilityCheck.supported) {
40
- return Promise.reject(
41
- new Error(
42
- `Whisper.wasm is not supported in this environment. Reason: ${usabilityCheck.detailedReason}`,
43
- ),
44
- );
45
- }
46
-
47
- const url = getModelUrl(model);
48
- const modelSize = SIZES[model];
49
-
50
- const existingModel = await getObject({key: url});
51
- if (existingModel) {
52
- onProgress({
53
- downloadedBytes: modelSize,
54
- totalBytes: modelSize,
55
- progress: 1,
56
- });
57
-
58
- return {
59
- alreadyDownloaded: true,
60
- };
61
- }
62
-
63
- const data = await fetchRemote({
64
- url,
65
- onProgress: (bytes) => {
66
- onProgress({
67
- downloadedBytes: bytes,
68
- progress: bytes / modelSize,
69
- totalBytes: modelSize,
70
- });
71
- },
72
- expectedLength: modelSize,
73
- });
74
-
75
- onProgress({
76
- downloadedBytes: modelSize,
77
- totalBytes: modelSize,
78
- progress: 1,
79
- });
80
-
81
- await putObject({key: url, value: data});
82
-
83
- return {
84
- alreadyDownloaded: false,
85
- };
86
- };
@@ -1,17 +0,0 @@
1
- import {MODELS, SIZES, type WhisperWebModel} from './constants';
2
-
3
- export type AvailableModel = {
4
- name: WhisperWebModel;
5
- downloadSize: number;
6
- };
7
-
8
- /**
9
- * Returns an array of all available Whisper models with their download sizes.
10
- * @returns An array of objects containing model name and download size in bytes
11
- */
12
- export const getAvailableModels = (): AvailableModel[] => {
13
- return MODELS.map((model) => ({
14
- name: model,
15
- downloadSize: SIZES[model],
16
- }));
17
- };
@@ -1,22 +0,0 @@
1
- import type {WhisperWebModel} from './constants';
2
- import {MODELS} from './constants';
3
- import {getKeysFromObjectStore} from './db/get-object-from-db';
4
- import {openDb} from './db/open-db';
5
- import {getModelUrl} from './get-model-url';
6
-
7
- export const getLoadedModels = async (): Promise<WhisperWebModel[]> => {
8
- const objectStore = await openDb('readonly');
9
- const loadedModels: WhisperWebModel[] = [];
10
-
11
- const result = await getKeysFromObjectStore({
12
- objectStore,
13
- });
14
-
15
- for (const model of MODELS) {
16
- if (result.includes(getModelUrl(model))) {
17
- loadedModels.push(model);
18
- }
19
- }
20
-
21
- return loadedModels;
22
- };
@@ -1,13 +0,0 @@
1
- import type {WhisperWebModel} from './constants';
2
-
3
- export const getModelUrl = (model: WhisperWebModel) => {
4
- return `https://huggingface.co/ggerganov/whisper.cpp/resolve/main/ggml-${model}.bin`;
5
- };
6
-
7
- export const sizes = {
8
- tiny: 74_000_000,
9
- base: 244_000_000,
10
- small: 769_000_000,
11
- medium: 1550_000_000,
12
- large: 3050_000_000,
13
- };
@@ -1,12 +0,0 @@
1
- export {canUseWhisperWeb} from './can-use-whisper-web';
2
- export {deleteModel} from './delete-model';
3
- export {
4
- DownloadWhisperModelParams,
5
- DownloadWhisperModelResult,
6
- downloadWhisperModel,
7
- } from './download-whisper-model';
8
- export {AvailableModel, getAvailableModels} from './get-available-models';
9
- export {getLoadedModels} from './get-loaded-models';
10
- export {resampleTo16Khz} from './resample-to-16khz';
11
- export {toCaptions} from './to-captions';
12
- export {TranscribeParams, transcribe} from './transcribe';
package/src/index.ts DELETED
@@ -1,93 +0,0 @@
1
- import type {
2
- CanUseWhisperWebResult,
3
- canUseWhisperWeb as originalCanUseWhisperWeb,
4
- WhisperWebUnsupportedReason,
5
- } from './can-use-whisper-web';
6
- import type {WhisperWebLanguage, WhisperWebModel} from './constants';
7
- import type {deleteModel as originalDeleteModel} from './delete-model';
8
- import type {
9
- DownloadWhisperModelOnProgress,
10
- DownloadWhisperModelParams,
11
- DownloadWhisperModelProgress,
12
- DownloadWhisperModelResult,
13
- downloadWhisperModel as originalDownloadWhisperModel,
14
- } from './download-whisper-model';
15
- import type {
16
- AvailableModel,
17
- getAvailableModels as originalGetAvailableModels,
18
- } from './get-available-models';
19
- import type {getLoadedModels as originalGetLoadedModels} from './get-loaded-models';
20
- import type {
21
- resampleTo16Khz as originalResampleTo16Khz,
22
- ResampleTo16KhzParams,
23
- } from './resample-to-16khz';
24
- import type {TranscriptionItemWithTimestamp, TranscriptionJson} from './result';
25
- import type {toCaptions as originalToCaptions} from './to-captions';
26
- import type {
27
- transcribe as originalTranscribe,
28
- TranscribeParams,
29
- } from './transcribe';
30
-
31
- export const transcribe: typeof originalTranscribe = () => {
32
- throw new Error(
33
- 'Loading this module from CommonJS is not supported. Load the ESM version of @remotion/whisper-web.',
34
- );
35
- };
36
-
37
- export const downloadWhisperModel: typeof originalDownloadWhisperModel = () => {
38
- throw new Error(
39
- 'Loading this module from CommonJS is not supported. Load the ESM version of @remotion/whisper-web.',
40
- );
41
- };
42
-
43
- export const getLoadedModels: typeof originalGetLoadedModels = () => {
44
- throw new Error(
45
- 'Loading this module from CommonJS is not supported. Load the ESM version of @remotion/whisper-web.',
46
- );
47
- };
48
-
49
- export const getAvailableModels: typeof originalGetAvailableModels = () => {
50
- throw new Error(
51
- 'Loading this module from CommonJS is not supported. Load the ESM version of @remotion/whisper-web.',
52
- );
53
- };
54
-
55
- export const deleteModel: typeof originalDeleteModel = () => {
56
- throw new Error(
57
- 'Loading this module from CommonJS is not supported. Load the ESM version of @remotion/whisper-web.',
58
- );
59
- };
60
-
61
- export const canUseWhisperWeb: typeof originalCanUseWhisperWeb = () => {
62
- throw new Error(
63
- 'Loading this module from CommonJS is not supported. Load the ESM version of @remotion/whisper-web.',
64
- );
65
- };
66
-
67
- export const resampleTo16Khz: typeof originalResampleTo16Khz = () => {
68
- throw new Error(
69
- 'Loading this module from CommonJS is not supported. Load the ESM version of @remotion/whisper-web.',
70
- );
71
- };
72
-
73
- export const toCaptions: typeof originalToCaptions = () => {
74
- throw new Error(
75
- 'Loading this module from CommonJS is not supported. Load the ESM version of @remotion/whisper-web.',
76
- );
77
- };
78
-
79
- export type {
80
- AvailableModel,
81
- CanUseWhisperWebResult,
82
- DownloadWhisperModelOnProgress,
83
- DownloadWhisperModelParams,
84
- DownloadWhisperModelProgress,
85
- DownloadWhisperModelResult,
86
- ResampleTo16KhzParams,
87
- TranscribeParams,
88
- TranscriptionItemWithTimestamp,
89
- TranscriptionJson,
90
- WhisperWebLanguage,
91
- WhisperWebModel,
92
- WhisperWebUnsupportedReason,
93
- };