from typing import Optional from langdetect import detect def detect_lang(text: str, whisper_lang: Optional[str] = None) -> str: """ Détecte la langue du texte. Utilise d'abord Whisper si fourni, sinon langdetect. Retourne un code simple ('fr' pour français, sinon code ISO approximatif). """ if whisper_lang: return whisper_lang try: code = detect(text) return code except Exception: return "unknown"