diff --git a/README.md b/README.md index 3d3ed17..8f28025 100644 --- a/README.md +++ b/README.md @@ -1349,6 +1349,7 @@ Transcribe Discord voice messages with Whisper, and optionally translate them wi - `[p]transcribe` - Transcribe the message and translate it into English. - `[p]transcribe ` - Translate into another language, by English name (`french`) or ISO code (`fr`). +- `[p]translate ` - Translate the message you reply to (or text you type), with the source language detected automatically. Add `from ` when detection is unsure or you want to be explicit. - `[p]transcribeset showoriginal ` - Show the original text under a translation (default: on). Reply to a voice message, or just run the command and the newest voice message within the last 25 messages is used. Attachments are accepted too, as long as they are audio (`ogg`, `opus`, `wav`, `mp3`, `m4a`, `flac`, `webm`). @@ -1359,3 +1360,5 @@ The cog talks to two local services: - `nllb-server` on `127.0.0.1:8200` for translation (NLLB-200, GPU) English needs only the first one: Whisper's own `translate` task handles it in a single pass. Everything else transcribes first, then translates. If Whisper is less than 50% confident about which language it heard, the cog prints the transcript and skips the translation rather than translating a guess. + +`[p]translate` works on text instead of audio: reply to a message and give the target language. Source detection uses `langdetect` (declared in `info.json` requirements), refuses text shorter than 12 characters, and refuses when the top guess is under 70% or is within 15 points of a runner-up. Both refusals name the `from ` form rather than guessing. diff --git a/transcribe/transcribe.py b/transcribe/transcribe.py index 115db2b..6894a97 100644 --- a/transcribe/transcribe.py +++ b/transcribe/transcribe.py @@ -285,6 +285,13 @@ class Transcribe(commands.Cog): "Language detection isn't installed. Reinstall the cog so its " "requirements install, or use `[p]translate from `." ) + # Short strings get confident nonsense out of langdetect ("ok" reads as + # Slovak), so require enough text before trusting a guess. + if len(text.strip()) < 12: + raise ServiceError( + "That's too short to identify the language reliably. " + "Use `[p]translate from `." + ) try: guesses = detect_langs(text) except LangDetectException as exc: