Skip to content

Doubao-powered voice input for Linux, Wayland and Omarchy

feat(onboarding): configure official ASR inline

quanru399693760a92
diff --git a/docs/volcengine-asr.md b/docs/volcengine-asr.md
index a13d648..da64350 100644
--- a/docs/volcengine-asr.md
+++ b/docs/volcengine-asr.md
@@ -34,8 +34,8 @@ Official references:
## Configure Doubao Say
1. On the initial **Sign in** page, switch **Recognition service** to **Volcengine official API**. You can also switch it later under **Settings → Recognition service**; both controls save immediately and stay in sync.
-2. Select **Open recognition settings**.
-3. Paste the API key. It saves automatically.
+2. Paste the key into the API Key field that appears on the sign-in page. It saves automatically. The new console does not require an App ID or Access Key.
+3. To replace the key later, you can also use **Settings → Recognition service**.
4. Select **Test API key**. A successful test verifies authentication and entitlement without uploading a recording.
5. Run the real voice test. Incremental text should appear in the overlay before recording finishes.
diff --git a/docs/volcengine-asr.zh-CN.md b/docs/volcengine-asr.zh-CN.md
index dd11407..5ed0338 100644
--- a/docs/volcengine-asr.zh-CN.md
+++ b/docs/volcengine-asr.zh-CN.md
@@ -39,8 +39,8 @@
## 在豆包说中配置
1. 在首次设置的“登录”页直接把“语音识别服务”切换为“火山引擎官方 API”;也可以稍后在“设置 → 语音识别服务”中切换。两处会立即保存并保持同步。
-2. 点击“打开语音识别设置”。
-3. 粘贴刚才创建的 API Key。修改会自动保存,不需要额外点击保存。
+2. 在登录页出现的 API Key 输入框中粘贴刚才创建的 Key。修改会自动保存,不需要额外点击保存。新版控制台不需要填写 App ID 或 Access Key。
+3. 如需以后更换 Key,也可打开“设置 → 语音识别服务”。
4. 点击“测试 API Key”。看到“API Key 可用”只代表鉴权和服务权限正常,不会上传录音。
5. 回到引导页执行“试说一句”。说话过程中应在悬浮窗看到增量文字,结束后得到最终结果。
diff --git a/src/doubao_input/app.py b/src/doubao_input/app.py
index a7addf2..cd293ff 100644
--- a/src/doubao_input/app.py
+++ b/src/doubao_input/app.py
@@ -234,6 +234,9 @@ class DoubaoInputApp(Gtk.Application):
test_polish=self._test_polish,
apply_microphone=self._apply_microphone,
apply_asr_provider=self._apply_asr_provider,
+ asr_has_key=self._official_has_key,
+ save_asr=self._save_official_key,
+ test_asr=self._test_official_asr,
),
)
self._update_checker = UpdateChecker(GLib.idle_add, self._update_available)
diff --git a/src/doubao_input/ui/control_window.py b/src/doubao_input/ui/control_window.py
index 0621246..6f9041f 100644
--- a/src/doubao_input/ui/control_window.py
+++ b/src/doubao_input/ui/control_window.py
@@ -42,6 +42,12 @@ class ControlWindow:
self._login_button = None
self._asr_provider = None
self._changing_asr_provider = False
+ self._asr_details = None
+ self._asr_key = None
+ self._asr_key_save_source = 0
+ self._asr_test_button = None
+ self._asr_status = None
+ self._asr_testing = False
self._trigger_picker = None
self._microphone = None
self._microphone_sources = []
@@ -65,6 +71,9 @@ class ControlWindow:
picker.cancel()
if self._actions.is_preview_testing():
self._actions.cancel_preview()
+ flush = getattr(self, "_flush_asr_key", None)
+ if flush:
+ flush()
if self._window:
self._window.set_visible(False)
@@ -106,6 +115,9 @@ class ControlWindow:
self.show()
def destroy(self):
+ flush = getattr(self, "_flush_asr_key", None)
+ if flush:
+ flush()
if self._window:
self._window.destroy()
self._window = None
@@ -156,13 +168,15 @@ class ControlWindow:
"API Key 已保存 · 可在设置中测试连接,或继续进行试说。") if logged_in else tr(
"No API key saved. Add one in Settings to continue.",
"尚未保存 API Key,请前往设置填写后继续。"))
- self._login_button.set_label(tr("Open recognition settings", "打开语音识别设置"))
+ self._login_button.set_visible(False)
else:
self._account_status.set_text(tr("Signed in · saved on this device. Continue without signing in again; the voice test checks whether the session is still valid.",
"已登录 · 登录信息保存在本机。无需重复登录,可直接继续;语音测试会验证登录是否仍有效。") if logged_in else
tr("Not signed in. Connect your Doubao account to continue.", "尚未登录,请先连接豆包账号。"))
self._login_button.set_label(tr("Sign in again / change account", "重新登录或更换账号") if logged_in else
tr("Open Doubao sign-in", "打开豆包登录"))
+ self._login_button.set_visible(True)
+ self._asr_details.set_visible(official)
if official:
self._status_label.set_text(tr("Official API ready · test your voice to verify", "官方 API 已就绪 · 请试说一句验证")
if logged_in else tr("Add an API key to get started", "请先填写 API Key"))
@@ -309,13 +323,39 @@ class ControlWindow:
xalign=0, hexpand=True, wrap=True))
self._asr_provider = Gtk.DropDown.new_from_strings([
tr("Doubao account", "豆包账号"),
- tr("Volcengine official API", "火山引擎官方 API"),
+ tr("Volcengine API", "火山引擎 API"),
])
self._asr_provider.set_selected(ASR_PROVIDERS.index(
self._actions.summary().get("asr_provider", "doubao")))
self._asr_provider.connect("notify::selected", self._asr_provider_changed)
provider_row.append(self._asr_provider)
account.append(provider_row)
+
+ self._asr_details = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=10)
+ key_row = Gtk.Box(spacing=12)
+ key_row.add_css_class("settings-row")
+ key_row.append(Gtk.Label(label="API Key", xalign=0, hexpand=True, wrap=True))
+ self._asr_key = Gtk.Entry(visibility=False, hexpand=True)
+ self._asr_key.set_invisible_char("•")
+ has_key = self._actions.asr_has_key()
+ self._asr_key.set_placeholder_text(tr(
+ "Saved — leave blank to keep" if has_key else "Enter speech API key",
+ "已保存,留空则保持不变" if has_key else "填写语音 API Key"))
+ self._asr_key.connect("changed", self._queue_asr_key_save)
+ key_row.append(self._asr_key)
+ self._asr_details.append(key_row)
+ self._asr_details.append(label(tr(
+ "The new Doubao Speech console uses one API Key. Resource ID volc.seedasr.sauc.duration is built in. App ID and Access Key are only for the legacy console and are not required here.",
+ "新版豆包语音控制台只使用一个 API Key;资源 ID volc.seedasr.sauc.duration 已内置。App ID 和 Access Key 仅用于旧版控制台,这里不需要填写。"), secondary=True))
+ self._asr_test_button = Gtk.Button(label=tr("Test API key", "测试 API Key"))
+ self._asr_test_button.connect("clicked", self._test_asr_clicked)
+ self._asr_details.append(self._asr_test_button)
+ self._asr_status = label("")
+ self._asr_status.add_css_class("accent")
+ self._asr_details.append(self._asr_status)
+ self._asr_details.set_visible(
+ self._actions.summary().get("asr_provider") == "volcengine")
+ account.append(self._asr_details)
self._account_status = label("")
account.append(self._account_status)
self._login_button = button(account, tr("Open Doubao sign-in", "打开豆包登录"), self._on_login, True)
@@ -472,6 +512,71 @@ class ControlWindow:
"Recognition service switched. Configure its credentials below to continue.",
"语音识别服务已切换,请在下方配置对应凭证后继续。"))
+ def _queue_asr_key_save(self, *_):
+ if not self._asr_key or not self._asr_key.get_text().strip():
+ return
+ if self._asr_key_save_source:
+ GLib.source_remove(self._asr_key_save_source)
+ self._asr_key_save_source = GLib.timeout_add(500, self._run_asr_key_save)
+
+ def _run_asr_key_save(self):
+ self._asr_key_save_source = 0
+ self._save_asr_key_now()
+ return GLib.SOURCE_REMOVE
+
+ def _save_asr_key_now(self):
+ if not self._asr_key:
+ return self._actions.asr_has_key()
+ key = self._asr_key.get_text().strip()
+ if not key:
+ return self._actions.asr_has_key()
+ try:
+ self._actions.save_asr(key)
+ except (ValueError, OSError) as error:
+ self._asr_status.set_text(str(error))
+ return False
+ self._asr_key.set_placeholder_text(tr(
+ "Saved — leave blank to keep", "已保存,留空则保持不变"))
+ self._asr_status.set_text(tr(
+ "API key saved automatically.", "API Key 已自动保存。"))
+ return True
+
+ def _flush_asr_key(self):
+ if self._asr_key_save_source:
+ GLib.source_remove(self._asr_key_save_source)
+ self._asr_key_save_source = 0
+ self._save_asr_key_now()
+
+ def _test_asr_clicked(self, *_):
+ if self._asr_testing:
+ return
+ if self._asr_key_save_source:
+ GLib.source_remove(self._asr_key_save_source)
+ self._asr_key_save_source = 0
+ if not self._save_asr_key_now():
+ self._asr_status.set_text(tr(
+ "Enter an API key first.", "请先填写 API Key。"))
+ return
+ self._asr_testing = True
+ self._asr_test_button.set_sensitive(False)
+ self._asr_test_button.set_label(tr("Testing…", "正在测试…"))
+ self._asr_status.set_text(tr(
+ "Testing official recognition…", "正在测试官方语音识别…"))
+ try:
+ self._actions.test_asr(
+ self._asr_key.get_text().strip() or None, self._asr_tested)
+ except (ValueError, OSError) as error:
+ self._asr_tested(None, str(error))
+
+ def _asr_tested(self, result, error):
+ self._asr_testing = False
+ self._asr_test_button.set_sensitive(True)
+ self._asr_test_button.set_label(tr("Test API key", "测试 API Key"))
+ self._asr_status.set_text(
+ tr("Test failed: ", "测试失败:") + error if error else
+ (result or tr("API key accepted.", "API Key 可用。")))
+ return GLib.SOURCE_REMOVE
+
def _continue_from_trigger(self):
picker = self._trigger_picker
if picker.listening:
diff --git a/src/doubao_input/ui/setup_actions.py b/src/doubao_input/ui/setup_actions.py
index eac68cd..616861b 100644
--- a/src/doubao_input/ui/setup_actions.py
+++ b/src/doubao_input/ui/setup_actions.py
@@ -20,3 +20,6 @@ class SetupActions:
test_polish: Callable = lambda settings, key, done: None
apply_microphone: Callable[[str], None] = lambda device: None
apply_asr_provider: Callable[[str], None] = lambda provider: None
+ asr_has_key: Callable[[], bool] = lambda: False
+ save_asr: Callable[[str], None] = lambda key: None
+ test_asr: Callable = lambda key, done: None
diff --git a/tests/manual_control_layout.py b/tests/manual_control_layout.py
index 9fd10ed..553a742 100644
--- a/tests/manual_control_layout.py
+++ b/tests/manual_control_layout.py
@@ -17,7 +17,9 @@ from doubao_input.settings import Settings
def main():
Gtk.init()
+ summary = {"asr_provider": "volcengine"}
actions = SetupActions(lambda: None, lambda: None, lambda: None, lambda: False,
+ summary=lambda: summary,
polish_settings=lambda: Settings(polish_enabled=True))
for language in ("en", "zh_CN"):
set_language(language)
diff --git a/tests/test_setup_actions.py b/tests/test_setup_actions.py
index 9fc2948..98bbb34 100644
--- a/tests/test_setup_actions.py
+++ b/tests/test_setup_actions.py
@@ -101,6 +101,30 @@ class SetupActionsTest(unittest.TestCase):
control.set_feedback.assert_called_once_with("busy")
control._refresh.assert_called_once_with()
+ def test_onboarding_official_key_test_saves_first_and_shows_result(self):
+ control = SimpleNamespace(
+ _asr_testing=False,
+ _asr_key_save_source=0,
+ _asr_key=Mock(),
+ _asr_status=Mock(),
+ _asr_test_button=Mock(),
+ _actions=Mock(),
+ )
+ control._asr_key.get_text.return_value = "test-key"
+ control._save_asr_key_now = lambda: ControlWindow._save_asr_key_now(control)
+ control._asr_tested = lambda result, error: ControlWindow._asr_tested(
+ control, result, error)
+
+ ControlWindow._test_asr_clicked(control)
+
+ control._actions.save_asr.assert_called_once_with("test-key")
+ self.assertTrue(control._asr_testing)
+ completed = control._actions.test_asr.call_args.args[1]
+ completed("API key accepted", "")
+ self.assertFalse(control._asr_testing)
+ self.assertEqual(
+ control._asr_status.set_text.call_args.args[0], "API key accepted")
+
def test_endpoint_test_has_adjacent_loading_and_success_feedback(self):
view = SimpleNamespace(
_testing=False,