npm package link
https://www.npmjs.com/package/med-scribe-alliance-ts-sdkInstallation
@ricky0123/vad-web— Voice Activity Detection@breezystack/lamejs— MP3 encodingzod— Schema validation
Integration Guide (Step-by-Step)
Step 1: Create the Client
ThebaseUrl is required — all API calls (session creation, upload, status polling) go through this URL.
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()callsinit()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.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
baseUrlis the root for all API calls. Session creation, audio upload, status polling — everything uses this URL. Make sure it’s correct and accessible.accessTokenmust be a valid Bearer token. All API requests includeAuthorization: Bearer <token>. If it expires, registeronTokenRequiredto 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. UsecancelSession()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. NoendSessioncall is made to the backend.- All async methods return
SDKResult<T>, never throw. Always checkresult.successbefore accessingresult.data. Errors are inresult.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
ValidationErrorbefore 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 viaonErrorcallback. 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 callinit()(orstartRecording()) again after reset.- Polling supports
AbortSignal. Passsignalin 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
| Method | Returns | Description |
|---|---|---|
init() | SDKResult<void> | Fetch discovery document. Called automatically by startRecording. |
reset() | Promise<void> | Stop recording, clear all state and caches. |
Recording
| Method | Returns | Description |
|---|---|---|
startRecording(options) | SDKResult<CreateSessionResponse> | Create session + start mic + begin upload. |
startRecordingWithSession(session, options?) | SDKResult<void> | Attach recorder to an existing session. |
pauseRecording() | void | Pause VAD (mic stays open, no chunks created). |
resumeRecording() | void | Resume VAD processing. |
endRecording() | SDKResult<StopRecordingResult> | Stop mic, flush audio, wait for uploads, end session. |
isRecording() | boolean | Whether a recording is active. |
isRecordingPaused() | boolean | Whether the active recording is paused. |
retryFailedUploads() | SDKResult<RetryUploadResult> | Retry uploads that failed during the last recording. |
hasFailedUploads() | boolean | Whether there are retryable failed uploads. |
Session
| Method | Returns | Description |
|---|---|---|
createSession(request) | SDKResult<CreateSessionResponse> | Create a session without starting a recording. |
getSessionStatus(sessionId?, options?) | SDKResult<GetSessionStatusResponse> | Get status. Supports poll and templateId options. |
getCurrentSession() | CreateSessionResponse | null | Get the active session if any. |
updateSession(request, sessionId?) | SDKResult<PatchSessionResponse> | Patch session (patient details, status, etc.). |
cancelSession(sessionId?) | SDKResult<PatchSessionResponse> | Cancel session (stops recorder, no server processing). |
Discovery
| Method | Returns | Description |
|---|---|---|
getDiscoveryDocument() | DiscoveryDocument | null | Raw discovery document. |
getDiscoveryConfig() | SDKResult<ResolvedConfig> | Resolved config from discovery. |
refreshDiscovery() | SDKResult<ResolvedConfig> | Force-refresh discovery. |
Auth
| Method | Description |
|---|---|
setAccessToken(token) | Update Bearer token. Propagates to transport, recorder, and worker. |
Callbacks
Register withclient.registerCallback(name, handler), remove with client.removeCallback(name, handler).
| Callback | Payload | Description |
|---|---|---|
onRecordingStateChange | RecordingStateChangeEvent | Recording started, paused, resumed, or ended. |
onAudioEvent | AudioEvent | Speech detection, silence warnings, chunk ready. |
onUploadEvent | UploadEvent | Upload progress and failures. |
onSessionEvent | SessionEvent | Session created, ended, status updates. |
onError | ErrorEvent | VAD, worker, transport, or validation errors. |
onTokenRequired | TokenRequiredEvent | 401 received — call event.resolve(newToken) to retry. |
Payload Shapes
Request / Response Types
Session
Recording
Error Handling
All public async methods returnSDKResult<T> — errors are returned, not thrown:
Error Classes
| Error | HTTP | Description |
|---|---|---|
ScribeError | — | Base error class |
ValidationError | 400 | Invalid request or config |
AuthenticationError | 401 | Auth failed (after token refresh attempt) |
ForbiddenError | 403 | Access denied |
SessionNotFoundError | 404 | Session doesn’t exist |
SessionExpiredError | 410 | Session expired |
RateLimitError | 429 | Rate limit exceeded |
DiscoveryError | — | Discovery fetch/parse failed |
TransportError | — | Network / IPC failure |
WorkerError | — | SharedWorker failure |
UploadError | — | Audio upload failure |
SharedWorker Support
The SDK offloads MP3 compression and upload to a SharedWorker for better main-thread performance. The worker is bundled separately asdist/worker.bundle.js.
Setup
Serving the Worker
The worker file must be served as a static asset: Copy to your public directory:Electron / IPC Mode
For Electron apps where network requests must go through the main process:Building from Source
dist/):
| File | Description |
|---|---|
index.mjs | Minified ESM bundle |
index.d.ts | Bundled type declarations |
worker.bundle.js | Self-contained IIFE SharedWorker |

