Skip to content

朗读与提示 ​

单独朗读一段文本(不上字幕)、给用户弹提示、把窗口从录屏/投屏里隐藏。


朗读(独立 TTS) ​

python
host.speak(text: str, voice: str | None = None, language: str | None = None) -> bool
host.stop_speak() -> bool
host.is_speaking() -> bool
  • 不上字幕,只合成并播放;失败返回 False(不抛异常)。
  • voice / language 省略时用当前 TTS 引擎的默认音色 / 目标语言。
  • stop_speak() 中断当前轻量朗读队列。
  • 需要「翻译 + 字幕 + 朗读」一体的,用 feed_direct_caption(..., tts=True)——不要 speak() + feed() 拼。

界面提示 ​

python
host.show_toast(message: str, level: str = "info", timeout_ms: int = 2500) -> bool
host.show_error(message: str, source: str = "plugin") -> bool
  • show_toast:level ∈ info | success | warning | error;走宿主统一 Toast 通道。 适合「设备切换中」「已注册音色」这类轻提示。
  • show_error:写入宿主的 errorOccurred 通道(与内置错误同一 UI),适合真的出错。
  • 两者都是信号进 UI,任意线程可调。
  • 面向用户的文案要说人话(不要暴露内部异常栈);堆栈走 host.log("error", ...)。

防录屏 / 防投屏 ​

python
host.set_window_excluded_from_capture(window: Any, exclude: bool = True) -> bool
  • Windows 下走 SetWindowDisplayAffinity(0x00000011):该窗口在腾讯会议 / Zoom / Teams 等屏幕共享中完全隐形。
  • 非 Windows 平台返回 False。
  • window 传 QML 侧窗口实例:bridge.setWindowExcludedFromCapture(this, true)。

Copilot 窗口控制 ​

python
host.set_copilot_visible(visible: bool) -> bool
host.toggle_copilot_window() -> bool

仅当插件挂了 copilot_window 插槽、或本身是 assistant 类插件时才有意义; 其它插件可以忽略。


用法建议 ​

需求用
划词后念一下译文host.speak(translation)
念译文 + 同时上字幕host.feed_direct_caption(text, tts=True)
打断当前朗读host.stop_speak()
轻提示(1~3 秒)host.show_toast("…", level="info")
真错误host.show_error("人话原因", source=self.id)
面试助手防窥bridge.setWindowExcludedFromCapture(this, true)

相关 ​

TransBox - 赋能全人类无界限跨语言交流