Streaming AudioFlow over Ktor
The Ktor extension adds adapters between Kodio's AudioFlow and Ktor's WebSocket plumbing so you can stream live mic capture to a backend (or pull a remote stream into a Player) without reinventing the framing.
Wire format
The protocol is intentionally minimal:
Format header: the
AudioFormatis encoded withAudioFormat.encodeToByteArray(), prefixed with the four ASCII bytesKDIO, and sent as the first binary frame.Chunks: every subsequent binary frame is one raw PCM byte chunk in the declared format.
The constants live in AudioFlowWireFormat.
Send a recorder over WebSocket
Stream a live recording from a mobile/desktop client to a server endpoint:
AudioFlow.sendOverWebSocket opens the socket, sends the format header, forwards every chunk as a binary frame, and closes cleanly.
For an already-open session, use AudioFlow.sendInto(session).
Receive an AudioFlow on the server
A Ktor server can read the same protocol with one call:
WebSocketSession.receiveAudioFlow() is for server-side handlers that already manage the session lifecycle.
Pull an AudioFlow from a server
Fetch a server-pushed AudioFlow and play it:
To collect the stream into a recording first:
Or use the block overload for manual control:
SSE fallback
The current release ships WebSocket support only. SSE-based delivery (for environments where WebSockets are blocked) is planned as a follow-up and will re-use the same KDIO-prefixed header. Track GitHub issue #6 for status.
Maven coordinates
This module declares kodio-core, ktor-client-core, and ktor-client-websockets as api dependencies. Bring your own engine (ktor-client-cio, ktor-client-darwin, ktor-client-js, and so on).