Doubao-powered voice input for Linux, Wayland and Omarchy
fix(asr): parse Seed results and restore readiness
quanrua332bd8ef41b
diff --git a/src/doubao_input/app.py b/src/doubao_input/app.pyindex 8a40a6b..3fb562c 100644--- a/src/doubao_input/app.py+++ b/src/doubao_input/app.py@@ -926,6 +926,10 @@ class DoubaoInputApp(Gtk.Application):finished = Trueprobe.disconnect()self._asr_probe = None+ if not error:+ self._sync_recognition_status()+ if self._control:+ self._control.refresh()GLib.idle_add(completed, result, error)# The server's initial protocol response is the credential/resource# acknowledgement. No microphone data is needed for this settings test.diff --git a/src/doubao_input/doubao/volcengine_protocol.py b/src/doubao_input/doubao/volcengine_protocol.pyindex a58102d..8218b3a 100644--- a/src/doubao_input/doubao/volcengine_protocol.py+++ b/src/doubao_input/doubao/volcengine_protocol.py@@ -127,10 +127,12 @@ def parse_response(data: bytes) -> SeedResponse:def result_text(message: dict | None) -> str:if not isinstance(message, dict):return ""- results = message.get("result")- if not isinstance(results, list):- return ""- for result in reversed(results):- if isinstance(result, dict) and isinstance(result.get("text"), str):- return result["text"].strip()+ result = message.get("result")+ if isinstance(result, dict) and isinstance(result.get("text"), str):+ return result["text"].strip()+ # Some compatible/legacy responses wrap result objects in a list.+ if isinstance(result, list):+ for item in reversed(result):+ if isinstance(item, dict) and isinstance(item.get("text"), str):+ return item["text"].strip()return ""diff --git a/tests/test_app_edges.py b/tests/test_app_edges.pyindex e8270f7..06eff00 100644--- a/tests/test_app_edges.py+++ b/tests/test_app_edges.py@@ -147,6 +147,20 @@ class AppSetupEdgesTest(TestCase):self.assertFalse(manager.interactive_auth)self.assertFalse(manager.clear_rejected_credentials)+ def test_successful_official_key_probe_restores_readiness(self):+ completed = Mock()+ app = SimpleNamespace(_busy=lambda: False, _asr_probe=None,+ _sync_recognition_status=Mock(), _control=Mock())+ with patch("doubao_input.app.VolcengineASRClient") as client_type, \+ patch("doubao_input.app.GLib.idle_add") as idle_add:+ probe = client_type.return_value+ DoubaoInputApp._test_official_asr(app, "test-key", completed)+ probe.on_open()+ probe.disconnect.assert_called_once_with()+ app._sync_recognition_status.assert_called_once_with()+ app._control.refresh.assert_called_once_with()+ idle_add.assert_called_once_with(completed, "API key accepted", "")+def test_microphone_selection_uses_normal_settings_pipeline(self):app = SimpleNamespace(settings=Settings(microphone=""), apply_settings=Mock())DoubaoInputApp._apply_microphone(app, "desk-mic")diff --git a/tests/test_volcengine_asr_client.py b/tests/test_volcengine_asr_client.pyindex 43f9667..c3cf9e0 100644--- a/tests/test_volcengine_asr_client.py+++ b/tests/test_volcengine_asr_client.py@@ -42,7 +42,7 @@ class FakeSocket:self.sent.append(packet)if len(packet) >= 2 and packet[1] == 0x23:await self.queue.put(response(- {"result": [{"text": "official result"}]}, sequence=-2, last=True))+ {"result": {"text": "official result"}}, sequence=-2, last=True))self.final_sent.set()async def recv(self):diff --git a/tests/test_volcengine_protocol.py b/tests/test_volcengine_protocol.pyindex e5fab01..0e972ec 100644--- a/tests/test_volcengine_protocol.py+++ b/tests/test_volcengine_protocol.py@@ -49,10 +49,12 @@ class VolcengineProtocolTest(unittest.TestCase):def test_response_parses_final_text_and_service_errors(self):response = parse_response(server_response(- {"result": [{"text": "hello"}]}, sequence=-3, last=True))+ {"result": {"text": "hello", "utterances": []}},+ sequence=-3, last=True))self.assertTrue(response.is_last)self.assertEqual(response.sequence, -3)self.assertEqual(result_text(response.message), "hello")+ self.assertEqual(result_text({"result": [{"text": "legacy"}]}), "legacy")rejected = parse_response(server_response({"message": "denied"}, code=45000000))self.assertEqual(rejected.code, 45000000)