naijalingo 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,268 @@
1
+ # 9jaLingo Node.js SDK
2
+
3
+ <p align="center">
4
+ <strong>The Official Node.js SDK for <a href="https://www.9jalingo.org">9jaLingo</a> — AI-Powered Text-to-Speech for Nigerian Languages</strong>
5
+ </p>
6
+
7
+ <p align="center">
8
+ <a href="https://www.npmjs.com/package/naijalingo"><img src="https://img.shields.io/npm/v/naijalingo.svg" alt="npm version"></a>
9
+ <a href="https://www.npmjs.com/package/naijalingo"><img src="https://img.shields.io/node/v/naijalingo.svg" alt="Node version"></a>
10
+ <a href="https://opensource.org/licenses/MIT"><img src="https://img.shields.io/badge/license-MIT-blue.svg" alt="License"></a>
11
+ </p>
12
+
13
+ ---
14
+
15
+ **9jaLingo** is a Voice AI speech platform built specifically for **African languages**. This SDK provides a simple TypeScript/JavaScript interface to the [9jaLingo TTS API](https://www.9jalingo.org), enabling developers to generate natural-sounding speech in **Hausa**, **Igbo**, **Yoruba**, and **Nigerian Pidgin** with over **240+ speaker voices**.
16
+
17
+ ### Key Features
18
+
19
+ - **Text-to-Speech** — Convert text to natural speech in 4 Nigerian languages
20
+ - **240+ Speaker Voices** — Choose from a diverse library of male and female voices
21
+ - **Voice Cloning** — Clone any voice from a short reference audio sample
22
+ - **Multi-Format Output** — WAV, PCM, MP3, FLAC, AAC, ALAC, or OGG
23
+ - **Streaming** — Stream audio chunks as they're generated
24
+ - **Long-Form Generation** — Automatic chunking for long texts
25
+ - **OpenAI-Compatible** — Familiar TTS-style API surface
26
+ - **Node.js 18+** — Native `fetch`, TypeScript types included
27
+
28
+ ---
29
+
30
+ ## Installation
31
+
32
+ ```bash
33
+ npm install naijalingo
34
+ ```
35
+
36
+ Requires **Node.js 18+**.
37
+
38
+ ## Quick Start
39
+
40
+ ```bash
41
+ # 1) Copy your real key from https://9jalingo.org/dashboard
42
+ # 2) Replace YOUR_API_KEY (do not leave this as-is)
43
+ export NAIJALINGO_API_KEY="YOUR_API_KEY"
44
+ ```
45
+
46
+ ```ts
47
+ import { NaijaLingo } from "naijalingo";
48
+
49
+ const client = new NaijaLingo(); // picks up NAIJALINGO_API_KEY
50
+
51
+ // voice/speaker = speaker ID · lang/language = language code
52
+ const audio = await client.tts.generate("Bawo ni, I dey greet you!", {
53
+ voice: "adeola_yo",
54
+ lang: "yo",
55
+ });
56
+ await audio.save("greeting.wav");
57
+ ```
58
+
59
+ Or pass the key explicitly:
60
+
61
+ ```ts
62
+ const client = new NaijaLingo({ apiKey: "YOUR_API_KEY" });
63
+ ```
64
+
65
+ > **Important:** For `generate` and `stream`:
66
+ > - `voice` / `speaker` = **speaker ID** (e.g. `ada_pcm`, `adaeze_ig`)
67
+ > - `lang` / `language` = **language code** (`ha`, `ig`, `yo`, `pcm`)
68
+ >
69
+ > Do **not** pass language codes as `voice`. Use `listSpeakers({ language: "pcm" })`
70
+ > to discover speaker IDs. Voice cloning is different: `clone(..., { voice: "ig" })`
71
+ > still takes a language code (sent as API `lang`).
72
+
73
+ ---
74
+
75
+ ## API Reference
76
+
77
+ ### Text-to-Speech
78
+
79
+ ```ts
80
+ import { NaijaLingo } from "naijalingo";
81
+
82
+ const client = new NaijaLingo();
83
+
84
+ const audio = await client.tts.generate("How you dey?", {
85
+ voice: "ada_pcm",
86
+ lang: "pcm",
87
+ });
88
+ await audio.save("output.wav");
89
+
90
+ // speaker= / language= aliases
91
+ const igbo = await client.tts.generate("Nnoo, kedu ka i mere?", {
92
+ speaker: "adaeze_ig",
93
+ language: "ig",
94
+ });
95
+ await igbo.save("adaeze_greeting.wav");
96
+
97
+ // Export to MP3
98
+ const mp3 = await client.tts.generate("Make we test compressed audio.", {
99
+ voice: "ada_pcm",
100
+ lang: "pcm",
101
+ responseFormat: "mp3",
102
+ });
103
+ await mp3.save("output.mp3");
104
+
105
+ // Fine-tune generation parameters
106
+ const tuned = await client.tts.generate("Na so life be sometimes.", {
107
+ voice: "ada_pcm",
108
+ lang: "pcm",
109
+ temperature: 0.8,
110
+ topP: 0.9,
111
+ repetitionPenalty: 1.2,
112
+ });
113
+ ```
114
+
115
+ ### Streaming
116
+
117
+ ```ts
118
+ import { createWriteStream } from "node:fs";
119
+
120
+ const stream = client.tts.stream("Very long text here...", {
121
+ speaker: "ada_pcm",
122
+ lang: "pcm",
123
+ });
124
+
125
+ const writer = createWriteStream("long_speech.wav");
126
+ for await (const chunk of stream) {
127
+ writer.write(chunk);
128
+ }
129
+ writer.end();
130
+
131
+ // Or collect the full stream
132
+ const audio = await client.tts
133
+ .stream(longText, { lang: "pcm", speaker: "ada_pcm" })
134
+ .collect();
135
+ await audio.save("long_speech.wav");
136
+ ```
137
+
138
+ ### Voice Cloning
139
+
140
+ ```ts
141
+ const audio = await client.tts.clone(
142
+ "Kedu ka i mere?",
143
+ "reference_voice.mp3",
144
+ { voice: "ig", responseFormat: "mp3" },
145
+ );
146
+ await audio.save("cloned.mp3");
147
+
148
+ // From a Buffer
149
+ import { readFileSync } from "node:fs";
150
+ const buf = readFileSync("reference.wav");
151
+ const cloned = await client.tts.clone("Hello!", buf, { voice: "pcm" });
152
+ ```
153
+
154
+ ### Speakers
155
+
156
+ ```ts
157
+ const speakers = await client.tts.listSpeakers();
158
+ for (const s of speakers) {
159
+ console.log(`${s.id} — ${s.language} (${s.gender})`);
160
+ }
161
+
162
+ const yoruba = await client.tts.listSpeakers({ language: "yo" });
163
+ const speaker = await client.tts.getSpeaker("ada_pcm");
164
+ console.log(speaker.name, speaker.language);
165
+ ```
166
+
167
+ ### Languages
168
+
169
+ ```ts
170
+ const langs = await client.tts.listLanguages();
171
+ for (const lang of langs.languages) {
172
+ console.log(`${lang.code}: ${lang.name}`);
173
+ }
174
+ ```
175
+
176
+ ### Models
177
+
178
+ ```ts
179
+ const models = await client.listModels();
180
+ for (const model of models) {
181
+ console.log(`${model.id} — owned by ${model.ownedBy}`);
182
+ }
183
+ ```
184
+
185
+ ### API Info & Health
186
+
187
+ ```ts
188
+ const info = await client.apiInfo();
189
+ console.log(info.name, info.version);
190
+
191
+ const service = await client.serviceInfo();
192
+ console.log(service.speechUrl);
193
+
194
+ const status = await client.tts.health();
195
+ console.log(status.status, status.totalSpeakers);
196
+ ```
197
+
198
+ ---
199
+
200
+ ## Error Handling
201
+
202
+ ```ts
203
+ import {
204
+ NaijaLingo,
205
+ AuthenticationError,
206
+ NotFoundError,
207
+ ServerError,
208
+ } from "naijalingo";
209
+
210
+ const client = new NaijaLingo();
211
+
212
+ try {
213
+ await client.tts.generate("Hello!", { voice: "nonexistent_speaker" });
214
+ } catch (err) {
215
+ if (err instanceof AuthenticationError) {
216
+ console.error("Invalid API key");
217
+ } else if (err instanceof NotFoundError) {
218
+ console.error("Speaker not found:", err.message);
219
+ } else if (err instanceof ServerError) {
220
+ console.error("Server error — try again later");
221
+ } else if (err instanceof Error) {
222
+ // e.g. language code passed as voice
223
+ console.error(err.message);
224
+ }
225
+ }
226
+ ```
227
+
228
+ ---
229
+
230
+ ## Configuration
231
+
232
+ | Option / Env | Environment Variable | Default |
233
+ |---|---|---|
234
+ | `apiKey` | `NAIJALINGO_API_KEY` | — |
235
+ | `baseUrl` | `NAIJALINGO_BASE_URL` | `https://api.9jalingo.org` |
236
+ | `timeout` | — | `300000` ms |
237
+
238
+ ```ts
239
+ const client = new NaijaLingo({
240
+ apiKey: "YOUR_API_KEY",
241
+ baseUrl: "https://api.9jalingo.org",
242
+ timeout: 300_000,
243
+ });
244
+ ```
245
+
246
+ ---
247
+
248
+ ## Supported Languages
249
+
250
+ | Code | Language | Example speakers |
251
+ |------|----------|------------------|
252
+ | `ha` | Hausa | `aisha_ha`, `bello_ha` |
253
+ | `ig` | Igbo | `adaeze_ig`, `ifeanyi_ig` |
254
+ | `yo` | Yoruba | `adeola_yo`, `adekunle_yo` |
255
+ | `pcm` | Nigerian Pidgin | `ada_pcm`, `blessing_pcm` |
256
+
257
+ ---
258
+
259
+ ## Links
260
+
261
+ - **Website:** [www.9jalingo.org](https://www.9jalingo.org)
262
+ - **API Docs:** [www.9jalingo.org/api-documentation](https://www.9jalingo.org/api-documentation)
263
+ - **Python SDK:** [`pip install naijalingo`](https://pypi.org/project/naijalingo/)
264
+ - **Support:** [support@9jalingo.org](mailto:support@9jalingo.org)
265
+
266
+ ## License
267
+
268
+ MIT