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

Before getting started, ensure you have:
  • Node 14 or higher
  • npm or yarn for dependency management
  • Access and refresh tokens from Eka Care (optional for some methods)
  • Microphone access via browser permissions
  • Stable network connectivity

Installation

GitHub Repository | npm Package Install the SDK using npm or yarn:

Usage

1. Get Ekascribe Instance

Get the SDK instance once and use it everywhere in your application to call all methods.
Important: Use this same ekascribe instance for all SDK method calls.

2. Fetch configurations list

Get supported input languages, output formats, and consultation modes.
  • Sample Response:

3. Fetch user’s favorite templates

Get the list of templates marked as favorites by the user (configured via my_templates in the config).
  • Sample Response:

Note: The my_templates field contains templates that were previously saved using the updateConfig() method (see Templates SDK Methods section).

4. Init transaction

Initialize a transaction before starting recording. This sets up the session with your configuration.
Key Parameters:
  • input_language: Language code array (e.g., ['en-IN'])
  • output_format_template: Array with template_id - depends on your end user’s template selection
  • system_info: Optional - Pass your system configuration to backend
  • patient_details: Optional - Patient information
  • version: SDK version
  • additional_data: Optional - Pass any data you want to receive unchanged in the response
  • transfer: Audio mode. Use vaded for audio already processed with Voice Activity Detection (SDK does this by default); use non-vaded only if you are sending raw audio without VAD.
  • model_type: Transcription model choice. pro = most accurate; lite = lower latency, more performant.
  • sharedWorkerUrl: Optional - Custom URL for the shared worker script. See Shared Worker Configuration section below for usage details.
  • Sample Response:

Error handling: Possible Error Codes in error_code:
  • txn_limit_exceeded: Maximum number of transactions exceeded
  • txn_init_failed: Something went wrong. Retry with the same method call
Handling 401 Status Code: If you receive a status_code: 401, update the tokens in your config and reinitialize the instance:

Shared Worker Configuration

The SDK supports using a shared worker for efficient background audio file uploads. If you provide a sharedWorkerUrl, the SDK will use a shared worker for file uploads. If not provided, the SDK will use the main thread for file uploads. Why use Shared Worker:
  • Better Performance: Offloads file uploads to a background thread, keeping the main thread free for UI interactions
  • Resource Efficiency: A single shared worker instance can handle uploads across multiple tabs/windows
  • Improved User Experience: Prevents UI blocking during large file uploads
How to configure:
Important notes:
  • Make sure to use the correct SDK version in the CDN URL
  • The worker URL must be accessible from the same origin or have proper CORS headers
  • Remember to revoke the object URL when you’re done: URL.revokeObjectURL(workerUrl)
  • If sharedWorkerUrl is not provided, the SDK will use the main thread for file uploads (no shared worker)

5. Start recording

Start recording audio after initializing the transaction.
  • Sample Response:

6. Pause recording

Pause the ongoing voice recording.
  • Sample Response:

7. Resume recording

Resume a paused recording.
  • Sample Response:

8. End recording

End the recording session. This method:
  • Stops the recording
  • Uploads all audio chunks to the server
  • Automatically retries failed uploads once
  • Calls the commit API to finalize the transaction
  • Sample Response:

Error handling: Possible Error Codes in error_code:
  • txn_stop_failed: Call endRecording again.
  • audio_upload_failed: Use retryUploadRecording (step 9).
  • txn_commit_failed: Call commitTransactionCall (step 11).
Handling 401 Status Code: If you receive a status_code: 401, update the tokens in your config and retry:

9. Get output recorded prescription

The SDK polls for you and resolves when processing finishes (default max wait: 2 minutes; override via max_polling_time, pass time in milliseconds).
Note:
  1. On passing template_id in request params, the function will return output only for that specific template ID. If template_id is not passed, it will return all template responses generated for that txn_id.
  2. Use onPartialResultCallback (see Generic Callbacks section) before calling pollSessionOutput to receive real-time updates during polling, display partial transcription results, and improve user experience with processing progress indicators.
Status codes to handle:
  • 200: Success; all templates processed.
  • 202: Templates are still processing; poll again (or let pollSessionOutput continue).
  • 206: Partial success; some templates not processed fully.
  • 401: Authentication token expired. Update the token.
  • 403: Invalid Authentication token. Pass new token.
  • 500: All template processing failed, or internal server error; stop and surface error.
  • Response type:

  • Example Response:

10. Retry upload recording

Retry uploading failed audio files after endRecording.
  • Sample Response:

force_commit behavior:
  • force_commit: true - Model will initiate the processing if some files still fail after retry
  • force_commit: false - It will waits until all files are uploaded successfully before processing.
Handling 401 Status Code: If you receive a status_code: 401, update the tokens in your config and retry:

11. Patch recording session status

Cancel or update the status of a recording session.
  • Sample Response:

Handling 401 Status Code: If you receive a code: 401, update the tokens in your config and retry:

12. Commit transaction

Call this if endRecording returns error_code: 'txn_commit_failed' or the transaction is not yet committed.
  • Response type:

Handling 401 Status Code: If you receive a status_code: 401, update the tokens in your config and retry:

13. Stop transaction

Use this method to stop a transaction that has not yet been stopped or returned a txn_stop_failed error in a previous step.
  • Response type:

Handling 401 Status Code: If you receive a status_code: 401, update the tokens in your config and retry:

14. Get previous sessions

Fetch previous sessions. txn_count controls how many sessions the API returns.
  • Response type:

15. Convert response to other template post session

Use this method to convert an existing transcription from a completed transaction into a different template format. This is useful when you want to reformat existing transcription data without re-recording.
Key Parameters:
  • txn_id: The transaction ID of the completed session you want to convert
  • template_id: The ID of the template format you want to convert the transcription into
  • Sample Response:

When to use:
  • When you need to apply a different template to an existing transcription
  • To generate multiple template formats from the same recording session
  • After completing a session, when you want to see the output in a different template structure
Note: After getting success response from this method, call pollSessionOutput (Point 9) to get the output for the new template_id.

16. Convert transcription to template

Use this method to convert a transcription text to a specific template format.
Key Parameters:
  • txn_id: The transaction ID of the session
  • template_id: The ID of the template format you want to convert to
  • transcript: Custom transcript text to use for conversion
  • Sample Response:

17. Update result summary

Use this method to update/edit the result summary (template output) for a transaction.
Key Parameters:
  • txnId: The transaction ID
  • data: Array of objects containing template-id and the updated data base64 encoded data
  • Sample Response:

18. Run system compatibility test

Use this method to run a comprehensive system compatibility test to ensure the user’s browser and device support all SDK features.
  • Sample Response:

When to use:
  • Before starting a recording session to ensure user’s system is compatible
  • To provide user feedback about missing permissions or unsupported features
  • During onboarding to identify potential issues

Templates SDK Methods

1. Get All Templates

Use this method to retrieve all available templates for the current user.
  • Response type:

2. Create Template

Use this method to create a new custom template.
  • Response type:

3. Edit Template

Use this method to update an existing template.
  • Response type:

4. Delete Template

Use this method to delete an existing template.
  • Response type:

5. Generate Template with AI by giving a prompt

Use this method to generate a template using AI with a text prompt.
  • Response type:

6. Add templates to list

Use this method to mark templates as favourite templates.
  • Response type:

7. Get All Sections

Use this method to retrieve all available template sections.
  • Response type:

8. Create Section in a template

Use this method to create a new section that can be used in templates.
  • Response type:

9. Edit Section in a template

Use this method to update an existing template section.
  • Response type:

10. Delete Section from a template

Use this method to delete a template section.
  • Response type:

Non-vaded flow: Upload raw audio to get output summary

Use this method to upload pre-recorded audio files directly and get transcription output without real-time recording. This is useful when you have existing audio files and want to process them. What this method does:
  • Gets a presigned URL from the server
  • Uploads audio files to S3 via presigned URL
  • Initializes a transaction with the uploaded files
  • Returns the transaction details
Key Parameters:
  • action: Pass ekascribe-v2 exactly as shown
  • audioFiles: Array of File or Blob objects
  • audioFileNames: Array of file names corresponding to audio files
  • transfer: Use non-vaded for raw audio files (not processed with VAD)
  • Other parameters: Same as initTransaction (see step 3)
  • Sample Response:

Error handling: Possible Error Codes in error_code:
  • get_presigned_url_failed: Failed to get presigned URL from server, retry with the same method
  • audio_upload_failed: Failed to upload audio files to S3, retry with the same method
  • txn_limit_exceeded: Maximum number of transactions exceeded
  • txn_init_failed: Failed to initialize transaction after upload, retry with the same method
Handling 401 Status Code: If you receive a status_code: 401, update the tokens in your config and retry:

Utility Methods

1. Get total uploaded files

Use this method to retrieve all the audio files generated for a specific session.
  • Response type:

2. Get successfully uploaded files

Use this method to retrieve all the audio files that were uploaded successfully.
  • Response type:

3. Get failed audio files

Use this method to retrieve all the audio files that failed to upload.
  • Response type:

4. Reset Class Instance

Use this method to reset the EkaScribe instance and clear all stored data.

5. Reinitialise VAD Instance

Use this method to reinitialize the Voice Activity Detection (VAD) instance.

6. Pause VAD Instance

Use this method to pause the Voice Activity Detection without stopping the recording session.

7. Destroy VAD Instance

Use this method to completely destroy the VAD instance and free up resources.

8. Update Authentication Tokens

Use this method to update the access token when it expires (e.g., when you receive a 401 error).
When to use:
  • When any API method returns status_code: 401
  • When eventCallback returns error.code: 401 in file_upload_status
  • Before token expiration to prevent upload failures

Generic Callbacks

1. Event callback

This callback provides information about SDK operations. Use it to monitor file uploads, transaction status, AWS configuration, and authentication errors.
  • Callback Structure:

  • Callback Types Explained:

file_upload_status - Track audio chunk upload progress Use this to monitor upload progress of audio chunks:
  • status: 'info' - Audio chunk info
    • data.success: Count of successfully uploaded chunks
    • data.total: Total chunks generated
    • data.fileName: Current chunk file name
    • data.chunkData: Audio data for current chunk
  • status: 'success' - Chunk uploaded successfully
    • data.success: Updated successful upload count
    • data.total: Total chunks
    • data.is_uploaded: true
  • status: 'error' - Chunk upload failed
    • error.code: HTTP error code
    • error.msg: Error message
    • error.details: Additional error details
  • Status codes to handle: If error.code === 401, it means your access token has expired. Update tokens immediately:

2. User speech callback

Triggered by Voice Activity Detection (VAD) when user starts or stops speaking.

3. Partial result callback

This callback provides real-time partial results while polling for the final output. Use it to display intermediate transcription and template results to users before processing is complete.
  • Callback Structure:

When to use:
  • Set this callback before calling pollSessionOutput to receive real-time updates
  • Display partial transcription results to improve user experience
  • Show processing progress indicators
  • Handle intermediate template results
Note: This callback is triggered multiple times during polling - once for each poll attempt until processing completes or times out.

Error codes

Refer Ekascribe for SDK implementations.