transcribe: refuse to auto-detect very short text
langdetect labels 'ok' as Slovak with high confidence, so the probability gate alone was not enough. Require 12+ characters before guessing, and document the translate command in the README.
This commit is contained in:
@@ -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` - Transcribe the message and translate it into English.
|
||||||
- `[p]transcribe <language>` - Translate into another language, by English name (`french`) or ISO code (`fr`).
|
- `[p]transcribe <language>` - Translate into another language, by English name (`french`) or ISO code (`fr`).
|
||||||
|
- `[p]translate <language>` - Translate the message you reply to (or text you type), with the source language detected automatically. Add `from <language>` when detection is unsure or you want to be explicit.
|
||||||
- `[p]transcribeset showoriginal <true|false>` - Show the original text under a translation (default: on).
|
- `[p]transcribeset showoriginal <true|false>` - 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`).
|
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)
|
- `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.
|
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 <language>` form rather than guessing.
|
||||||
|
|||||||
@@ -285,6 +285,13 @@ class Transcribe(commands.Cog):
|
|||||||
"Language detection isn't installed. Reinstall the cog so its "
|
"Language detection isn't installed. Reinstall the cog so its "
|
||||||
"requirements install, or use `[p]translate <target> from <source>`."
|
"requirements install, or use `[p]translate <target> from <source>`."
|
||||||
)
|
)
|
||||||
|
# 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 <target> from <source>`."
|
||||||
|
)
|
||||||
try:
|
try:
|
||||||
guesses = detect_langs(text)
|
guesses = detect_langs(text)
|
||||||
except LangDetectException as exc:
|
except LangDetectException as exc:
|
||||||
|
|||||||
Reference in New Issue
Block a user