Skip to main content
Capture and process audio in the browser and generate structured medical documentation through Eka Care’s voice transcription service. @eka-care/ekascribe-ts-sdk handles microphone capture, voice-activity detection, chunked upload and session lifecycle for you. It also ships a prebuilt recording Widget, session/document utilities (history, details, documents), and Eka env / clientId handling.

Prerequisites

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

Installation

npm package →

Integration Guide (Step-by-Step)

Step 1: Initialize the SDK

The SDK uses a singleton patterngetEkaScribeInstance() always returns the same instance for a given env + clientId combination. flavour and allianceConfig.baseUrl are both required. flavour identifies your app variant on every request — Eka Care issues the value to use. Omitting baseUrl throws [EkaScribe] allianceConfig.baseUrl is required at runtime. To use Eka Care’s hosted scribe service, set baseUrl to:
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 tunnel your local server over HTTPS and test against production directly. Alternatively, point at the development baseUrl (https://api.dev.eka.care/voice/v1) which works from plain localhost.
Singleton behaviour:
  • Calling getEkaScribeInstance() again with the same config returns the same instance.
  • If env or clientId changes, the old instance is automatically reset.
  • If only access_token changes, the token is updated without resetting.
  • One active recording at a time. Call endRecording() or cancelSession() before starting a new one.

Step 2: Register Callbacks

Register callbacks before starting a recording — events fire immediately once recording starts.
onTokenRequired must return the new token as a string. The handler has a 10 second timeout.
See Callbacks for the full list and payload shapes.

Step 3: Start Recording

startRecordingV2() creates the session, starts the microphone, and begins chunked upload in one call. It returns TStartRecordingResponse — check error_code, then read the session id from txn_id.
Use clinical_notes_template for testing, or contact Eka Care to create a custom template for your use case. Call ekascribe.sessions.getConfig() to list the templates enabled for your account.

Step 4: Pause / Resume

Optional, during recording. Pausing stops VAD processing — the mic stays open and no new chunks are created.

Step 5: End Recording

Stops the microphone, flushes the last audio chunk, waits for uploads, and tells the server the session has ended — which triggers server-side processing. On audio_upload_failed, retry the failed chunks with retryUploadRecording().

Step 6: Poll for Results

getSessionStatus() returns an SDKResult — check success before reading data.

Step 7: Cancel Instead of End (optional)

Stops recording without triggering processing.

Step 8: Clean Up

resetInstance() tears down the singleton — clears state, destroys the widget, removes callbacks. Call getEkaScribeInstance() again afterwards to get a fresh instance.

Flow Diagram

Full Example


Important Notes

  • flavour is required. It identifies your app variant on every request. Eka Care issues the value to use.
  • allianceConfig.baseUrl is the root for all API calls. Session creation, audio upload, status polling — everything uses this URL. It is required; omitting it throws at runtime.
  • access_token must be a valid Bearer token. All API requests include Authorization: Bearer <token>. If it expires, register onTokenRequired to auto-refresh.
  • Register callbacks before startRecordingV2(). Events fire immediately once recording starts — if callbacks aren’t registered, you’ll miss upload progress and errors.
  • endRecording() triggers server processing. Use cancelSession() instead if you don’t want processing to happen.
  • Recording methods and status methods report errors differently. startRecordingV2() / endRecording() return an error_code field; getSessionStatus() returns an SDKResult you check with result.success.
  • One active recording at a time. Call endRecording() or cancelSession() before starting a new one.
  • Microphone permission is requested on startRecordingV2(). If denied, you get the microphone error code.
  • resetInstance() is a full teardown. It clears state, destroys the widget and removes callbacks. Call getEkaScribeInstance() again afterwards.

Bundler Setup (Vite / Webpack / Next.js)

The SDK uses a SharedWorker for background audio uploads. Modern bundlers handle this automatically. Vite — works out of the box. Webpack 5 — works out of the box (new URL(..., import.meta.url) is natively supported). Next.js — ensure the SDK is used only on the client:
Browser (script tag):
SharedWorker URL — pass sharedWorkerUrl in config. Resolve it with the built-in helper:

Prebuilt Widget (zero-UI recording)

The SDK provides an optional pre-built recording UI injected via Shadow DOM — you write zero UI code. Step 1: Enable the widget in config with session defaults and callbacks:
Step 2: Call startForPatient() per patient — the widget appears and the user drives it (pause, resume, stop). Results arrive via callbacks.
The widget handles startRecordingV2(), pauseRecording(), resumeRecording(), endRecording(), and getSessionStatus() internally. Widget state flow:

Session & Document Utilities

Helpers for fetching session history, details, and documents.

getSessionHistory(request)

Fetch previous sessions.

getSessionDetails(request)

Detailed info including documents, context, and presigned URLs.
Presigned URLs are temporary — check presigned_url_expires_at (epoch) before using. Call getDocument(documentId) for a fresh URL if expired.

getDocument(documentId)

Fetch a single document by ID (and a fresh presigned URL).

patchSessionStatus(request, sessionId?)

Update session properties.

Account config (getConfig)

Call ekascribe.sessions.getConfig() to fetch your account config: supported languages, output formats, consultation modes, and my_templates (the valid template_id values to pass when starting a recording). clinical_notes_template is a ready-to-use testing template; contact Eka Care for a custom one.
Response: TGetConfigV2Response

Discovery

ekascribe.sessions.getDiscoveryDocument() returns what the server supports — models, languages, upload methods and audio formats.

Pre-recorded Audio Upload

Upload a pre-recorded audio file instead of live recording, for non-real-time flows.
  1. Create session via ekascribe.sessions.createSession()
  2. Upload audio via processPreRecordedAudio()
  3. End session via ekascribe.sessions.endSession()

Authentication

The token you pass at init is used for every request. Two ways to keep it fresh: Automatic (recommended) — register onTokenRequired; the SDK calls it on a 401 and retries the failed request:
ManualupdateAuthTokens() propagates a new token to all internal transports and the worker:
If you have onTokenRequired registered, the SDK handles 401s automatically. You only need updateAuthTokens() for proactive token rotation (e.g. before expiry).

Configuration

Recording Options

Passed to startRecordingV2():

API Reference

Instance lifecycle

Recording

Session

Documents

Widget

Auth


Callbacks

Register with ekascribe.registerCallback(name, handler).

Payload shapes


Request / Response Types

Recording responses

Session


Error Handling

The SDK reports errors two ways, depending on the method. Recording methods (startRecordingV2, endRecording) return an error_code field:
Status methods (getSessionStatus) return an SDKResult<T> — errors are returned, not thrown:

Error Codes


Deprecated Methods

These methods are from older SDK versions. They still work but are not recommended for new integrations.

Source and specification