Skip to main content

Eka Care Ekascribe Typescript SDK Integration

This guide explains how to integrate the Eka Care Ekascribe Typescript SDK into your application.

Overview

The Eka Care Ekascribe SDK allows you to capture and process audio, generating structured medical documentation using Eka Care’s voice transcription API.

Prerequisites

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

Installation

Install the SDK using npm or yarn:

Bundler Setup

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. The new URL(..., import.meta.url) pattern is natively supported.

Next.js

Ensure the SDK is only used on the client side:

Browser (Script Tag)


Instance Management

The SDK uses a singleton pattern. getEkaScribeInstance() always returns the same instance for a given env + clientId combination.
  • Calling getEkaScribeInstance() multiple times 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 on the existing instance without resetting.
  • The SDK supports one active recording at a time. Always call endRecording() or cancelSession() before starting a new recording. If you call startRecordingV2() while a recording is active, the SDK cleans up the old recording locally but does not end the session on the server — the old session will be left abandoned until it expires.

Integration Guide

Step 1: Initialize the SDK

EkaScribeConfig

Step 2: Register Callbacks

Register callbacks before starting a recording. Events fire immediately once recording starts.
See Callbacks Reference for all callback types and payloads.

Step 3: Start Recording

Creates a session and starts the microphone in one call.

RecordingOptions

Response: TStartRecordingResponse

Step 4: Pause / Resume

Response: TPauseRecordingResponse

Step 5: End Recording

Stops the microphone, flushes pending audio, waits for all uploads, and ends the session on the server (triggers processing).

Response: TEndRecordingResponse

Step 6: Get Output

Use getSessionStatus() to poll for results after ending the recording.

Response: SDKResult<GetSessionStatusResponse>

Step 7: Clean Up

After calling resetInstance(), you must call getEkaScribeInstance() again to get a new instance.

Flow Diagram


Callbacks Reference

Register with registerCallback(name, handler). Remove with removeCallback(name, handler).

onTokenRequired

Called automatically when the SDK receives a 401 from any API call. Your handler must return a fresh access token. The SDK will update its internal token and retry the failed request.
Important:
  • The handler must return Promise<string> or string
  • The SDK times out after 10 seconds — if your refresh takes longer, the request fails
  • Once the token is returned, the SDK calls updateAuthTokens() internally — you don’t need to call it yourself
  • This replaces the old pattern of manually checking status_code: 401 in every response

Type

onRecordingStateChange

Fired when recording state transitions.

Type

onAudioEvent

Fired for speech detection, silence warnings, chunk creation, and frame processing.

Type

onUploadEvent

Fired for upload progress, failures, and retries.

Type

onSessionEvent

Fired on session lifecycle events.

Type

onError

Fired on SDK errors — VAD failures, worker errors, network issues, validation errors.

Type

Removing Callbacks

Retry Failed Uploads

If endRecording() returns audio_upload_failed, retry the failed uploads:

Response: TEndRecordingResponse

Cancel a Session

Cancel a session without triggering server-side processing.

Response: SDKResult<PatchSessionResponse>

Pre-Recorded Audio Upload

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

Request

Response: TStartRecordingResponse


Session Utils

getSessionHistory(request)

Fetch previous sessions.

Response: TGetTransactionHistoryResponse

getSessionDetails(request)

Get detailed information about a specific session, including documents, context, and presigned URLs.
Each document in the response contains a presigned_url. To get the actual document content (notes, transcript, etc.), you need to fetch it from this URL:
Presigned URLs are temporary — check presigned_url_expires_at (epoch timestamp) before using. Call getDocument(documentId) to get a fresh presigned URL if expired.

Request

Response: TGetV1SessionDetailsResponse

getDocument(documentId)

Fetch a single document by ID. Use this to get a fresh presigned URL if the previous one has expired.

Response: TPostV1DocumentResponse

patchSessionStatus(request, sessionId?)

Update session properties (patient details, status, templates).

Discovery

getDiscoveryDocument()

Get the raw discovery document fetched during initialization. Contains server capabilities (supported models, languages, upload methods, audio formats).
Returns DiscoveryDocument | null.

getDiscoveryConfig()

Get the resolved configuration derived from the discovery document.
Returns SDKResult<ResolvedConfig>.

Widget

The SDK provides an optional pre-built recording UI. When enabled, the SDK injects a floating widget into your page via Shadow DOM — you write zero UI code.

Integration

Step 1: Enable the widget in SDK config with session defaults and callbacks:
Step 2: Call startForPatient() for each patient — the widget appears and the user interacts with it directly (pause, resume, stop). You receive results via callbacks.
That’s it. The widget handles startRecordingV2(), pauseRecording(), resumeRecording(), endRecording(), and getSessionStatus() internally.

Widget State Flow

Types


Authentication

updateAuthTokens(token)

Manually update the access token. This propagates the 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).

SharedWorker Configuration

The SDK offloads audio compression and upload to a SharedWorker for better main-thread performance. If SharedWorker is unavailable or fails, the SDK silently falls back to main-thread processing.

Setup

Pass the URL in config:
Notes:
  • The worker URL must be accessible from the same origin or have proper CORS headers
  • Remember to revoke blob URLs when done: URL.revokeObjectURL(workerUrl)
  • If sharedWorkerUrl is not provided, the SDK uses the main thread (no SharedWorker)

Error Codes


Deprecated Methods

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

initTransaction(request)

Creates a session on the server. Must be followed by startRecording().

startRecording(microphoneID?)

Starts recording for an already initialized session.

getTemplateOutput(request)

Fetches processed template output for a session.

getOutputTranscription(request)

Fetches the transcription output for a session.

commitTransactionCall()

Commits the current transaction on the server.

stopTransactionCall()

Stops the current transaction on the server.

Full Example


Refer EkaScribe TS SDK for SDK implementation.