1.5.0 • Published 10 months ago
@cariva/asr-sdk v1.5.0
Cariva ASR SDK for JavaScript
Effortlessly integrate Cariva’s Automatic Speech Recognition (ASR) API into your JavaScript applications to transcribe audio with minimal setup.
📋 Table of Contents
✨ Features
- Minimal Setup: Get up and running in minutes.
- Flexible Environments: Supports Node.js (v18+) and modern browsers.
- Promise‑based API: Intuitive task creation and processing.
- Cancellation Support: Abort long‑running tasks.
- Customizable: Override language and medical specialty for model tuning.
🎬 Demo
Try a live integration guide and playground demo here.
⚙️ Requirements
- Node.js v18 or higher (for npm install)
- Modern browsers (for CDN usage)
🚀 Installation
npm
npm install @cariva/asr-sdk
# or
yarn add @cariva/asr-sdkCDN
Include via <script> tag:
<script src="https://cdn.jsdelivr.net/npm/@cariva/asr-sdk/dist/global/1.4.0/index.min.js"></script>💡 Quick Start
import { ASR, ASRConfigs, cancelASRTask } from '@cariva/asr-sdk';
(async () => {
const config = new ASRConfigs({
key: 'YOUR_API_KEY', // required
secret: 'YOUR_API_SECRET', // required
mode: 'doc-ipd-soap', // required
lang: 'en', // optional, default: 'en'
specialty: 'other', // optional, default: 'other'
newLineString: '\n', // optional
});
const asr = new ASR(config);
try {
const task = await asr.create();
// Cancel if it takes longer than 5 minutes
const timeoutId = setTimeout(async () => {
console.warn('Cancelling ASR task due to timeout');
await cancelASRTask(task.id);
}, 300000);
const audioBlob = /* your File or Blob */;
const result = await task.process(audioBlob);
clearTimeout(timeoutId);
console.log('Transcription:', result);
} catch (error) {
console.error('ASR error:', error);
}
})();🔧 Configuration
ASRConfigs
| Option | Type | Required | Default | Description |
|---|---|---|---|---|
key | String | Yes | — | Your Cariva ASR API public key |
secret | String | Yes | — | Your Cariva ASR API secret key |
mode | String | Yes | — | Recognition mode: doc-ipd-soap | doc-opd-clinicalrecord | nur-opd-nursenote-start | nur-opd-nursenote-end |
lang | String | No | en | Transcription language: en | th (only for SOAP/clinicalrecord modes) |
specialty | String | No | other | Medical specialty for improved accuracy (SOAP/clinicalrecord modes) |
newLineString | String | No | \n | Replacement string for newline characters |
Process Options
When calling task.process(), you can override configuration per request:
| Option | Type | Required | Default | Description |
|---|---|---|---|---|
file | File | Blob | Yes | — | Audio file or blob to transcribe |
lang | String | No | en | Override transcription language |
specialty | String | No | other | Override medical specialty |
⚠️ Error Handling
All failures are thrown as JavaScript Error. Wrap your calls in try/catch:
try {
// ASR logic...
} catch (err) {
console.error("ASR processing failed:", err);
}🗂️ Specialty Key Mapping
| # | Label | Key |
|---|---|---|
| 1 | General Practitioner (GP) | gen-practitioner |
| 2 | General Medicine | gen-med |
| 3 | Cardiology | med-cardio |
| 4 | Pulmonology | med-pulmonary |
| 5 | Gastroenterology (GI) | med-gastro |
| 6 | Neurology | med-neuro |
| 7 | Nephrology | med-nephro |
| 8 | Oncology | med-onco |
| 9 | Endocrinology | med-endo |
| 10 | Dermatology (Skin) | med-skin |
| 11 | 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 |
📜 License
This project is licensed under the Apache License 2.0.