Package Exports
- asr-sdk-dev
Readme
Cariva ASR SDK for JavaScript
Introduction
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.
Demo
For a live demonstration and integration guide, visit our playground demo.
Requirements
- Node.js 18 or higher
Installation
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:
npm install @cariva/asr-sdk --saveInstall via CDN
To include the SDK directly in your HTML file via CDN
<script src="https://cdn.jsdelivr.net/npm/@cariva/asr-sdk/dist/global/<version>/index.min.js"></script>Example Usage
Here's a sample implementation using the Cariva ASR SDK:
// Import ASR SDK
const { ASR, 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', or 'medclerk'
};
(async () => {
// Initialize Voice audio file
const audioFile = new Blob(["..."]); // Replace this placeholder with an actual audio file Blob
// Initialize ASR instance with config
const asr = new ASR(config);
try {
// Create an ASR task
const task = await asr.create();
// Optionally set a timeout to cancel the task if it takes too long
const TIMEOUT_MS = 10000; // Timeout in milliseconds (e.g., 10 seconds)
const timeout = setTimeout(async () => {
console.log("Cancelling ASR task due to timeout...");
await cancelASRTask();
console.log("ASR task cancelled.");
}, TIMEOUT_MS);
// Process the audio file and get the ASR result
const result = await task.process(audioFile);
console.log('ASR Result:', result); // Output the result
} catch (error) {
// Cancel the ASR task if an error occurs
console.error("Error getting ASR result:", error);
}
})();Configuration Options
key(string): Your ASR API key.secret(string): Your ASR SECRET key.mode(string): Recognition mode, can be set toorder,soap, ormedclerk.
Error Handling
If an error occurs during processing, it will be logged to the console, and the ASR task will be canceled to free up resources.
License
- This SDK is available under the terms of the LICENSE.