@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.
Files changed (78) hide show
  1. package/.turbo/turbo-make.log +6 -0
  2. package/LICENSE.md +49 -0
  3. package/README.md +18 -0
  4. package/build-wasm.ts +117 -0
  5. package/bundle.ts +15 -0
  6. package/dist/can-use-whisper-web.d.ts +18 -0
  7. package/dist/can-use-whisper-web.js +80 -0
  8. package/dist/constants.d.ts +10 -0
  9. package/dist/constants.js +225 -0
  10. package/dist/db/delete-object.d.ts +3 -0
  11. package/dist/db/delete-object.js +13 -0
  12. package/dist/db/get-object-from-db.d.ts +10 -0
  13. package/dist/db/get-object-from-db.js +27 -0
  14. package/dist/db/open-db.d.ts +1 -0
  15. package/dist/db/open-db.js +53 -0
  16. package/dist/db/put-object.d.ts +4 -0
  17. package/dist/db/put-object.js +18 -0
  18. package/dist/delete-model.d.ts +2 -0
  19. package/dist/delete-model.js +6 -0
  20. package/dist/download-model.d.ts +5 -0
  21. package/dist/download-model.js +32 -0
  22. package/dist/download-whisper-model.d.ts +15 -0
  23. package/dist/download-whisper-model.js +48 -0
  24. package/dist/esm/index.mjs +652 -0
  25. package/dist/get-loaded-models.d.ts +2 -0
  26. package/dist/get-loaded-models.js +17 -0
  27. package/dist/get-model-url.d.ts +9 -0
  28. package/dist/get-model-url.js +10 -0
  29. package/dist/index.d.ts +14 -0
  30. package/dist/index.js +18 -0
  31. package/dist/load-mod/load-mod.d.ts +2 -0
  32. package/dist/load-mod/load-mod.js +6 -0
  33. package/dist/log.d.ts +10 -0
  34. package/dist/log.js +33 -0
  35. package/dist/mod.d.ts +6 -0
  36. package/dist/mod.js +1 -0
  37. package/dist/print-handler.d.ts +9 -0
  38. package/dist/print-handler.js +25 -0
  39. package/dist/resample-to-16khz.d.ts +8 -0
  40. package/dist/resample-to-16khz.js +66 -0
  41. package/dist/result.d.ts +53 -0
  42. package/dist/result.js +1 -0
  43. package/dist/simulate-progress.d.ts +9 -0
  44. package/dist/simulate-progress.js +53 -0
  45. package/dist/transcribe.d.ts +18 -0
  46. package/dist/transcribe.js +97 -0
  47. package/dist/transcription-speed.d.ts +3 -0
  48. package/dist/transcription-speed.js +13 -0
  49. package/emscripten.cpp +303 -0
  50. package/eslint.config.mjs +5 -0
  51. package/main.d.ts +46 -0
  52. package/main.js +3 -0
  53. package/package.json +52 -0
  54. package/src/can-use-whisper-web.ts +103 -0
  55. package/src/constants.ts +232 -0
  56. package/src/db/delete-object.ts +16 -0
  57. package/src/db/get-object-from-db.ts +43 -0
  58. package/src/db/open-db.ts +62 -0
  59. package/src/db/put-object.ts +27 -0
  60. package/src/delete-model.ts +8 -0
  61. package/src/download-model.ts +52 -0
  62. package/src/download-whisper-model.ts +86 -0
  63. package/src/get-loaded-models.ts +22 -0
  64. package/src/get-model-url.ts +13 -0
  65. package/src/index.module.ts +9 -0
  66. package/src/index.ts +72 -0
  67. package/src/load-mod/load-mod.ts +11 -0
  68. package/src/log.ts +41 -0
  69. package/src/mod.ts +13 -0
  70. package/src/print-handler.ts +39 -0
  71. package/src/resample-to-16khz.ts +105 -0
  72. package/src/result.ts +59 -0
  73. package/src/simulate-progress.ts +74 -0
  74. package/src/transcribe.ts +184 -0
  75. package/src/transcription-speed.ts +21 -0
  76. package/tsconfig.json +11 -0
  77. package/tsconfig.tsbuildinfo +1 -0
  78. package/worker.js +3 -0
@@ -0,0 +1,18 @@
1
+ import { openDb } from './open-db';
2
+ export const putObject = async ({ key, value, }) => {
3
+ const objectStore = await openDb('readwrite');
4
+ return new Promise((resolve, reject) => {
5
+ try {
6
+ const putRq = objectStore.put(value, key);
7
+ putRq.onsuccess = () => {
8
+ resolve();
9
+ };
10
+ putRq.onerror = () => {
11
+ reject(new Error(`Failed to store "${key}" in IndexedDB`));
12
+ };
13
+ }
14
+ catch (e) {
15
+ reject(new Error(`Failed to store "${key}" in IndexedDB: ${e}`));
16
+ }
17
+ });
18
+ };
@@ -0,0 +1,2 @@
1
+ import type { WhisperWebModel } from './constants';
2
+ export declare const deleteModel: (model: WhisperWebModel) => Promise<void>;
@@ -0,0 +1,6 @@
1
+ import { deleteObject } from './db/delete-object';
2
+ import { getModelUrl } from './get-model-url';
3
+ export const deleteModel = async (model) => {
4
+ const url = getModelUrl(model);
5
+ await deleteObject({ key: url });
6
+ };
@@ -0,0 +1,5 @@
1
+ export declare const fetchRemote: ({ url, onProgress, expectedLength, }: {
2
+ url: string;
3
+ onProgress: (progress: number) => void;
4
+ expectedLength: number;
5
+ }) => Promise<Uint8Array<ArrayBuffer>>;
@@ -0,0 +1,32 @@
1
+ export const fetchRemote = async ({ url, onProgress, expectedLength, }) => {
2
+ // start the fetch
3
+ const response = await fetch(url, { method: 'get' });
4
+ if (!response.ok || !response.body) {
5
+ throw new Error(`failed to fetch: ${url}`);
6
+ }
7
+ const contentLength = response.headers.get('content-length');
8
+ // hugging face servers do include this header
9
+ const total = parseInt(contentLength, 10);
10
+ if (total !== expectedLength) {
11
+ throw new Error(`Content-Length header is ${total} for ${url} but expected ${expectedLength}`);
12
+ }
13
+ const reader = response.body.getReader();
14
+ const chunks = [];
15
+ let receivedLength = 0;
16
+ while (true) {
17
+ const { done, value } = await reader.read();
18
+ if (done) {
19
+ break;
20
+ }
21
+ chunks.push(value);
22
+ receivedLength += value.length;
23
+ onProgress(receivedLength);
24
+ }
25
+ let position = 0;
26
+ const chunksAll = new Uint8Array(receivedLength);
27
+ for (const chunk of chunks) {
28
+ chunksAll.set(chunk, position);
29
+ position += chunk.length;
30
+ }
31
+ return chunksAll;
32
+ };
@@ -0,0 +1,15 @@
1
+ import { type WhisperWebModel } from './constants';
2
+ export type DownloadWhisperModelProgress = {
3
+ downloadedBytes: number;
4
+ totalBytes: number;
5
+ progress: number;
6
+ };
7
+ export type DownloadWhisperModelOnProgress = (progress: DownloadWhisperModelProgress) => void;
8
+ export interface DownloadWhisperModelParams {
9
+ model: WhisperWebModel;
10
+ onProgress: DownloadWhisperModelOnProgress;
11
+ }
12
+ export type DownloadWhisperModelResult = {
13
+ alreadyDownloaded: boolean;
14
+ };
15
+ export declare const downloadWhisperModel: ({ model, onProgress, }: DownloadWhisperModelParams) => Promise<DownloadWhisperModelResult>;
@@ -0,0 +1,48 @@
1
+ import { canUseWhisperWeb } from './can-use-whisper-web';
2
+ import { MODELS, SIZES } 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
+ export const downloadWhisperModel = async ({ model, onProgress, }) => {
8
+ if (!model || !MODELS.includes(model)) {
9
+ throw new Error(`Invalid model name: ${model}. Supported models: ${MODELS.join(', ')}.`);
10
+ }
11
+ const usabilityCheck = await canUseWhisperWeb(model);
12
+ if (!usabilityCheck.supported) {
13
+ return Promise.reject(new Error(`Whisper.wasm is not supported in this environment. Reason: ${usabilityCheck.detailedReason}`));
14
+ }
15
+ const url = getModelUrl(model);
16
+ const modelSize = SIZES[model];
17
+ const existingModel = await getObject({ key: url });
18
+ if (existingModel) {
19
+ onProgress({
20
+ downloadedBytes: modelSize,
21
+ totalBytes: modelSize,
22
+ progress: 1,
23
+ });
24
+ return {
25
+ alreadyDownloaded: true,
26
+ };
27
+ }
28
+ const data = await fetchRemote({
29
+ url,
30
+ onProgress: (bytes) => {
31
+ onProgress({
32
+ downloadedBytes: bytes,
33
+ progress: bytes / modelSize,
34
+ totalBytes: modelSize,
35
+ });
36
+ },
37
+ expectedLength: modelSize,
38
+ });
39
+ onProgress({
40
+ downloadedBytes: modelSize,
41
+ totalBytes: modelSize,
42
+ progress: 1,
43
+ });
44
+ await putObject({ key: url, value: data });
45
+ return {
46
+ alreadyDownloaded: false,
47
+ };
48
+ };