{"record":{"id":"3e234b59e89ff9f1","repo":"microsoft/VibeVoice","slug":"streamingttsservice-not-initialized","errorCode":null,"errorMessage":"StreamingTTSService not initialized","messagePattern":"StreamingTTSService not initialized","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"demo/web/app.py","lineNumber":184,"sourceCode":"                    map_location=self._torch_device,\n                    weights_only=True,\n                )\n            self._voice_cache[key] = prefilled_outputs\n\n        return self._voice_cache[key]\n\n    def _get_voice_resources(self, requested_key: Optional[str]) -> Tuple[str, object, Path, str]:\n        key = requested_key if requested_key and requested_key in self.voice_presets else self.default_voice_key\n        if key is None:\n            key = next(iter(self.voice_presets))\n            self.default_voice_key = key\n\n        prefilled_outputs = self._ensure_voice_cached(key)\n        return key, prefilled_outputs\n\n    def _prepare_inputs(self, text: str, prefilled_outputs: object):\n        if not self.processor or not self.model:\n            raise RuntimeError(\"StreamingTTSService not initialized\")\n\n        processor_kwargs = {\n            \"text\": text.strip(),\n            \"cached_prompt\": prefilled_outputs,\n            \"padding\": True,\n            \"return_tensors\": \"pt\",\n            \"return_attention_mask\": True,\n        }\n\n        processed = self.processor.process_input_with_cached_prompt(**processor_kwargs)\n\n        prepared = {\n            key: value.to(self._torch_device) if hasattr(value, \"to\") else value\n            for key, value in processed.items()\n        }\n        return prepared\n\n    def _run_generation(","sourceCodeStart":166,"sourceCodeEnd":202,"githubUrl":"https://github.com/microsoft/VibeVoice/blob/94da20d98b2fa7688e9cbfaf7692ddb4954f7600/demo/web/app.py#L166-L202","documentation":"Raised by StreamingTTSService._prepare_inputs when self.processor or self.model is None, i.e. the method was called before service.load() finished assigning them. It is a guard against using the service in a half-constructed state, not a model error.","triggerScenarios":"Instantiating StreamingTTSService(model_path=..., device=...) and calling generate/prepare before .load(); load() failed partway (e.g. MODEL_PATH invalid) leaving attributes unset; a request reaching the handler before the startup event completed.","commonSituations":"Race in FastAPI: a request hits the TTS endpoint while the startup hook is still loading weights; an exception during load() was swallowed and the half-initialized service kept in app.state; unit tests constructing the service without load().","solutions":["Call service.load() once before any inference (the app startup event does this).","Make sure MODEL_PATH points to a valid model directory so load() does not fail partway.","Gate the TTS endpoint behind a readiness flag set only after startup completes, returning 503 until then.","In tests, always run load() (or mock both processor and model) before calling generate()."],"exampleFix":"# before\nservice = StreamingTTSService(model_path, device)\nservice._prepare_inputs(text, prefilled)  # RuntimeError\n\n# after\nservice = StreamingTTSService(model_path, device)\nservice.load()\nservice._prepare_inputs(text, prefilled)","handlingStrategy":"type-guard","validationCode":"def service_ready(service) -> bool:\n    return service is not None and service.processor is not None and service.model is not None","typeGuard":"def is_loaded(service) -> bool:\n    return getattr(service, \"processor\", None) is not None and getattr(service, \"model\", None) is not None","tryCatchPattern":"if not is_loaded(service):\n    raise HTTPException(status_code=503, detail=\"TTS service warming up\")\nreturn service.generate(...)","preventionTips":["Call service.load() in the startup hook before serving requests","Return 503 from endpoints until app.state.tts_service is fully loaded","Fail startup loudly if load() raises instead of keeping a half-initialized service"],"tags":["web-demo","lifecycle","not-initialized","race-condition"],"backgroundTag":null,"analyzedSha":"94da20d98b2fa7688e9cbfaf7692ddb4954f7600","analyzedAt":"2026-08-15T04:12:07.418Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}