audixa 1.0.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,342 @@
1
+ # Audixa
2
+
3
+ > Official Node.js + TypeScript SDK for the [Audixa](https://audixa.ai) Text-to-Speech API
4
+
5
+ [![npm version](https://img.shields.io/npm/v/audixa.svg)](https://www.npmjs.com/package/audixa)
6
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
7
+ [![TypeScript](https://img.shields.io/badge/TypeScript-Ready-blue.svg)](https://www.typescriptlang.org/)
8
+
9
+ ## What is Audixa?
10
+
11
+ Audixa is a powerful AI-powered text-to-speech platform that generates natural, human-like voices. This SDK provides a simple, type-safe way to integrate Audixa's TTS capabilities into your Node.js applications.
12
+
13
+ **Features:**
14
+ - 🎯 Full TypeScript support with complete type definitions
15
+ - 🔄 Dual module support (ESM + CommonJS)
16
+ - 🛡️ Robust error handling with custom error classes
17
+ - ⏱️ Configurable timeouts and request cancellation
18
+ - 📚 Comprehensive JSDoc documentation for IDE auto-completion
19
+
20
+ ## Installation
21
+
22
+ ```bash
23
+ npm install audixa
24
+ ```
25
+
26
+ or with yarn:
27
+
28
+ ```bash
29
+ yarn add audixa
30
+ ```
31
+
32
+ or with pnpm:
33
+
34
+ ```bash
35
+ pnpm add audixa
36
+ ```
37
+
38
+ ## Quick Start
39
+
40
+ ### TypeScript
41
+
42
+ ```typescript
43
+ import Audixa from 'audixa';
44
+
45
+ const audixa = new Audixa('your-api-key');
46
+
47
+ // Generate TTS and wait for completion
48
+ const audioUrl = await audixa.generateTTS({
49
+ text: 'Hello! This is a test of the Audixa text-to-speech API.',
50
+ voice: 'en-US-female-1',
51
+ model: 'base'
52
+ });
53
+
54
+ console.log('Audio URL:', audioUrl);
55
+ ```
56
+
57
+ ### JavaScript (CommonJS)
58
+
59
+ ```javascript
60
+ const { Audixa } = require('audixa');
61
+
62
+ const audixa = new Audixa('your-api-key');
63
+
64
+ // Generate TTS and wait for completion
65
+ audixa.generateTTS({
66
+ text: 'Hello! This is a test of the Audixa text-to-speech API.',
67
+ voice: 'en-US-female-1',
68
+ model: 'base'
69
+ }).then(audioUrl => {
70
+ console.log('Audio URL:', audioUrl);
71
+ });
72
+ ```
73
+
74
+ ### JavaScript (ESM)
75
+
76
+ ```javascript
77
+ import Audixa from 'audixa';
78
+
79
+ const audixa = new Audixa('your-api-key');
80
+
81
+ const audioUrl = await audixa.generateTTS({
82
+ text: 'Hello! This is a test of the Audixa text-to-speech API.',
83
+ voice: 'en-US-female-1'
84
+ });
85
+
86
+ console.log('Audio URL:', audioUrl);
87
+ ```
88
+
89
+ ## Configuration
90
+
91
+ ```typescript
92
+ import Audixa from 'audixa';
93
+
94
+ const audixa = new Audixa('your-api-key', {
95
+ baseUrl: 'https://api.audixa.ai/v2', // Custom API base URL (optional)
96
+ timeout: 30000 // Request timeout in ms (default: 30000)
97
+ });
98
+ ```
99
+
100
+ ## API Reference
101
+
102
+ ### Start TTS Generation
103
+
104
+ Creates a new text-to-speech task and returns a generation ID.
105
+
106
+ ```typescript
107
+ const { generation_id } = await audixa.startTTS({
108
+ // Required parameters
109
+ text: 'Your text here (minimum 30 characters)',
110
+ voice: 'en-US-female-1',
111
+
112
+ // Optional parameters
113
+ model: 'base', // 'base' or 'advance'
114
+ speed: 1.0, // 0.5 to 2.0
115
+
116
+ // Advance model only
117
+ emotion: 'happy', // 'neutral', 'happy', 'sad', 'angry', 'surprised'
118
+ temperature: 0.8, // 0.7 to 0.9
119
+ top_p: 0.9, // 0.7 to 0.98
120
+ do_sample: true
121
+ });
122
+
123
+ console.log('Generation ID:', generation_id);
124
+ ```
125
+
126
+ ### Poll TTS Status
127
+
128
+ Check the status of a TTS generation job.
129
+
130
+ ```typescript
131
+ const status = await audixa.getStatus(generation_id);
132
+
133
+ console.log('Status:', status.status); // 'Generating', 'Completed', or 'Failed'
134
+ console.log('Audio URL:', status.audio_url); // Available when status is 'Completed'
135
+ ```
136
+
137
+ ### Complete Polling Example
138
+
139
+ ```typescript
140
+ async function generateAndWait(text: string, voice: string): Promise<string> {
141
+ // Start generation
142
+ const { generation_id } = await audixa.startTTS({ text, voice });
143
+
144
+ // Poll until complete
145
+ while (true) {
146
+ const status = await audixa.getStatus(generation_id);
147
+
148
+ if (status.status === 'Completed') {
149
+ return status.audio_url!;
150
+ }
151
+
152
+ if (status.status === 'Failed') {
153
+ throw new Error('TTS generation failed');
154
+ }
155
+
156
+ // Wait 1 second before polling again
157
+ await new Promise(resolve => setTimeout(resolve, 1000));
158
+ }
159
+ }
160
+ ```
161
+
162
+ Or use the convenience method:
163
+
164
+ ```typescript
165
+ const audioUrl = await audixa.generateTTS(
166
+ { text: 'Your text here', voice: 'en-US-female-1' },
167
+ { pollInterval: 1000, maxWaitTime: 60000 }
168
+ );
169
+ ```
170
+
171
+ ### Get Available Voices
172
+
173
+ Retrieve the list of available voices for a specific model.
174
+
175
+ ```typescript
176
+ const { voices } = await audixa.getVoices('base');
177
+
178
+ for (const voice of voices) {
179
+ console.log(`${voice.name} (${voice.voice_id})`);
180
+ console.log(` Gender: ${voice.gender}`);
181
+ console.log(` Accent: ${voice.accent}`);
182
+ console.log(` Free: ${voice.free}`);
183
+ console.log(` Description: ${voice.description}`);
184
+ }
185
+ ```
186
+
187
+ ## Error Handling
188
+
189
+ The SDK provides a custom `AudixaError` class for comprehensive error handling:
190
+
191
+ ```typescript
192
+ import Audixa, { AudixaError } from 'audixa';
193
+
194
+ const audixa = new Audixa('your-api-key');
195
+
196
+ try {
197
+ const result = await audixa.startTTS({
198
+ text: 'Hello world',
199
+ voice: 'en-US-female-1'
200
+ });
201
+ } catch (error) {
202
+ if (error instanceof AudixaError) {
203
+ console.log('Error code:', error.code);
204
+ console.log('HTTP status:', error.status);
205
+ console.log('Message:', error.message);
206
+
207
+ switch (error.code) {
208
+ case 'INVALID_API_KEY':
209
+ console.log('Please check your API key');
210
+ break;
211
+ case 'INSUFFICIENT_CREDITS':
212
+ console.log('Please add more credits to your account');
213
+ break;
214
+ case 'INVALID_PARAMS':
215
+ console.log('Please check your request parameters');
216
+ break;
217
+ case 'FORBIDDEN':
218
+ console.log('You do not have access to this voice');
219
+ break;
220
+ case 'TIMEOUT':
221
+ console.log('The request timed out');
222
+ break;
223
+ case 'NETWORK_ERROR':
224
+ console.log('Network error occurred');
225
+ break;
226
+ }
227
+ }
228
+ }
229
+ ```
230
+
231
+ ### Error Codes
232
+
233
+ | Code | HTTP Status | Description |
234
+ |------|-------------|-------------|
235
+ | `INVALID_PARAMS` | 400 | Invalid request parameters |
236
+ | `INVALID_API_KEY` | 401 | Invalid or missing API key |
237
+ | `INSUFFICIENT_CREDITS` | 402 | Not enough credits in account |
238
+ | `FORBIDDEN` | 403 | Access denied to resource |
239
+ | `NOT_FOUND` | 404 | Resource not found |
240
+ | `TIMEOUT` | - | Request timed out |
241
+ | `NETWORK_ERROR` | - | Network connectivity issue |
242
+
243
+ ## Request Cancellation
244
+
245
+ All methods support cancellation via `AbortController`:
246
+
247
+ ```typescript
248
+ const controller = new AbortController();
249
+
250
+ // Cancel after 5 seconds
251
+ setTimeout(() => controller.abort(), 5000);
252
+
253
+ try {
254
+ const result = await audixa.startTTS(
255
+ { text: 'Hello world', voice: 'en-US-female-1' },
256
+ { signal: controller.signal }
257
+ );
258
+ } catch (error) {
259
+ if (error instanceof AudixaError && error.code === 'TIMEOUT') {
260
+ console.log('Request was cancelled');
261
+ }
262
+ }
263
+ ```
264
+
265
+ ## TypeScript Types
266
+
267
+ All types are exported for use in your TypeScript projects:
268
+
269
+ ```typescript
270
+ import Audixa, {
271
+ // Options
272
+ AudixaOptions,
273
+ RequestOptions,
274
+
275
+ // TTS types
276
+ StartTTSRequest,
277
+ StartTTSResponse,
278
+ TTSStatusResponse,
279
+ TTSModel,
280
+ TTSEmotion,
281
+ TTSStatus,
282
+
283
+ // Voice types
284
+ GetVoicesResponse,
285
+ Voice,
286
+
287
+ // Error types
288
+ AudixaError,
289
+ AudixaErrorCode
290
+ } from 'audixa';
291
+ ```
292
+
293
+ ### Type Definitions
294
+
295
+ ```typescript
296
+ // TTS Request
297
+ interface StartTTSRequest {
298
+ text: string; // Required, min 30 chars
299
+ voice: string; // Required
300
+ model?: 'base' | 'advance';
301
+ speed?: number; // 0.5 - 2.0
302
+
303
+ // Advance model only
304
+ emotion?: 'neutral' | 'happy' | 'sad' | 'angry' | 'surprised';
305
+ temperature?: number; // 0.7 - 0.9
306
+ top_p?: number; // 0.7 - 0.98
307
+ do_sample?: boolean;
308
+ }
309
+
310
+ // TTS Status Response
311
+ interface TTSStatusResponse {
312
+ status: 'Generating' | 'Completed' | 'Failed';
313
+ audio_url: string | null;
314
+ generation_id?: string;
315
+ }
316
+
317
+ // Voice
318
+ interface Voice {
319
+ voice_id: string;
320
+ name: string;
321
+ gender: string;
322
+ accent: string;
323
+ free: boolean;
324
+ description: string;
325
+ }
326
+ ```
327
+
328
+ ## Full API Documentation
329
+
330
+ For complete API documentation, visit: [https://docs.audixa.ai](https://docs.audixa.ai)
331
+
332
+ ## License
333
+
334
+ MIT © [anurag-pro](https://github.com/anurag-pro)
335
+
336
+ ## Links
337
+
338
+ - [Audixa Website](https://audixa.ai)
339
+ - [Audixa Dashboard](https://audixa.ai/dashboard)
340
+ - [API Documentation](https://docs.audixa.ai)
341
+ - [GitHub Repository](https://github.com/AudixaAI/audixa-npm-sdk)
342
+ - [npm Package](https://www.npmjs.com/package/audixa)