Addis AI Code Examples

Translation API

Easily translate between Amharic, Oromo, and other languages

Translation Example
1import { addisAI } from 'addis-ai';
2
3// Initialize the client with your API key
4const client = new addisAI.Client({
5 apiKey: process.env.ADDIS_AI_API_KEY
6});
7
8// Function to translate text to Amharic
9async function translateToAmharic(text) {
10 try {
11 const result = await client.translate({
12 text,
13 targetLanguage: 'am',
14 sourceLanguage: 'en'
15 });
16
17 console.log(`Original: ${text}`);
18 console.log(`Amharic: ${result.translatedText}`);
19 return result.translatedText;
20 } catch (error) {
21 console.error('Translation failed:', error);
22 }
23}
24
25// Example usage
26translateToAmharic('Hello, how are you today?');

Speech-to-Text API

Convert audio files to text with support for multiple Ethiopian languages

Speech Recognition Example
1import { addisAI } from 'addis-ai';
2
3// Initialize the client
4const client = new addisAI.Client({
5 apiKey: process.env.ADDIS_AI_API_KEY
6});
7
8// Function to convert speech to text
9async function convertSpeechToText(audioFile) {
10 try {
11 const result = await client.speechToText({
12 audioFile,
13 language: 'am', // Amharic
14 options: {
15 punctuate: true,
16 format: 'json'
17 }
18 });
19
20 console.log('Transcription:', result.text);
21 return result.text;
22 } catch (error) {
23 console.error('Speech-to-Text conversion failed:', error);
24 }
25}

Natural Language Processing

Perform sentiment analysis and entity recognition on Amharic text

NLP Processing Example
1import { addisAI } from 'addis-ai';
2
3// Initialize the client with your API key
4const client = new addisAI.Client({
5 apiKey: process.env.ADDIS_AI_API_KEY
6});
7
8// Function to translate text to Amharic
9async function translateToAmharic(text) {
10 try {
11 const result = await client.translate({
12 text,
13 targetLanguage: 'am',
14 sourceLanguage: 'en'
15 });
16
17 console.log(`Original: ${text}`);
18 console.log(`Amharic: ${result.translatedText}`);
19 return result.translatedText;
20 } catch (error) {
21 console.error('Translation failed:', error);
22 }
23}
24
25// Example usage
26translateToAmharic('Hello, how are you today?');