Skip to main content
Capture and process audio in the browser and generate structured medical documentation through Eka Care’s voice transcription service. med-scribe-alliance-ts-sdk is the open-source MedScribe Alliance SDK. It gives you a ScribeClient that speaks the MedScribe Alliance protocol directly: discovery, recording, chunked upload, session lifecycle, output retrieval.

Prerequisites

  • Node 14+
  • npm or yarn
  • Microphone access via browser permissions
  • Stable network connectivity
  • An access token from Eka Care

Installation

Peer dependencies (installed automatically):
  • @ricky0123/vad-web — Voice Activity Detection
  • @breezystack/lamejs — MP3 encoding
  • zod — Schema validation
npm package →

Integration Guide (Step-by-Step)

Step 1: Create the Client

The baseUrl is required — every API call (session creation, upload, status polling) goes through it. If you leave it out, the SDK throws allianceConfig.baseUrl is required at runtime. To use Eka Care’s hosted scribe service, use:
Production APIs require a secure (HTTPS) origin. They will not work from http:// or http://localhost — an insecure origin fails the CORS preflight (the authorization header is rejected).Recommended: Use ngrok to give your local server a public HTTPS URL and test against the production baseUrl directly.Alternatively, point at the staging baseUrl (https://api.dev.eka.care/voice/v1) which works from plain localhost.

Step 2: Initialize (Discovery)

init() fetches the discovery document from the server. This tells the SDK what the server supports (models, languages, upload methods, audio formats, etc.).
startRecording() calls init() automatically if not already initialized. You can skip this step if you go directly to recording.

Step 3: Register Callbacks

Register callbacks before starting a recording. These are how you receive events from the SDK.

Step 4: Start Recording

Creates a session, starts the microphone, and begins chunked upload in one call.
Use clinical_notes_template for testing, or contact Eka Care to create a custom template for your use case.

Pause / Resume

Step 5: End Recording

Stops the microphone, flushes the last audio chunk, waits for all uploads to complete, and tells the server the session has ended (triggers server-side processing).

Step 6: Poll for Results

After ending the recording, poll the server until processing is complete.

Step 7: Clean Up

Flow Diagram


Important Notes

  • baseUrl is the root for all API calls. Session creation, audio upload, status polling — everything uses this URL. Make sure it’s correct and accessible.
  • accessToken must be a valid Bearer token. All API requests include Authorization: Bearer <token>. If it expires, register onTokenRequired to auto-refresh.
  • Register callbacks before startRecording(). Events fire immediately once recording starts — if callbacks aren’t registered, you’ll miss upload progress and errors.
  • endRecording() triggers server processing. Once you call it, the server begins processing the uploaded audio. Use cancelSession() instead if you don’t want processing to happen.
  • cancelSession() does NOT trigger processing. It stops the recorder locally, cleans up state, and tells the server the session is cancelled. No endSession call is made to the backend.
  • All async methods return SDKResult<T>, never throw. Always check result.success before accessing result.data. Errors are in result.error.
  • The SDK validates inputs against the discovery document. If the server doesn’t support an upload type, language, or model you requested, you’ll get a ValidationError before the API call is made.
  • SharedWorker is optional. If you provide workerScriptUrl, the SDK offloads MP3 compression and upload to a SharedWorker. If the worker fails to load, it silently falls back to main-thread processing.
  • Microphone permission is requested on startRecording(). The browser will prompt the user for mic access. If denied, you’ll get an error via onError callback.
  • reset() is a full teardown. It destroys the transport, clears discovery cache, removes all callbacks, and sets the client back to uninitialized state. You’ll need to call init() (or startRecording()) again after reset.
  • Polling supports AbortSignal. Pass signal in poll options to cancel polling early (e.g. when the user navigates away).

Other Operations

Cancel a Session

Stops the recorder locally without triggering server-side processing, then tells the server the session is cancelled.

Update a Session (Patch)

Update session properties after creation.

Two-Step Flow (Create Session + Record Separately)

Get Status for a Specific Template

Retry Failed Uploads

Update Auth Token


Configuration

Recording Options

API Reference

Lifecycle

Recording

Session

Discovery

Auth

Callbacks

Register with client.registerCallback(name, handler), remove with client.removeCallback(name, handler).

Payload Shapes

Request / Response Types

Session

Recording

Error Handling

All public async methods return SDKResult<T> — errors are returned, not thrown:

Error Classes

SharedWorker Support

The SDK offloads MP3 compression and upload to a SharedWorker for better main-thread performance. The worker is bundled separately as dist/worker.bundle.js.

Setup

Serving the Worker

The worker file must be served as a static asset: Copy to your public directory:
Or use a CDN blob URL (avoids same-origin restrictions):
Or set a global override:
If the SharedWorker fails to initialize, the SDK silently falls back to main-thread compression and upload.

Electron / IPC Mode

For Electron apps where network requests must go through the main process:
IPC mode always uses main-thread compression (SharedWorker can’t access the IPC bridge).

Source and specification