Skip to content

Captions & translation ​

Push text into the caption chain, or call the currently active MT engine directly.


feed_direct_caption — source text only ​

python
host.feed_direct_caption(
    text: str,
    lang: str = "auto",
    *,
    tts: bool = False,
    drop_noise: bool = False,
) -> bool
ParameterDescription
textSource text; an empty string returns False
langSource language, defaults to auto
ttsWhether to read the translation aloud; tools default to False
drop_noiseWhether to discard web noise such as ok / you; tools must pass False

Behaviour:

  • SI running: goes through the full caption / history / TTS policy.
  • Otherwise: lightweight path (MT + captions + history) — no ASR, no audio stream is opened.
  • If the user turned both "Source" and "Translation" off, they are turned on automatically (so you never end up "translated but invisible").

Compatible alias: feedDirectCaption(text, lang) ≡ feed_direct_caption(text, lang, tts=False, drop_noise=False).


feed_caption — you already have the translation ​

python
host.feed_caption(
    text: str,
    translation: str | None = None,
    lang: str = "auto",
    source: str = "plugin",
    *,
    tts: bool = False,
    drop_noise: bool = False,
) -> bool

When translation is non-empty, MT is skipped and the bilingual captions go up directly. Used for: selections that already carry a translation, caption-bridge frame patches, and so on.

source is written into the history record (defaults to "plugin"; the internal lightweight path uses "select", browser captions use "web").


translate / translate_batch ​

python
host.translate(text: str, source: str = "auto", target: str = "zh",
               glossary_context: str | None = None) -> str

host.translate_batch(texts: list[str], source: str = "auto", target: str = "zh",
                     *, glossary_context: str | None = None) -> list[str]
  • Goes through the currently active BaseMTEngineProvider.translate.
  • Failures return an empty string and never raise (failed entries in translate_batch are empty strings too).
  • glossary_context is passed through to the active MT (see mt).

Which one to use ​

SituationUse
Source text only, and you want the host to handle the whole chain (including read-aloud)feed_direct_caption(..., tts=True)
Source text only, and you do not want read-aloudfeed_direct_caption(...)
You already have the translation (selection / externally synced captions)feed_caption(text, translation, source=…)
You only want to translate a piece of text quietly, without publishing captionstranslate()
You need "translation + captions + read-aloud" as one unitfeed_direct_caption(..., tts=True) — do not stitch speak() + feed() together

TransBox — empowering borderless cross-language communication for everyone