@juspay/neurolink
Version:
The pipe layer of an AI nervous system: one interface connecting provider neurons to your application, across three inference types — generate, stream and decide. `decide` returns typed, calibrated judgements from a non-generative model (~400ms, ~$0.00002
43 lines (42 loc) • 1.73 kB
TypeScript
/**
* Transcribe WebSocket — `transcribeStream()` over a socket.
*
* Protocol (one transcription per connection):
* 1. The client's first frame is TEXT: a JSON config with the fields of
* `POST /agent/transcribe` minus the audio (`provider`, `model`,
* `language`, `dictionary`, `correction`, `fallback`, `streaming` …).
* 2. Then BINARY frames of PCM16LE mono audio at `streaming.sampleRate`
* (default 16000).
* 3. A TEXT frame `{"type":"end"}` (or closing the socket) ends the audio; the
* server flushes the last utterance.
*
* The server sends one TEXT frame per `TranscribeStreamEvent` (JSON), then
* closes with 1000. A bad config is answered with an `error` event and close
* code 1008.
*
* The route adapters do not handle upgrades, so this attaches to the Node
* `http.Server` the caller owns, next to whatever else is listening there; it
* answers only upgrades on its own path.
*
* @module server/websocket/transcribeWebSocket
*/
import type { Server as HttpServer } from "node:http";
import type { NeuroLink } from "../../neurolink.js";
import type { ServerTranscribeWebSocketOptions } from "../../types/index.js";
/**
* Serve `transcribeStream()` on `path` (default
* `/v1/audio/transcriptions/stream`) of an existing HTTP server.
*
* @example
* ```typescript
* const server = http.createServer(app);
* const ws = await attachTranscribeWebSocket(server, neurolink, {
* authToken: process.env.NEUROLINK_SERVER_API_KEY?.split(","),
* });
* server.listen(3000);
* // later: ws.close();
* ```
*/
export declare function attachTranscribeWebSocket(server: HttpServer, neurolink: NeuroLink, options?: ServerTranscribeWebSocketOptions): Promise<{
close: () => void;
}>;