🎥 Make videos programmatically with React
invalid model name doesn't mean we can't use whisper in the browser
Igor Samokhovetsd5fcf7dccd83
diff --git a/packages/docs/docs/whisper-wasm/can-use-whisper-wasm.mdx b/packages/docs/docs/whisper-wasm/can-use-whisper-wasm.mdxindex 4308d544dd..eb6c669ac2 100644--- a/packages/docs/docs/whisper-wasm/can-use-whisper-wasm.mdx+++ b/packages/docs/docs/whisper-wasm/can-use-whisper-wasm.mdx@@ -70,7 +70,6 @@ Possible values values include:- `not-cross-origin-isolated`: The page is not cross-origin isolated.- `indexed-db-unavailable`: IndexedDB is not available.- `navigator-storage-unavailable`: `navigator.storage.estimate()` API is not available.-- `invalid-model-name`: The provided model name is not valid.- `quota-undefined`: Storage quota could not be determined.- `usage-undefined`: Storage usage could not be determined.- `not-enough-space`: Insufficient storage space for the specified model.diff --git a/packages/whisper-wasm/src/can-use-whisper-wasm.ts b/packages/whisper-wasm/src/can-use-whisper-wasm.tsindex 588d510bf0..50420e2886 100644--- a/packages/whisper-wasm/src/can-use-whisper-wasm.ts+++ b/packages/whisper-wasm/src/can-use-whisper-wasm.ts@@ -1,12 +1,11 @@import type {WhisperWasmModel} from './constants';-import {MODELS, SIZES} from './constants';+import {SIZES} from './constants';export enum WhisperWasmUnsupportedReason {WindowUndefined = 'window-undefined',IndexedDbUnavailable = 'indexed-db-unavailable',NavigatorStorageUnavailable = 'navigator-storage-unavailable',StorageEstimationApiUnavailable = 'storage-estimation-api-unavailable',- InvalidModelName = 'invalid-model-name',QuotaUndefined = 'quota-undefined',UsageUndefined = 'usage-undefined',NotEnoughSpace = 'not-enough-space',@@ -58,16 +57,6 @@ export const canUseWhisperWasm = async (};}- if (!model || !MODELS.includes(model)) {- return {- supported: false,- reason: WhisperWasmUnsupportedReason.InvalidModelName,- detailedReason: `Invalid model name. Supported models: ${MODELS.join(- ', ',- )}.`,- };- }-try {const estimate = await navigator.storage.estimate();diff --git a/packages/whisper-wasm/src/download-whisper-model.ts b/packages/whisper-wasm/src/download-whisper-model.tsindex 84db29286c..360c6116c4 100644--- a/packages/whisper-wasm/src/download-whisper-model.ts+++ b/packages/whisper-wasm/src/download-whisper-model.ts@@ -1,5 +1,5 @@import {canUseWhisperWasm} from './can-use-whisper-wasm';-import type {WhisperWasmModel} from './constants';+import {MODELS, type WhisperWasmModel} from './constants';import {getObject} from './db/get-object-from-db';import {putObject} from './db/put-object';import {fetchRemote} from './download-model';@@ -18,6 +18,12 @@ export const downloadWhisperModel = async ({model,onProgress,}: DownloadWhisperModelParams): Promise<DownloadWhisperModelResult> => {+ if (!model || !MODELS.includes(model)) {+ throw new Error(+ `Invalid model name: ${model}. Supported models: ${MODELS.join(', ')}.`,+ );+ }+const usabilityCheck = await canUseWhisperWasm(model);if (!usabilityCheck.supported) {