Enterprise Node.js SDK for Abena AI Services - ASR, TTS, Translation
npm install abenasdk
![License: Proprietary]()
The official enterprise-grade Node.js SDK for integrating Abena AI's powerful services into your applications. Access high-quality Text-to-Speech (TTS), accurate Automatic Speech Recognition (ASR), and Neural Machine Translation with a simple and intuitive async/await API.
- High-Quality TTS: Synthesize natural-sounding speech using intuitive voice names.
- Accurate ASR: Transcribe audio from files, Buffers, or Streams.
- Neural Translation: Translate text between hundreds of user-friendly language codes.
- Robust & Secure: Built with production-grade validation and security.
- Detailed Error Handling: Clear, specific exceptions for easy debugging in your application.
- TypeScript Support: Fully typed for a modern development experience.
The package requires Node.js v14 or higher.
``bash`
npm install @abena-ai-team/abenasdk
`javascript
const { AbenasClient, FileError } = require('@abena-ai-team/abenasdk');
const fs = require('fs');
// Best practice: store your API key in an environment variable
// export ABENA_API_KEY="sk_your_api_key_here"
const client = new AbenasClient({
apiKey: process.env.ABENA_API_KEY
});
async function main() {
try {
// Text-to-Speech (TTS)
const audioBuffer = await client.tts.synthesize(
'Hello from the Abena AI software development kit.',
'akua'
);
fs.writeFileSync('speech_output.wav', audioBuffer);
console.log("Audio saved to speech_output.wav");
// Automatic Speech Recognition (ASR)
const transcription = await client.asr.transcribe('speech_output.wav', 'en');
console.log(Transcription: ${transcription.text});
// Translation
const translation = await client.translator.translate({
text: 'Hello from Abena AI!',
source_language: 'en',
target_language: 'fr'
});
console.log(Translation: ${translation.translation});
} catch (error) {
console.error(An error occurred: [${error.name}] ${error.message});
if (error instanceof FileError) {
console.error("Please ensure the input file exists.");
}
}
}
main();
`
`javascript
const { AbenasClient } = require('@abena-ai-team/abenasdk');
// For Production (default)
const client = new AbenasClient({ apiKey: 'YOUR_PROD_KEY' });
`
#### synthesize(text, voice, outputFile)
Converts text to speech.
- text (string): The text to synthesize. Max 500 characters.voice
- (string): The voice name to use (e.g., 'akua', 'abena').outputFile
- (string, optional): Path to save the .wav file. If omitted, a Buffer is returned.
`javascript
// Get audio data as a Buffer
const audioBuffer = await client.tts.synthesize('Hello world', 'akua');
// Or save directly to a file
await client.tts.synthesize('Hello world', 'abena', 'output.wav');
`
#### transcribe(audioSource, language)
Transcribes an audio file to text.
- audioSource (string | Buffer | Stream): The audio to transcribe. Can be a file path, a Buffer, or a Readable stream.language
- (string): The language of the audio (e.g., 'en').
`javascript
// From a file path
const result = await client.asr.transcribe('./audio.wav', 'en');
console.log(result.text);
// From a Buffer
const audioBuffer = fs.readFileSync('./audio.wav');
const resultFromBuffer = await client.asr.transcribe(audioBuffer, 'en');
`
#### translate({ text, source_language, target_language })
Translates text between languages.
- text (string): The text to translate. Max 1000 characters.source_language
- (string): The source language code (e.g., 'en').target_language
- (string): The target language code (e.g., 'fr').
`javascript`
const result = await client.translator.translate({
text: 'Welcome to the future of AI.',
source_language: 'en',
target_language: 'twi'
});
console.log(result.translation);
The SDK throws specific, custom errors to allow for robust error handling.
`javascript
const { AbenasClient, APIError, ValidationError, FileError } = require('@abena-ai-team/abenasdk');
const client = new AbenasClient({ apiKey: '...' });
try {
await client.asr.transcribe('non_existent_file.wav');
} catch (error) {
if (error instanceof FileError) {
console.error(File Error: ${error.message});Validation Error: ${error.message}
} else if (error instanceof ValidationError) {
console.error();API Error: [Status ${error.status}] ${error.message}
} else if (error instanceof APIError) {
console.error();An unexpected error occurred: ${error.message}
// The raw server response data is available if needed
console.error('Server Response:', error.data);
} else {
console.error();`
}
}
- Full API Docs: https://abena.mobobi.com/playground/sdk/docs/ (Example URL)
- cURL Examples: See the examples/curl/ directory.info@mobobi.com` for any bugs or feature requests.
- Report an Issue: Please contact
---
© 2025 Mobobi LLC. All rights reserved.