Skip to content

Instantly share code, notes, and snippets.

@eepytofu
Created May 24, 2026 04:25
Show Gist options
  • Select an option

  • Save eepytofu/ab0eebebd02d0c39504b46b5c1e87144 to your computer and use it in GitHub Desktop.

Select an option

Save eepytofu/ab0eebebd02d0c39504b46b5c1e87144 to your computer and use it in GitHub Desktop.
Windows Live Captions → WebSocket bridge
import asyncio
import uiautomation as auto
import websockets
PORT = 6677
def get_caption_text():
try:
window = auto.WindowControl(searchDepth=1, Name="Live Captions")
text_el = window.TextControl(searchDepth=20, AutomationId="CaptionsTextBlock")
return text_el.Name
except:
return None
async def handler(websocket):
print("Overlay connected!")
last_text = ""
try:
while True:
text = get_caption_text()
if text and text != last_text:
# only send the last non-empty line
lines = [l.strip() for l in text.splitlines() if l.strip()]
if lines:
await websocket.send(lines[-1])
last_text = text
await asyncio.sleep(0.3)
except websockets.exceptions.ConnectionClosed:
print("Overlay disconnected, waiting for reconnect...")
async def main():
print(f"Starting server on port {PORT}...")
async with websockets.serve(handler, "localhost", PORT):
await asyncio.Future()
asyncio.run(main())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment