Skip to content

Doubao-powered voice input for Linux, Wayland and Omarchy

feat: separate polishing status with sparkle animation (#30)

Leyange24f85c4af61
diff --git a/.github/workflows/midscene-ubuntu-22.04.yml b/.github/workflows/midscene-ubuntu-22.04.yml
index fa22275..5f107b7 100644
--- a/.github/workflows/midscene-ubuntu-22.04.yml
+++ b/.github/workflows/midscene-ubuntu-22.04.yml
@@ -12,6 +12,7 @@ on:
- "tests/e2e/package.json"
- "tests/e2e/package-lock.json"
- "tests/e2e/gtk_fixture.py"
+ - "tests/e2e/polish_fixture.py"
- "tests/e2e/cases/**"
- "tests/e2e/midscene.config.ts"
- "src/**"
@@ -25,6 +26,7 @@ on:
- "tests/e2e/package.json"
- "tests/e2e/package-lock.json"
- "tests/e2e/gtk_fixture.py"
+ - "tests/e2e/polish_fixture.py"
- "tests/e2e/cases/**"
- "tests/e2e/midscene.config.ts"
- "src/**"
@@ -150,6 +152,10 @@ jobs:
exit 1
fi
+ - name: Verify polishing overlay with Midscene
+ working-directory: tests/e2e
+ run: timeout --signal=TERM --kill-after=10s 10m npm test -- --project ubuntu-polishing
+
- name: Upload Midscene report
if: always()
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
diff --git a/README.md b/README.md
index fd71deb..188d611 100644
--- a/README.md
+++ b/README.md
@@ -65,6 +65,10 @@ and troubleshooting.
### Optional voice polishing
+During polishing, a separate status row and softly pulsing stars sit above the
+transcript. A shortcut hint appears after three seconds; reduced motion keeps
+the stars static.
+
Turn on the **Voice polishing · Experimental** switch on the Trigger key page to configure an
OpenAI-compatible Base URL, API key, model and separate Chinese/English prompts.
Doubao Say selects a prompt from each transcript's dominant language. The bundled prompts remove
diff --git a/README.zh-CN.md b/README.zh-CN.md
index 5f7c334..b464564 100644
--- a/README.zh-CN.md
+++ b/README.zh-CN.md
@@ -49,6 +49,9 @@ API Key 保存在 `~/.config/doubao-say/volcengine_api_key`(或对应的
### 可选语音润色
+润色时,独立状态栏和缓慢闪烁的星星位于正文上方;等待三秒后显示快捷键提示。
+开启减少动态效果时,星星保持静止。
+
在“快捷键”页面打开**语音润色 · 实验特性**开关,可配置 OpenAI 兼容的 Base URL、API Key、模型和
中文与英文 Prompt;应用会根据每次转写的主要语言自动选择。内置 Prompt 会去除口水词、重复和口误,改善标点与结构,同时保留原意;用户可
自行修改,也可一键恢复默认内容。
diff --git a/src/doubao_input/app.py b/src/doubao_input/app.py
index 3879878..11791ba 100644
--- a/src/doubao_input/app.py
+++ b/src/doubao_input/app.py
@@ -480,7 +480,7 @@ class DoubaoInputApp(Gtk.Application):
self.recent.keep(text, "polishing")
self._control.set_result(text, tr("Polishing… press the trigger to use the original",
"正在润色…再次按快捷键可直接使用原文"))
- self._overlay.show(tr("Polishing…", "正在润色…"))
+ self._overlay.show_polishing(text)
self._polish_context = (text, self._target, send_enter)
if getattr(self, "_polish_mode", None) == "pre" and self._preview_polish.inflight == text and self._polisher.busy:
self._polish_mode = "final"
@@ -492,7 +492,6 @@ class DoubaoInputApp(Gtk.Application):
self._polisher.cancel()
self._polish_mode = "final"
logger.info("Starting final polish request")
- self._overlay.set_text(tr("Polishing · ", "润色中 · ") + text)
self._polisher.start(text, self.settings, api_key, self._polish_finished,
progress=self._polish_progress)
return
diff --git a/src/doubao_input/ui/overlay.py b/src/doubao_input/ui/overlay.py
index 284244f..66c2d58 100644
--- a/src/doubao_input/ui/overlay.py
+++ b/src/doubao_input/ui/overlay.py
@@ -80,6 +80,11 @@ class Overlay:
self._window: Gtk.Window | None = None
self._label: Gtk.Label | None = None
self._status_label: Gtk.Label | None = None
+ self._status_row = None
+ self._sparkles = []
+ self._hint_label = None
+ self._waveform = None
+ self._polishing_since = None
self._canvas: Gtk.Picture | None = None
self._panel: Gtk.Box | None = None
self._css_provider: Gtk.CssProvider | None = None
@@ -114,6 +119,34 @@ class Overlay:
def show(self, status: str | None = None) -> None:
self._run_on_main(self._show, status or tr("Listening…", "聆听中…"))
+ def show_polishing(self, text: str) -> None:
+ """Keep polishing activity separate from the transcript."""
+ self._run_on_main(self._show_polishing, text)
+
+ def _show_polishing(self, text: str) -> None:
+ self._show(tr("Polishing…", "润色中"))
+ self._polishing_since = time.monotonic()
+ self._waveform.set_visible(False)
+ self._status_label.set_xalign(0.0)
+ self._status_row.add_css_class("polishing-status")
+ self._status_row.set_tooltip_text(
+ tr("Press shortcut again to use original", "再次按快捷键使用原文"))
+ for star in self._sparkles:
+ star.set_opacity(1.0)
+ star.set_visible(True)
+ self._set_text(text)
+
+ def _clear_polishing(self) -> None:
+ self._polishing_since = None
+ if self._status_row is not None:
+ self._status_label.set_xalign(0.5)
+ self._status_row.remove_css_class("polishing-status")
+ self._status_row.set_tooltip_text(None)
+ self._hint_label.set_visible(False)
+ self._waveform.set_visible(True)
+ for star in self._sparkles:
+ star.set_visible(False)
+
def hide(self) -> None:
self._run_on_main(self._hide)
@@ -166,6 +199,7 @@ class Overlay:
def _show(self, status: str) -> None:
self._ensure_window()
+ self._clear_polishing()
self._text = ""
self._status_text = status
self._status_priority = True
@@ -176,6 +210,7 @@ class Overlay:
self._arm_ticker()
def _hide(self) -> None:
+ self._clear_polishing()
self._motion = VoiceMotion()
if self._update_button:
self._update_button.popdown()
@@ -201,6 +236,7 @@ class Overlay:
self._arm_ticker()
def _set_status(self, status: str) -> None:
+ self._clear_polishing()
self._status_text = status
self._status_priority = True
if self._window is not None:
@@ -213,7 +249,7 @@ class Overlay:
self._state = value
if self._css_provider is not None:
self._load_css()
- if not self._text:
+ if not self._text and self._polishing_since is None:
state_status = {
"starting": tr("Starting voice recognition…", "正在启动语音识别…"),
"recording": tr("Listening…", "正在聆听…"),
@@ -281,6 +317,7 @@ class Overlay:
canvas.set_can_shrink(False)
canvas.set_halign(Gtk.Align.CENTER)
waveform = Gtk.Overlay()
+ self._waveform = waveform
waveform.set_child(canvas)
self._update_button = Gtk.MenuButton(label="", visible=False)
self._update_button.set_direction(Gtk.ArrowType.NONE)
@@ -318,7 +355,15 @@ class Overlay:
self._status_label = Gtk.Label()
self._status_label.add_css_class("doubao-overlay-label")
- panel.append(self._status_label)
+ self._status_row = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=8)
+ self._status_row.set_halign(Gtk.Align.FILL)
+ self._status_label.set_hexpand(True)
+ self._status_row.append(self._status_label)
+ for glyph in ("✦", "✧", "✦"):
+ star = Gtk.Label(label=glyph, visible=False)
+ self._sparkles.append(star)
+ self._status_row.append(star)
+ panel.append(self._status_row)
label = Gtk.Label()
label.set_xalign(0.5)
@@ -329,6 +374,11 @@ class Overlay:
label.set_hexpand(True)
label.add_css_class("doubao-overlay-label")
panel.append(label)
+ self._hint_label = Gtk.Label(
+ label=tr("Press shortcut again to use original", "再次按快捷键使用原文"),
+ visible=False)
+ self._hint_label.add_css_class("doubao-polish-hint")
+ panel.append(self._hint_label)
self._window = win
self._panel = panel
@@ -342,6 +392,9 @@ class Overlay:
win.get_style_context().add_provider(
self._css_provider, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION
)
+ for widget in (self._status_row, self._status_label, self._hint_label, label):
+ widget.get_style_context().add_provider(
+ self._css_provider, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION)
win.set_child(panel)
self._render_canvas()
@@ -364,6 +417,16 @@ class Overlay:
border-radius: {CORNER_PX}px;
padding: 5px 15px 4px 15px;
}}
+ .polishing-status {{
+ color: {self._theme['accent']};
+ padding: 6px 0 10px 0;
+ margin-bottom: 8px;
+ }}
+ .doubao-polish-hint {{
+ font-size: 10px;
+ margin-top: 6px;
+ opacity: 0.7;
+ }}
.doubao-overlay-label {{
color: {self._theme['bright_foreground']};
font-size: 12px;
@@ -399,6 +462,14 @@ class Overlay:
now = time.monotonic()
elapsed = max(0.0, now - self._last_peak_tick)
self._last_peak_tick = now
+ if self._polishing_since is not None:
+ age = now - self._polishing_since
+ for index, star in enumerate(self._sparkles):
+ opacity = 1.0 if self.reduced_motion else (
+ 0.35 + 0.65 * (0.5 + 0.5 * math.sin(age * math.tau / 2.4 - index * 1.2)))
+ star.set_opacity(opacity)
+ self._hint_label.set_visible(age >= 3.0)
+ return GLib.SOURCE_CONTINUE
with self._audio_lock:
since_sample = max(0.0, now - self._latest_rms_at)
current_db = max(
diff --git a/tests/e2e/README.md b/tests/e2e/README.md
index 8ba26cd..d5e2515 100644
--- a/tests/e2e/README.md
+++ b/tests/e2e/README.md
@@ -112,3 +112,19 @@ ASR, recording, credential persistence, or global shortcut delivery.
Run `npm test -- --project ubuntu` with the system dependencies and model
configuration from the Ubuntu workflow. The Omarchy projects retain their shared
onboarding and shell cases.
+
+## Polishing overlay regression
+
+The Ubuntu workflow also runs `npm test -- --project ubuntu-polishing`.
+`polish_fixture.py` exposes test controls around the real Overlay component,
+using synthetic transcripts without microphone, network, or input injection.
+`cases/polishing.yaml` visually checks English and Chinese status/transcript
+separation, stars, absence of a divider, the delayed hint, streaming text updates,
+reduced-motion presentation, completion, and hiding. Timing and static-star
+behavior are additionally checked by `tests/manual/polish_overlay.py`; a still
+image alone does not prove animation or reduced-motion timing.
+
+The test shares the existing isolated desktop setup and model credentials.
+Inspect the HTML replay under `midscene_run/report/`. This component flow does not
+establish live ASR, polishing service, or paste acceptance, and does not add
+Wayland coverage for the overlay.
diff --git a/tests/e2e/cases/polishing.yaml b/tests/e2e/cases/polishing.yaml
new file mode 100644
index 0000000..0456502
--- /dev/null
+++ b/tests/e2e/cases/polishing.yaml
@@ -0,0 +1,17 @@
+cases:
+ - name: Polishing status stays separate from synthetic transcript
+ steps:
+ - aiAct: Click Start English polishing once in the Polishing overlay test controls window.
+ - aiAssert: A separate dark overlay shows Polishing at the upper left and three stars at the upper right. The transcript Please send the notes tomorrow. is below with clear space separating it from the status. No horizontal divider line appears inside the overlay.
+ - wait: { duration: 3500 }
+ - aiAssert: The overlay displays Press shortcut again to use original as a smaller secondary hint below the transcript.
+ - aiAct: Click Stream revised text once in the test controls window.
+ - aiAssert: The overlay transcript now reads Please send the meeting notes tomorrow. The Polishing status and stars remain in their own row above the transcript.
+ - aiAct: Click Start Chinese polishing once in the test controls window.
+ - aiAssert: The dark overlay displays 润色中 in its status row and 请明天发送会议纪要。 as separate text below, with three stars at the upper right and no horizontal divider.
+ - aiAct: Click Start reduced motion once in the test controls window.
+ - aiAssert: The overlay shows English Polishing status, three clearly visible stars, and the separate transcript Please send the notes tomorrow.
+ - aiAct: Click Finish polishing once in the test controls window.
+ - aiAssert: The overlay status reads Polished - Sending text and the three polishing stars have disappeared.
+ - aiAct: Click Hide overlay once in the test controls window.
+ - aiAssert: The dark transcript overlay is gone. The Polishing overlay test controls window remains visible.
diff --git a/tests/e2e/midscene.config.ts b/tests/e2e/midscene.config.ts
index 884d96b..2073b4e 100644
--- a/tests/e2e/midscene.config.ts
+++ b/tests/e2e/midscene.config.ts
@@ -73,6 +73,7 @@ const setup = defineProjectSetup<DesktopContext>({
async setup({ project, onTeardown }) {
const omarchy = project.name.startsWith('omarchy-');
const shell = project.name === 'omarchy-shell';
+ const polishing = project.name === 'ubuntu-polishing';
let desktopReady = false;
const createAgent = async () => {
const agent = await agentForComputer({
@@ -84,6 +85,7 @@ const setup = defineProjectSetup<DesktopContext>({
keepXvfbAliveUntilProcessExit: true,
aiContexts: shell
? { aiAssert: 'Inspect the real Omarchy desktop through VNC. Judge only visible pixels; do not infer success from commands or configuration.' }
+ : polishing ? { aiAct: 'Test the native polishing overlay using the separate Polishing overlay test controls window. Use visible button labels.' }
: { aiAct: `Test the English Doubao Say GTK onboarding window${omarchy ? ' inside a real Omarchy VM shown through VNC' : ''}. Interact only with Doubao Say and use visible labels.` },
});
desktopReady = true;
@@ -116,7 +118,7 @@ const setup = defineProjectSetup<DesktopContext>({
context.resetFixture = async () => {
await cleanup();
configDirectory = await mkdtemp(resolve(tmpdir(), 'doubao-midscene-'));
- fixture = spawn('/usr/bin/python3', ['tests/e2e/gtk_fixture.py'], {
+ fixture = spawn('/usr/bin/python3', [polishing ? 'tests/e2e/polish_fixture.py' : 'tests/e2e/gtk_fixture.py'], {
cwd: root, detached: true, stdio: ['ignore', 'pipe', 'pipe'],
env: {
...process.env, GDK_BACKEND: 'x11', GSK_RENDERER: 'cairo', GTK_A11Y: 'none',
@@ -177,6 +179,7 @@ const moveBarLeft = defineNode<typeof empty, void, DesktopContext>({
export default defineTestProject<DesktopContext>({
test: { maxConcurrency: 1, testTimeout: 8 * 60_000 },
projects: [
+ { name: 'ubuntu-polishing', setup, files: { include: ['cases/polishing.yaml'] } },
{ name: 'ubuntu', setup, files: { include: ['cases/onboarding.yaml', 'cases/onboarding-regressions.yaml'] } },
{ name: 'omarchy-onboarding', setup, files: { include: ['cases/onboarding.yaml'] } },
{ name: 'omarchy-shell', setup, files: { include: ['cases/omarchy-shell.yaml'] } },
diff --git a/tests/e2e/polish_fixture.py b/tests/e2e/polish_fixture.py
new file mode 100644
index 0000000..79a42f3
--- /dev/null
+++ b/tests/e2e/polish_fixture.py
@@ -0,0 +1,60 @@
+"""Native polishing overlay fixture; no microphone, network, or input injection."""
+import signal
+
+import gi
+
+gi.require_version("Gtk", "4.0")
+from gi.repository import GLib, Gtk
+
+from doubao_input.i18n import set_language
+from doubao_input.ui.overlay import Overlay
+
+
+def main():
+ Gtk.init()
+ set_language("en")
+ overlay = Overlay()
+ window = Gtk.Window(title="Polishing overlay test controls")
+ window.set_default_size(480, 320)
+ box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=12)
+ for side in ("start", "end", "top", "bottom"):
+ getattr(box, "set_margin_" + side)(24)
+ window.set_child(box)
+ box.append(Gtk.Label(label="Synthetic polishing preview - no live service"))
+
+ def start(language="en", reduced=False):
+ set_language(language)
+ overlay.hide()
+ overlay.reduced_motion = reduced
+ overlay.show_polishing("Please send the notes tomorrow." if language == "en"
+ else "请明天发送会议纪要。")
+
+ actions = [
+ ("Start English polishing", lambda: start()),
+ ("Stream revised text", lambda: overlay.set_text("Please send the meeting notes tomorrow.")),
+ ("Start Chinese polishing", lambda: start("zh_CN")),
+ ("Start reduced motion", lambda: start(reduced=True)),
+ ("Finish polishing", lambda: overlay.set_status("Polished - Sending text…")),
+ ("Hide overlay", overlay.hide),
+ ]
+ for title, callback in actions:
+ button = Gtk.Button(label=title)
+ button.connect("clicked", lambda _button, action=callback: action())
+ box.append(button)
+ loop = GLib.MainLoop()
+ signal.signal(signal.SIGTERM, lambda *_: GLib.idle_add(loop.quit))
+ signal.signal(signal.SIGINT, lambda *_: GLib.idle_add(loop.quit))
+ window.connect("close-request", lambda *_: loop.quit())
+ try:
+ window.present()
+ print("READY: synthetic Doubao Say GTK fixture", flush=True)
+ loop.run()
+ finally:
+ overlay.hide()
+ if overlay._window:
+ overlay._window.destroy()
+ window.destroy()
+
+
+if __name__ == "__main__":
+ main()
diff --git a/tests/manual/polish_overlay.py b/tests/manual/polish_overlay.py
new file mode 100644
index 0000000..d84b347
--- /dev/null
+++ b/tests/manual/polish_overlay.py
@@ -0,0 +1,48 @@
+"""Opt-in GTK check of polishing status, animation and cleanup; no audio/input."""
+from unittest.mock import patch
+
+from safety import hard_deadline
+from doubao_input.i18n import set_language
+from doubao_input.ui.overlay import Gtk, Overlay
+
+
+def main():
+ Gtk.init()
+ overlay = Overlay()
+ try:
+ for language, status in (("en", "Polishing…"), ("zh_CN", "润色中")):
+ set_language(language)
+ overlay.show_polishing("Example transcript")
+ assert overlay._label.get_text() == "Example transcript"
+ assert overlay._status_label.get_text() == status
+ assert not overlay._waveform.get_visible()
+ assert not overlay._hint_label.get_visible()
+ assert overlay._status_row.has_css_class("polishing-status")
+ with patch("doubao_input.ui.overlay.time.monotonic",
+ return_value=overlay._polishing_since + 3.5):
+ overlay._tick()
+ assert overlay._hint_label.get_visible()
+ assert any(star.get_opacity() < 0.95 for star in overlay._sparkles)
+ overlay.reduced_motion = True
+ overlay._tick()
+ assert all(star.get_opacity() == 1 for star in overlay._sparkles)
+ overlay.reduced_motion = False
+ overlay.set_text("Polished transcript")
+ assert overlay._status_label.get_text() == status
+ overlay.set_status("Sending text…")
+ assert overlay._polishing_since is None
+ assert overlay._waveform.get_visible()
+ assert not any(star.get_visible() for star in overlay._sparkles)
+ assert not overlay._hint_label.get_visible()
+ overlay.hide()
+ assert overlay._ticker_src is None
+ print("PASS: bilingual polishing status, animation, reduced motion and cleanup")
+ finally:
+ overlay.hide()
+ if overlay._window:
+ overlay._window.destroy()
+
+
+if __name__ == "__main__":
+ with hard_deadline():
+ main()
diff --git a/tests/unit/test_product.py b/tests/unit/test_product.py
index bd01bfd..6dfa894 100644
--- a/tests/unit/test_product.py
+++ b/tests/unit/test_product.py
@@ -129,7 +129,7 @@ class ProductTest(TestCase):
"raw transcript", app.settings, "key", app._polish_finished,
progress=app._polish_progress)
- def test_polishing_overlay_starts_with_labeled_original_text(self):
+ def test_polishing_overlay_keeps_status_separate_from_original_text(self):
app = polishing_app(_setup_session=Mock(), settings=Settings(polish_enabled=True),
recent=RecentResult(), _control=Mock(), _overlay=Mock(), _target="target",
_enter_after_paste=False, _polish_context=None, _polisher=Mock(),
@@ -140,8 +140,8 @@ class ProductTest(TestCase):
app._setup_session.complete_voice.return_value = False
app._polisher.busy = False
DoubaoInputApp._do_paste(app, "raw transcript")
- app._overlay.show.assert_called_once_with("Polishing…")
- app._overlay.set_text.assert_called_once_with("Polishing · raw transcript")
+ app._overlay.show_polishing.assert_called_once_with("raw transcript")
+ app._overlay.set_text.assert_not_called()
def test_trigger_cancels_polishing_and_uses_original(self):
app = polishing_app(_polish_context=("raw", "target", False),