sarvamai/batch-api-typescript
TypeScript
Captured source
source ↗sarvamai/batch-api-typescript
Language: TypeScript
Stars: 0
Forks: 1
Open issues: 1
Created: 2025-02-17T13:49:13Z
Pushed: 2025-02-19T09:41:23Z
Default branch: main
Fork: no
Archived: no
README:
Sarvam AI Speech-to-Text Batch Processing
This TypeScript script allows you to process multiple audio files using Sarvam AI's Speech-to-Text API. It handles file upload, job monitoring, and result download.
Prerequisites
1. Node.js (v14 or later) – Download from nodejs.org 2. npm (Node Package Manager) – Included with Node.js 3. A Sarvam AI API key – Obtain from dashboard.sarvam.ai 4. Audio files in WAV format
Setup
1. Clone and Install Dependencies
git clone cd batch-api-typescript npm install
2. Install Required Packages
npm install axios fs winston @azure/storage-blob mime-types typescript @types/node @types/mime-types @types/winston @azure/storage-file-datalake
3. Initialize TypeScript Configuration
npx tsc --init
4. Create Required Directories
mkdir src cd src mkdir data
The data directory stores the downloaded transcription results, and src is for TypeScript source files.
5. Create `index.ts` in the `src` Directory
Create a new file named index.ts inside the src folder and paste your provided script.
Configuration
1. API Key Setup
- Get your API key from dashboard.sarvam.ai
- Replace the
API_SUBSCRIPTION_KEYvalue inindex.ts:
const API_SUBSCRIPTION_KEY = 'API_SUBSCRIPTION_KEY';
2. Audio Files
- Update the
localFilesarray inmain()with your audio file paths:
const localFiles = [ '/Users/adityam/Repos/batch-api-typescript/medical_domain_test (1).wav', ];
3. Running the Script
1. Compile TypeScript
npx tsc
This will generate a index.js file.
2. Run the Script
node index.js
Process Flow
1. The script initializes a new job with Sarvam AI 2. Uploads specified audio files to Azure storage 3. Starts the transcription job 4. Monitors job status until completion 5. Downloads transcription results to the data directory
Output
- Transcription results will be saved in the
datadirectory. - Each audio file will have a corresponding JSON file containing the transcription.
- The JSON files include:
- Transcribed text
- Confidence scores
- Timing information
Troubleshooting
1. Authentication Errors
- Verify your Sarvam AI API key is correct.
- Check if the API key has expired.
2. File Upload Errors
- Ensure audio files are in WAV format.
- Verify file paths are correct.
- Check file permissions.
3. TypeScript Errors
- Run
npx tscto check for compilation errors. - Ensure all dependencies are properly installed.
Important Notes
- Make sure your account is whitelisted to use the API.
- Only WAV/MP3 audio files are supported.
- Monitor the console output for detailed progress information.
Notability
notability 4.0/10Routine new repo, not a major release