Mercurial
view dictation/webrtc_smoke.py @ 279:b3b547563ec7
Add Google connector service and agent wiki
Implement the C/Seobeo Google Drive and Gmail connector with encrypted OAuth storage, Zenbu authentication, browser testing, AI tool discovery, chunked HTTP decoding, and Bazel coverage. Consolidate repository guidance into progressive wiki documentation and enforce arena-first allocation for new first-party C code.
Co-authored-by: Copilot <[email protected]>
Copilot-Session: 84c338fd-0939-4bb3-b7f3-1062eb213e5d
| author | MrJuneJune <me@mrjunejune.com> |
|---|---|
| date | Mon, 17 Aug 2026 22:22:36 -0700 |
| parents | 78699f810817 |
| children |
line wrap: on
line source
from __future__ import annotations import argparse import asyncio import json from aiortc import RTCPeerConnection, RTCSessionDescription from aiortc.contrib.media import MediaPlayer import httpx async def run(server_url: str, audio_path: str, timeout: float) -> None: peer = RTCPeerConnection() channel = peer.createDataChannel("transcripts") player = MediaPlayer(audio_path) if player.audio is None: raise RuntimeError("Input file does not contain an audio track") peer.addTrack(player.audio) final_received = asyncio.Event() session_id = None @channel.on("message") def on_message(message): event = json.loads(message) print(json.dumps(event, ensure_ascii=False), flush=True) if event.get("type") == "transcript.final": final_received.set() try: offer = await peer.createOffer() await peer.setLocalDescription(offer) async with httpx.AsyncClient(timeout=timeout) as client: response = await client.post( f"{server_url}/api/webrtc/offer", json={ "sdp": peer.localDescription.sdp, "type": peer.localDescription.type, }, ) response.raise_for_status() answer = response.json() session_id = answer["sessionId"] await peer.setRemoteDescription( RTCSessionDescription( sdp=answer["sdp"], type=answer["type"], ) ) await asyncio.wait_for(final_received.wait(), timeout=timeout) await client.post( f"{server_url}/api/webrtc/session/{session_id}/close" ) finally: await peer.close() def main() -> None: parser = argparse.ArgumentParser() parser.add_argument("audio") parser.add_argument( "--server", default="http://127.0.0.1:8090", ) parser.add_argument("--timeout", type=float, default=60.0) args = parser.parse_args() asyncio.run(run(args.server.rstrip("/"), args.audio, args.timeout)) if __name__ == "__main__": main()