{"record":{"id":"60fa253f0ca838ff","repo":"moeru-ai/airi","slug":"web-speech-api-is-not-available-in-this-environmen","errorCode":null,"errorMessage":"Web Speech API is not available in this environment. It requires a browser context with SpeechRecognition support (Chrome, Edge, Safari).","messagePattern":"Web Speech API is not available in this environment\\. It requires a browser context with SpeechRecognition support \\(Chrome, Edge, Safari\\)\\.","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/stage-ui/src/libs/providers/providers/browser-web-speech-api/provider.ts","lineNumber":61,"sourceCode":"/**\n * Web Speech API Speech Recognition provider\n *\n * This is a free, browser-native STT solution that requires no API keys.\n * Available in Chrome, Edge, Safari, and other Chromium-based browsers.\n *\n * Limitations:\n * - Only works in browser contexts (Electron renderer, web browsers)\n * - Requires user permission for microphone access\n * - Language support depends on browser implementation\n * - Not available in Node.js or Tauri main process\n */\nexport function createWebSpeechAPIProvider(): TranscriptionProviderWithExtraOptions<string, WebSpeechAPIExtraOptions> {\n  // Check if Web Speech API is available\n  const isAvailable = typeof window !== 'undefined'\n    && ('webkitSpeechRecognition' in window || 'SpeechRecognition' in window)\n\n  if (!isAvailable) {\n    throw new Error('Web Speech API is not available in this environment. It requires a browser context with SpeechRecognition support (Chrome, Edge, Safari).')\n  }\n\n  const SpeechRecognition = (window as any).SpeechRecognition || (window as any).webkitSpeechRecognition\n\n  return {\n    transcription: (model: string, extraOptions?: WebSpeechAPIExtraOptions) => {\n      return {\n        baseURL: 'about:blank', // Web Speech API doesn't use HTTP endpoints\n        model: model || 'web-speech-api',\n        fetch: async (_request: RequestInfo | URL, _init?: RequestInit) => {\n          // Web Speech API does not support file-based transcription - it only supports live streaming\n          // Check if a file is provided in the request body and reject it\n          if (_init?.body) {\n            // If body is FormData, it likely contains a file\n            // If body is a Blob/File, it's definitely a file\n            const body = _init.body\n            if (body instanceof FormData || body instanceof Blob || body instanceof File) {\n              const error = new Error('Web Speech API does not support file-based transcription. It only supports live streaming from a MediaStream. Please use the streaming transcription API or select a different provider that supports file-based transcription.')","sourceCodeStart":43,"sourceCodeEnd":79,"githubUrl":"https://github.com/moeru-ai/airi/blob/27111382b4a79a7e983289d6e983a06af185ed0f/packages/stage-ui/src/libs/providers/providers/browser-web-speech-api/provider.ts#L43-L79","documentation":"Thrown by createWebSpeechAPIProvider() when the running environment has no window object or window lacks both SpeechRecognition and webkitSpeechRecognition. The Web Speech API is a browser-only, vendor-specific capability; without it the provider cannot construct a transcription client, so construction aborts. This is an environment capability check, not a runtime error.","triggerScenarios":"createWebSpeechAPIProvider() is called where typeof window === 'undefined' (Node.js, SSR, Tauri/Electron main process, a Web Worker) or in a browser without SpeechRecognition (Firefox, some Chromium embedded views with the flag disabled).","commonSituations":"Importing the provider during SSR/Node build or in the Electron main process. Running in Firefox, which lacks SpeechRecognition. Headless test environment (jsdom) without the API. Embedded WebView with the speech API disabled.","solutions":["Only construct the provider in a supported browser renderer context (Chromium-based browser, Edge, Safari, Electron renderer with the API enabled).","Guard construction: check 'SpeechRecognition' in window || 'webkitSpeechRecognition' in window before calling createWebSpeechAPIProvider().","In Firefox or unsupported environments, choose a different transcription provider (e.g. Whisper, Aliyun NLS).","For SSR/build, dynamic-import the provider inside an onMounted or client-only guard so it is never evaluated in Node."],"exampleFix":"// before\nconst provider = createWebSpeechAPIProvider()\n// after\nconst canUseWebSpeech = typeof window !== 'undefined'\n  && ('SpeechRecognition' in window || 'webkitSpeechRecognition' in window)\nif (!canUseWebSpeech)\n  throw new Error('Web Speech API unsupported in this browser; pick another transcription provider')\nconst provider = createWebSpeechAPIProvider()","handlingStrategy":"type-guard","validationCode":"function isWebSpeechSupported(): boolean {\n  return typeof window !== 'undefined'\n    && ('webkitSpeechRecognition' in window || 'SpeechRecognition' in window)\n}\n// before constructing the provider:\nif (!isWebSpeechSupported()) {\n  // pick another transcription provider; do not call createWebSpeechAPIProvider()\n}","typeGuard":"function isWebSpeechSupported(): boolean {\n  return typeof window !== 'undefined'\n    && ('webkitSpeechRecognition' in window || 'SpeechRecognition' in window)\n}","tryCatchPattern":"try {\n  const provider = createWebSpeechAPIProvider()\n}\ncatch (err) {\n  if (err instanceof Error && err.message.startsWith('Web Speech API is not available')) {\n    // fall back to a server-side transcription provider (Whisper, Aliyun NLS)\n  }\n  else throw err\n}","preventionTips":["Dynamic-import the provider inside onMounted/client-only guards so SSR/build never evaluates it.","Feature-detect SpeechRecognition before offering Web Speech as a transcription option.","In Firefox, do not surface Web Speech as an available provider."],"tags":["browser-support","web-speech-api","environment","precondition","transcription"],"backgroundTag":null,"analyzedSha":"27111382b4a79a7e983289d6e983a06af185ed0f","analyzedAt":"2026-08-12T18:33:34.132Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}