Repository: vllm-project/vllm
File: vllm/entrypoints/openai/speech_to_text/speech_to_text.py (Python)

Code before:
            logger.info("Input processor warmup completed in %.2fs", warmup_elapsed)
        except Exception:
            # Don't fail initialization if warmup fails - log warning and continue
            logger.exception(
                "Input processor warmup failed (non-fatal): %s. "
                "First request may experience higher latency."
            )

    @cached_property
    def model_cls(self) -> type[SupportsTranscription]:
        from vllm.model_executor.model_loader import get_model_cls

        model_cls = get_model_cls(self.model_config)
        return cast(type[SupportsTranscription], model_cls)

    async def _detect_language(
        self,
        audio_chunk: np.ndarray,
        request_id: str,
    ) -> str:
        """Auto-detect the spoken language from an audio chunk.

        Delegates prompt construction and output parsing to the model class
        via ``get_language_detection_prompt`` and
        ``parse_language_detection_output``.  Falls back to ``"en"`` on any
        failure.
        """
        try:
            from vllm.sampling_params import SamplingParams

            prompt = self.model_cls.get_language_detection_prompt(
                audio_chunk,
                self.asr_config,
            )
            allowed_token_ids = self.model_cls.get_language_token_ids(
                self.tokenizer,
            )
            sampling_params = SamplingParams(
                max_tokens=1,
                temperature=0.0,
                allowed_token_ids=allowed_token_ids,
            )

            result_generator = self.engine_client.generate(
                prompt,
                sampling_params,
                request_id,
            )

            final_output: RequestOutput | None = None
            async for output in result_generator:

Review comment (bug):
don't have a strong opinion on fallback to en, but I've seen cases where failing was the preferred policy as it would "signal" to provide language tag manually.
We can also address this in a separate PR.  

Code after:

        model_cls = get_model_cls(self.model_config)
        return cast(type[SupportsTranscription], model_cls)

    async def _detect_language(
        self,
        audio_chunk: np.ndarray,
        request_id: str,
    ) -> str:
        """Auto-detect the spoken language from an audio chunk.

        Delegates prompt construction and output parsing to the model class
        via ``get_language_detection_prompt`` and
        ``parse_language_detection_output``.
        """
        from vllm.sampling_params import SamplingParams

        prompt = self.model_cls.get_language_detection_prompt(
            audio_chunk,
            self.asr_config,
        )
        allowed_token_ids = self.model_cls.get_language_token_ids(
            self.tokenizer,
        )
        sampling_params = SamplingParams(
            max_tokens=1,
            temperature=0.0,
            allowed_token_ids=allowed_token_ids,
        )

        result_generator = self.engine_client.generate(
            prompt,
            sampling_params,
            request_id,
        )

        final_output: RequestOutput
        async for final_output in result_generator:
            if final_output.finished:
                break

        token_ids = list(final_output.outputs[0].token_ids)
        lang = self.model_cls.parse_language_detection_output(
            token_ids,
            self.tokenizer,
        )

        logger.info("Auto-detected language: '%s'", lang)
        return lang

    async def _preprocess_speech_to_text(