JavaScript SDK for Cariva ASR

The Cariva ASR SDK for JavaScript enables fast and easy integration with Cariva's Automatic Speech Recognition (ASR) system. With minimal setup, you can begin using Cariva's ASR AI capabilities to transcribe audio within minutes.
For a live demonstration and integration guide, visit our playground demo.
- Node.js 18 or higher
You can install the @cariva/asr-sdk SDK either via npm or directly in the browser using a CDN.
#### Install via npm
To add the SDK to your project using npm, run:
``bash`
npm install @cariva/asr-sdk --save
#### Install via CDN
To include the SDK directly in your HTML file via CDN
`html`
Here's a sample implementation using the Cariva ASR SDK:
`javascript
// Import ASR SDK
const { ASR, ASRConfigs, cancelASRTask } = require("@cariva/asr-sdk");
// ASR configuration
const config = {
key: "API_KEY", // Replace with your actual API key
secret: "API_SECRET", // Replace with your actual API secret
mode: "RECOGNITION_MODE", // Set recognition mode: 'order', 'soap', 'medclerk', 'nsos' and 'neos'
lang: "RESULT_LANGUAGE", // Optional: Set ASR process language
specialty: "DOCTOR_SPECIALTY", // Optional: Set doctor specialty
newLineString: "CUSTOM_NEW_LINE_STRING", // Optional: Set a string to replace \n with a new line.
};
// Function to process audio with ASR
async function processAudio() {
const audioFile = new Blob(["..."]); // Replace this placeholder with an actual audio file
const asr = new ASR(config);
try {
const task = await asr.create();
// Set timeout for task cancellation
const TIMEOUT_MS = 10000;
const timeout = setTimeout(async () => {
console.log("Cancelling ASR task due to timeout...");
await cancelASRTask();
console.log("ASR task cancelled.");
}, TIMEOUT_MS);
// Process audio file
const result = await task.process(audioFile);
clearTimeout(timeout); // Clear timeout if task completes in time
console.log("ASR Result:", result);
} catch (error) {
console.error("Error processing ASR:", error);
}
}
// Execute the function
processAudio();
`
| Item | Type | Required | Default | Detail |
| ----------- | ------ | -------- | ------- | ------------------------------------------------------------------------------------------------------------------------------------------- |
| key | string | Yes | - | Your Cariva ASR API Public key |Secret
| | string | Yes | - | Your Cariva ASR API Secret key |mode
| | string | Yes | - | Recognition mode can be set to order \| soap \| medclerk \| nsos \| neos |lang
| | string | No | en | AI result language (Available on medclerk and soap) en \| th |specialty
| | string | No | other | Mapping specific medical specialties to corresponding AI models enhances the accuracy and reliability (Available on medclerk and soap). |
If an error occurs during processing, it will be logged to the console, and the ASR task will be canceled to free up resources.
---
When calling the process on a created task, there are two optional parameters that can be sent. These parameters will overwrite the configuration options.
| Item | Type | Required | Default | Detail |
| ----------- | ------------ | -------- | ------- | ------------------------------------------------------------------------------------------------------------------------------------------- |
| file | file \| blob | Yes | - | Audio recording file. |lang
| | string | No | en | AI result language (Available on medclerk and soap) en \| th |specialty
| | string | No | other | Mapping specific medical specialties to corresponding AI models enhances the accuracy and reliability (Available on medclerk and soap). |
---
- The lang and specialty options are applicable when using medclerk or soap mode.key
- Ensure to provide valid API keys ( and Secret`) to access the Cariva ASR service.
Below is the table show key for send as specialty.
| No | Label | Key |
| --- | -------------------------------- | ---------------- |
| 1 | General Practitioner (GP) | gen-practitioner |
| 2 | General Medicine | gen-med |
| 3 | MED Cardiology | med-cardio |
| 4 | MED Pulmonology | med-pulmonary |
| 5 | MED Gastroenterology (GI) | med-gastro |
| 6 | MED Neurology | med-neuro |
| 7 | MED Nephrology | med-nephro |
| 8 | MED Oncology | med-onco |
| 9 | MED Endocrinology | med-endo |
| 10 | MED Dermatology (Skin) | med-skin |
| 11 | MED Allergy and Immunology | med-allergy |
| 12 | General Surgery | surgery |
| 13 | Orthopedic | orthopedic |
| 14 | General Pediatrics | gen-ped |
| 15 | Ophthalmology (Eye) | ophthalmology |
| 16 | Otolaryngology (ENT) | otolaryngology |
| 17 | Obstetrics & Gynecology (OB-GYN) | ob-gyn |
| 18 | Emergency (ER) | emergency |
| 19 | Other specialists | other |