docs: publish bridge with restructured markdown docs
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
"""Probe obmux with a record segment (voice message) to test the bridge path."""
|
||||
import asyncio
|
||||
import base64
|
||||
import json
|
||||
import sys
|
||||
import zlib
|
||||
|
||||
from websockets.asyncio.client import connect
|
||||
|
||||
CONFIG = json.load(open(r"C:\Users\GuoAn\.dsh\wechat-bridge\config.json", encoding="utf-8"))
|
||||
WAV = sys.argv[1] if len(sys.argv) > 1 else r"C:\Users\GuoAn\.dsh\wechat-bridge\tmp\tts_1794648113.wav"
|
||||
TARGET = sys.argv[2] if len(sys.argv) > 2 else "文件传输助手"
|
||||
|
||||
|
||||
def uid_of(name: str) -> int:
|
||||
return 8_000_000_000_000 + (zlib.crc32(name.encode("utf-8")) % 1_000_000)
|
||||
|
||||
|
||||
async def main() -> None:
|
||||
raw = open(WAV, "rb").read()
|
||||
b64 = "base64://" + base64.b64encode(raw).decode("ascii")
|
||||
headers = {"Authorization": f"Bearer {CONFIG['token']}"}
|
||||
async with connect(f"ws://127.0.0.1:{CONFIG['listen_port']}", additional_headers=headers) as ws:
|
||||
print("connected, sending voice", len(raw), "bytes")
|
||||
payload = {
|
||||
"action": "send_private_msg",
|
||||
"params": {"user_id": uid_of(TARGET), "message": [{"type": "record", "data": {"file": b64}}]},
|
||||
"echo": "probe-voice",
|
||||
}
|
||||
await ws.send(json.dumps(payload, ensure_ascii=False))
|
||||
deadline = asyncio.get_running_loop().time() + 90
|
||||
while asyncio.get_running_loop().time() < deadline:
|
||||
try:
|
||||
resp = await asyncio.wait_for(ws.recv(), timeout=deadline - asyncio.get_running_loop().time())
|
||||
except asyncio.TimeoutError:
|
||||
break
|
||||
msg = json.loads(resp)
|
||||
print("<-", json.dumps(msg, ensure_ascii=False)[:300])
|
||||
if msg.get("echo") == "probe-voice":
|
||||
break
|
||||
|
||||
|
||||
asyncio.run(main())
|
||||
Reference in New Issue
Block a user