diff --git a/gateway/platforms/weixin.py b/gateway/platforms/weixin.py index 3eda50d30..026c84714 100644 --- a/gateway/platforms/weixin.py +++ b/gateway/platforms/weixin.py @@ -66,14 +66,6 @@ from gateway.platforms.base import ( from hermes_constants import get_hermes_home from utils import atomic_json_write -try: - import pilk - - PILK_AVAILABLE = True -except ImportError: # pragma: no cover - optional dependency - pilk = None # type: ignore[assignment] - PILK_AVAILABLE = False - ILINK_BASE_URL = "https://ilinkai.weixin.qq.com" WEIXIN_CDN_BASE_URL = "https://novac2c.cdn.weixin.qq.com/c2c" ILINK_APP_ID = "bot" @@ -1695,11 +1687,6 @@ class WeixinAdapter(BasePlatformAdapter): item_kwargs["encode_type"] = 6 item_kwargs["sample_rate"] = 24000 item_kwargs["bits_per_sample"] = 16 - if PILK_AVAILABLE: - try: - item_kwargs["playtime"] = pilk.get_duration(path) - except Exception as exc: - logger.warning("[%s] failed to read SILK duration for %s: %s", self.name, path, exc) media_item = item_builder(**item_kwargs) last_message_id = None diff --git a/tests/gateway/test_weixin.py b/tests/gateway/test_weixin.py index 211b9b8b5..95df61910 100644 --- a/tests/gateway/test_weixin.py +++ b/tests/gateway/test_weixin.py @@ -631,7 +631,7 @@ class TestWeixinVoiceSending: @patch.object(weixin, "_api_post", new_callable=AsyncMock) @patch.object(weixin, "_upload_ciphertext", new_callable=AsyncMock) @patch.object(weixin, "_get_upload_url", new_callable=AsyncMock) - def test_send_file_sets_voice_playtime_from_silk_duration( + def test_send_file_sets_voice_metadata_for_silk_payload( self, get_upload_url_mock, upload_ciphertext_mock, @@ -645,13 +645,11 @@ class TestWeixinVoiceSending: upload_ciphertext_mock.return_value = "enc-q" api_post_mock.return_value = {"success": True} - with patch("gateway.platforms.weixin.pilk.get_duration", return_value=1260) as duration_mock: - asyncio.run(adapter._send_file("wxid_test123", str(silk), "")) + asyncio.run(adapter._send_file("wxid_test123", str(silk), "")) - duration_mock.assert_called_once_with(str(silk)) payload = api_post_mock.await_args.kwargs["payload"] voice_item = payload["msg"]["item_list"][0]["voice_item"] - assert voice_item["playtime"] == 1260 + assert voice_item.get("playtime", 0) == 0 assert voice_item["encode_type"] == 6 assert voice_item["sample_rate"] == 24000 assert voice_item["bits_per_sample"] == 16