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:
@@ -285,6 +285,13 @@ class Transcribe(commands.Cog):
|
||||
"Language detection isn't installed. Reinstall the cog so its "
|
||||
"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:
|
||||
guesses = detect_langs(text)
|
||||
except LangDetectException as exc:
|
||||
|
||||
Reference in New Issue
Block a user