{"record":{"id":"0ea090e7985bd381","repo":"moeru-ai/airi","slug":"2-recognition-already-running-this-is-normal-if","errorCode":null,"errorMessage":"2. Recognition already running - this is normal if called multiple times","messagePattern":"2\\. Recognition already running - this is normal if called multiple times","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"packages/stage-ui/src/libs/providers/providers/browser-web-speech-api/provider.ts","lineNumber":459,"sourceCode":"  recognition.onsoundend = () => {\n    console.info('Web Speech API sound ended')\n  }\n\n  recognition.onaudioend = () => {\n    console.info('Web Speech API audio capture ended')\n  }\n\n  recognition.onnomatch = () => {\n    console.info('Web Speech API: No speech match')\n  }\n\n  const started = startRecognition()\n  if (!started) {\n    // If immediate start failed, it might be a permission issue\n    // Web Speech API will prompt for permission automatically, so we just log\n    console.warn('Web Speech API recognition did not start immediately. This might be due to:')\n    console.warn('1. Microphone permission not granted - browser should prompt automatically')\n    console.warn('2. Recognition already running - this is normal if called multiple times')\n    console.warn('3. Browser requires user gesture - ensure microphone was enabled by user action')\n\n    // Don't retry immediately - wait for permission or user action\n    // The recognition instance is already created, so it can be started later if needed\n  }\n\n  return {\n    fullStream,\n    text: deferredText.promise,\n    textStream,\n    recognition: recognitionInstance,\n  }\n}\n","sourceCodeStart":441,"sourceCodeEnd":473,"githubUrl":"https://github.com/moeru-ai/airi/blob/677329427f32468c74b17f3ec47eeca4e05bec65/packages/stage-ui/src/libs/providers/providers/browser-web-speech-api/provider.ts#L441-L473","documentation":"Third line of the Web Speech API start-failure warn block: enumerated cause 2, 'Recognition already running - this is normal if called multiple times'. recognition.start() on an instance in the 'listening' state throws InvalidStateError, which startRecognition() converts to a false return. The log marks this as expected noise rather than a fault.","triggerScenarios":"Calling the provider twice without an intervening onend, re-invoking transcription while a previous session is still active, or restart logic that fires before the previous recognition fully stopped (between start and the onend event).","commonSituations":"Toggle handlers that do not debounce; auto-restart timers overlapping a still-running recognition; React/Vue strict-mode double effects in dev starting recognition twice.","solutions":["Track a running flag set in recognition.onstart and cleared in recognition.onend; only call start() when it is false","Call recognition.abort() before re-starting if you intentionally want a fresh session","Debounce or serialize start requests from UI toggles","Treat this specific occurrence as benign - transcription continues from the already-running instance"],"exampleFix":"// before\nfunction begin() {\n  try { recognition.start() } catch { /* double start throws */ }\n}\n\n// after\nconst running = ref(false)\nrecognition.onstart = () => { running.value = true }\nrecognition.onend = () => { running.value = false }\nfunction begin() {\n  if (!running.value) recognition.start()\n}","handlingStrategy":"validation","validationCode":"const running = ref(false)\nrecognition.onstart = () => { running.value = true }\nrecognition.onend = () => { running.value = false }\nif (!running.value)\n  startRecognition()","typeGuard":null,"tryCatchPattern":"try {\n  recognition.start()\n}\ncatch (err) {\n  if ((err as DOMException).name === 'InvalidStateError')\n    return // already running\n  throw err\n}","preventionTips":["Maintain a running flag driven by onstart/onend events","Debounce UI toggles that start recognition","Call abort() before intentionally restarting a session"],"tags":["web-speech-api","invalid-state","double-start","speech-recognition"],"backgroundTag":"invalid-state-error","analyzedSha":"677329427f32468c74b17f3ec47eeca4e05bec65","analyzedAt":"2026-08-18T17:29:58.153Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}