kugelaudio 0.1.1
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/CHANGELOG.md +20 -0
- package/LICENSE +21 -0
- package/README.md +499 -0
- package/dist/index.d.mts +319 -0
- package/dist/index.d.ts +319 -0
- package/dist/index.js +421 -0
- package/dist/index.mjs +384 -0
- package/package.json +56 -0
- package/src/client.ts +370 -0
- package/src/errors.ts +73 -0
- package/src/index.ts +79 -0
- package/src/types.ts +184 -0
- package/src/utils.ts +120 -0
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,319 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Type definitions for KugelAudio SDK.
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* TTS model information.
|
|
6
|
+
*/
|
|
7
|
+
interface Model {
|
|
8
|
+
id: string;
|
|
9
|
+
name: string;
|
|
10
|
+
description: string;
|
|
11
|
+
parameters: string;
|
|
12
|
+
maxInputLength: number;
|
|
13
|
+
sampleRate: number;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Voice category types.
|
|
17
|
+
*/
|
|
18
|
+
type VoiceCategory = 'premade' | 'cloned' | 'designed';
|
|
19
|
+
/**
|
|
20
|
+
* Voice sex types.
|
|
21
|
+
*/
|
|
22
|
+
type VoiceSex = 'male' | 'female' | 'neutral';
|
|
23
|
+
/**
|
|
24
|
+
* Voice age types.
|
|
25
|
+
*/
|
|
26
|
+
type VoiceAge = 'young' | 'middle_aged' | 'old';
|
|
27
|
+
/**
|
|
28
|
+
* Voice information.
|
|
29
|
+
*/
|
|
30
|
+
interface Voice {
|
|
31
|
+
id: number;
|
|
32
|
+
name: string;
|
|
33
|
+
description?: string;
|
|
34
|
+
category?: VoiceCategory;
|
|
35
|
+
sex?: VoiceSex;
|
|
36
|
+
age?: VoiceAge;
|
|
37
|
+
supportedLanguages: string[];
|
|
38
|
+
sampleText?: string;
|
|
39
|
+
avatarUrl?: string;
|
|
40
|
+
sampleUrl?: string;
|
|
41
|
+
isPublic: boolean;
|
|
42
|
+
verified: boolean;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* TTS generation request options.
|
|
46
|
+
*/
|
|
47
|
+
interface GenerateOptions {
|
|
48
|
+
/** Text to synthesize */
|
|
49
|
+
text: string;
|
|
50
|
+
/** Model to use (default: 'kugel-one-turbo') */
|
|
51
|
+
model?: string;
|
|
52
|
+
/** Voice ID to use */
|
|
53
|
+
voiceId?: number;
|
|
54
|
+
/** CFG scale for generation (default: 2.0) */
|
|
55
|
+
cfgScale?: number;
|
|
56
|
+
/** Maximum tokens to generate (default: 2048) */
|
|
57
|
+
maxNewTokens?: number;
|
|
58
|
+
/** Output sample rate (default: 24000) */
|
|
59
|
+
sampleRate?: number;
|
|
60
|
+
/** Whether to add speaker prefix (default: true) */
|
|
61
|
+
speakerPrefix?: boolean;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Streaming session configuration.
|
|
65
|
+
*/
|
|
66
|
+
interface StreamConfig {
|
|
67
|
+
/** Voice ID to use */
|
|
68
|
+
voiceId?: number;
|
|
69
|
+
/** CFG scale for generation */
|
|
70
|
+
cfgScale?: number;
|
|
71
|
+
/** Maximum tokens per generation */
|
|
72
|
+
maxNewTokens?: number;
|
|
73
|
+
/** Output sample rate */
|
|
74
|
+
sampleRate?: number;
|
|
75
|
+
/** Whether to add speaker prefix */
|
|
76
|
+
speakerPrefix?: boolean;
|
|
77
|
+
/** Auto-flush timeout in milliseconds */
|
|
78
|
+
flushTimeoutMs?: number;
|
|
79
|
+
/** Maximum buffer length */
|
|
80
|
+
maxBufferLength?: number;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Audio chunk from streaming TTS.
|
|
84
|
+
*/
|
|
85
|
+
interface AudioChunk {
|
|
86
|
+
/** Raw PCM16 audio as base64 */
|
|
87
|
+
audio: string;
|
|
88
|
+
/** Encoding format */
|
|
89
|
+
encoding: 'pcm_s16le';
|
|
90
|
+
/** Chunk index */
|
|
91
|
+
index: number;
|
|
92
|
+
/** Sample rate */
|
|
93
|
+
sampleRate: number;
|
|
94
|
+
/** Number of samples */
|
|
95
|
+
samples: number;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Final message from TTS generation.
|
|
99
|
+
*/
|
|
100
|
+
interface GenerationStats {
|
|
101
|
+
/** Indicates this is the final message */
|
|
102
|
+
final: true;
|
|
103
|
+
/** Number of chunks generated */
|
|
104
|
+
chunks: number;
|
|
105
|
+
/** Total samples generated */
|
|
106
|
+
totalSamples: number;
|
|
107
|
+
/** Duration of audio in milliseconds */
|
|
108
|
+
durationMs: number;
|
|
109
|
+
/** Generation time in milliseconds */
|
|
110
|
+
generationMs: number;
|
|
111
|
+
/** Time to first audio in milliseconds */
|
|
112
|
+
ttfaMs: number | null;
|
|
113
|
+
/** Real-time factor */
|
|
114
|
+
rtf: number;
|
|
115
|
+
/** Error message if any */
|
|
116
|
+
error?: string;
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Complete audio response from TTS generation.
|
|
120
|
+
*/
|
|
121
|
+
interface AudioResponse {
|
|
122
|
+
/** Raw PCM16 audio bytes as ArrayBuffer */
|
|
123
|
+
audio: ArrayBuffer;
|
|
124
|
+
/** Sample rate */
|
|
125
|
+
sampleRate: number;
|
|
126
|
+
/** Number of samples */
|
|
127
|
+
samples: number;
|
|
128
|
+
/** Duration in milliseconds */
|
|
129
|
+
durationMs: number;
|
|
130
|
+
/** Generation time in milliseconds */
|
|
131
|
+
generationMs: number;
|
|
132
|
+
/** Real-time factor */
|
|
133
|
+
rtf: number;
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Event callbacks for streaming.
|
|
137
|
+
*/
|
|
138
|
+
interface StreamCallbacks {
|
|
139
|
+
/** Called when an audio chunk is received */
|
|
140
|
+
onChunk?: (chunk: AudioChunk) => void;
|
|
141
|
+
/** Called when generation is complete */
|
|
142
|
+
onFinal?: (stats: GenerationStats) => void;
|
|
143
|
+
/** Called on error */
|
|
144
|
+
onError?: (error: Error) => void;
|
|
145
|
+
/** Called when connection opens */
|
|
146
|
+
onOpen?: () => void;
|
|
147
|
+
/** Called when connection closes */
|
|
148
|
+
onClose?: () => void;
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* KugelAudio client options.
|
|
152
|
+
*/
|
|
153
|
+
interface KugelAudioOptions {
|
|
154
|
+
/** Your KugelAudio API key */
|
|
155
|
+
apiKey: string;
|
|
156
|
+
/** API base URL (default: https://api.kugelaudio.com) */
|
|
157
|
+
apiUrl?: string;
|
|
158
|
+
/** TTS server URL (default: https://eu.kugelaudio.com) */
|
|
159
|
+
ttsUrl?: string;
|
|
160
|
+
/** Request timeout in milliseconds (default: 60000) */
|
|
161
|
+
timeout?: number;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* KugelAudio API Client.
|
|
166
|
+
*/
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* Models resource for listing TTS models.
|
|
170
|
+
*/
|
|
171
|
+
declare class ModelsResource {
|
|
172
|
+
private client;
|
|
173
|
+
constructor(client: KugelAudio);
|
|
174
|
+
/**
|
|
175
|
+
* List available TTS models.
|
|
176
|
+
*/
|
|
177
|
+
list(): Promise<Model[]>;
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* Voices resource for managing voices.
|
|
181
|
+
*/
|
|
182
|
+
declare class VoicesResource {
|
|
183
|
+
private client;
|
|
184
|
+
constructor(client: KugelAudio);
|
|
185
|
+
/**
|
|
186
|
+
* List available voices.
|
|
187
|
+
*/
|
|
188
|
+
list(options?: {
|
|
189
|
+
language?: string;
|
|
190
|
+
includePublic?: boolean;
|
|
191
|
+
limit?: number;
|
|
192
|
+
}): Promise<Voice[]>;
|
|
193
|
+
/**
|
|
194
|
+
* Get a specific voice by ID.
|
|
195
|
+
*/
|
|
196
|
+
get(voiceId: number): Promise<Voice>;
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* TTS resource for text-to-speech generation.
|
|
200
|
+
*/
|
|
201
|
+
declare class TTSResource {
|
|
202
|
+
private client;
|
|
203
|
+
constructor(client: KugelAudio);
|
|
204
|
+
/**
|
|
205
|
+
* Generate audio from text with streaming via WebSocket.
|
|
206
|
+
* Returns complete audio after all chunks are received.
|
|
207
|
+
*/
|
|
208
|
+
generate(options: GenerateOptions): Promise<AudioResponse>;
|
|
209
|
+
/**
|
|
210
|
+
* Stream audio from text via WebSocket.
|
|
211
|
+
*/
|
|
212
|
+
stream(options: GenerateOptions, callbacks: StreamCallbacks): Promise<void>;
|
|
213
|
+
private parseError;
|
|
214
|
+
}
|
|
215
|
+
/**
|
|
216
|
+
* KugelAudio API client.
|
|
217
|
+
*
|
|
218
|
+
* @example
|
|
219
|
+
* ```typescript
|
|
220
|
+
* const client = new KugelAudio({ apiKey: 'your_api_key' });
|
|
221
|
+
*
|
|
222
|
+
* // List models
|
|
223
|
+
* const models = await client.models.list();
|
|
224
|
+
*
|
|
225
|
+
* // List voices
|
|
226
|
+
* const voices = await client.voices.list();
|
|
227
|
+
*
|
|
228
|
+
* // Generate audio
|
|
229
|
+
* const audio = await client.tts.generate({
|
|
230
|
+
* text: 'Hello, world!',
|
|
231
|
+
* model: 'kugel-one-turbo',
|
|
232
|
+
* });
|
|
233
|
+
* ```
|
|
234
|
+
*/
|
|
235
|
+
declare class KugelAudio {
|
|
236
|
+
private _apiKey;
|
|
237
|
+
private _apiUrl;
|
|
238
|
+
private _ttsUrl;
|
|
239
|
+
private _timeout;
|
|
240
|
+
/** Models resource */
|
|
241
|
+
readonly models: ModelsResource;
|
|
242
|
+
/** Voices resource */
|
|
243
|
+
readonly voices: VoicesResource;
|
|
244
|
+
/** TTS resource */
|
|
245
|
+
readonly tts: TTSResource;
|
|
246
|
+
constructor(options: KugelAudioOptions);
|
|
247
|
+
/** Get API key */
|
|
248
|
+
get apiKey(): string;
|
|
249
|
+
/** Get TTS URL */
|
|
250
|
+
get ttsUrl(): string;
|
|
251
|
+
/**
|
|
252
|
+
* Make an HTTP request to the API.
|
|
253
|
+
* @internal
|
|
254
|
+
*/
|
|
255
|
+
request<T>(method: string, path: string, body?: unknown): Promise<T>;
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
/**
|
|
259
|
+
* Custom errors for KugelAudio SDK.
|
|
260
|
+
*/
|
|
261
|
+
/**
|
|
262
|
+
* Base error class for KugelAudio SDK.
|
|
263
|
+
*/
|
|
264
|
+
declare class KugelAudioError extends Error {
|
|
265
|
+
readonly statusCode?: number;
|
|
266
|
+
constructor(message: string, statusCode?: number);
|
|
267
|
+
}
|
|
268
|
+
/**
|
|
269
|
+
* Thrown when authentication fails.
|
|
270
|
+
*/
|
|
271
|
+
declare class AuthenticationError extends KugelAudioError {
|
|
272
|
+
constructor(message?: string);
|
|
273
|
+
}
|
|
274
|
+
/**
|
|
275
|
+
* Thrown when rate limit is exceeded.
|
|
276
|
+
*/
|
|
277
|
+
declare class RateLimitError extends KugelAudioError {
|
|
278
|
+
constructor(message?: string);
|
|
279
|
+
}
|
|
280
|
+
/**
|
|
281
|
+
* Thrown when user has insufficient credits.
|
|
282
|
+
*/
|
|
283
|
+
declare class InsufficientCreditsError extends KugelAudioError {
|
|
284
|
+
constructor(message?: string);
|
|
285
|
+
}
|
|
286
|
+
/**
|
|
287
|
+
* Thrown when request validation fails.
|
|
288
|
+
*/
|
|
289
|
+
declare class ValidationError extends KugelAudioError {
|
|
290
|
+
constructor(message: string);
|
|
291
|
+
}
|
|
292
|
+
/**
|
|
293
|
+
* Thrown when connection to server fails.
|
|
294
|
+
*/
|
|
295
|
+
declare class ConnectionError extends KugelAudioError {
|
|
296
|
+
constructor(message?: string);
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
/**
|
|
300
|
+
* Utility functions for KugelAudio SDK.
|
|
301
|
+
*/
|
|
302
|
+
/**
|
|
303
|
+
* Decode base64 string to ArrayBuffer.
|
|
304
|
+
*/
|
|
305
|
+
declare function base64ToArrayBuffer(base64: string): ArrayBuffer;
|
|
306
|
+
/**
|
|
307
|
+
* Decode PCM16 base64 audio to Float32Array.
|
|
308
|
+
*/
|
|
309
|
+
declare function decodePCM16(base64: string): Float32Array;
|
|
310
|
+
/**
|
|
311
|
+
* Create a WAV file from PCM16 audio data.
|
|
312
|
+
*/
|
|
313
|
+
declare function createWavFile(audio: ArrayBuffer, sampleRate: number): ArrayBuffer;
|
|
314
|
+
/**
|
|
315
|
+
* Create a Blob from WAV data for browser use.
|
|
316
|
+
*/
|
|
317
|
+
declare function createWavBlob(audio: ArrayBuffer, sampleRate: number): Blob;
|
|
318
|
+
|
|
319
|
+
export { type AudioChunk, type AudioResponse, AuthenticationError, ConnectionError, type GenerateOptions, type GenerationStats, InsufficientCreditsError, KugelAudio, KugelAudioError, type KugelAudioOptions, type Model, RateLimitError, type StreamCallbacks, type StreamConfig, ValidationError, type Voice, type VoiceAge, type VoiceCategory, type VoiceSex, base64ToArrayBuffer, createWavBlob, createWavFile, decodePCM16 };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,319 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Type definitions for KugelAudio SDK.
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* TTS model information.
|
|
6
|
+
*/
|
|
7
|
+
interface Model {
|
|
8
|
+
id: string;
|
|
9
|
+
name: string;
|
|
10
|
+
description: string;
|
|
11
|
+
parameters: string;
|
|
12
|
+
maxInputLength: number;
|
|
13
|
+
sampleRate: number;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Voice category types.
|
|
17
|
+
*/
|
|
18
|
+
type VoiceCategory = 'premade' | 'cloned' | 'designed';
|
|
19
|
+
/**
|
|
20
|
+
* Voice sex types.
|
|
21
|
+
*/
|
|
22
|
+
type VoiceSex = 'male' | 'female' | 'neutral';
|
|
23
|
+
/**
|
|
24
|
+
* Voice age types.
|
|
25
|
+
*/
|
|
26
|
+
type VoiceAge = 'young' | 'middle_aged' | 'old';
|
|
27
|
+
/**
|
|
28
|
+
* Voice information.
|
|
29
|
+
*/
|
|
30
|
+
interface Voice {
|
|
31
|
+
id: number;
|
|
32
|
+
name: string;
|
|
33
|
+
description?: string;
|
|
34
|
+
category?: VoiceCategory;
|
|
35
|
+
sex?: VoiceSex;
|
|
36
|
+
age?: VoiceAge;
|
|
37
|
+
supportedLanguages: string[];
|
|
38
|
+
sampleText?: string;
|
|
39
|
+
avatarUrl?: string;
|
|
40
|
+
sampleUrl?: string;
|
|
41
|
+
isPublic: boolean;
|
|
42
|
+
verified: boolean;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* TTS generation request options.
|
|
46
|
+
*/
|
|
47
|
+
interface GenerateOptions {
|
|
48
|
+
/** Text to synthesize */
|
|
49
|
+
text: string;
|
|
50
|
+
/** Model to use (default: 'kugel-one-turbo') */
|
|
51
|
+
model?: string;
|
|
52
|
+
/** Voice ID to use */
|
|
53
|
+
voiceId?: number;
|
|
54
|
+
/** CFG scale for generation (default: 2.0) */
|
|
55
|
+
cfgScale?: number;
|
|
56
|
+
/** Maximum tokens to generate (default: 2048) */
|
|
57
|
+
maxNewTokens?: number;
|
|
58
|
+
/** Output sample rate (default: 24000) */
|
|
59
|
+
sampleRate?: number;
|
|
60
|
+
/** Whether to add speaker prefix (default: true) */
|
|
61
|
+
speakerPrefix?: boolean;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Streaming session configuration.
|
|
65
|
+
*/
|
|
66
|
+
interface StreamConfig {
|
|
67
|
+
/** Voice ID to use */
|
|
68
|
+
voiceId?: number;
|
|
69
|
+
/** CFG scale for generation */
|
|
70
|
+
cfgScale?: number;
|
|
71
|
+
/** Maximum tokens per generation */
|
|
72
|
+
maxNewTokens?: number;
|
|
73
|
+
/** Output sample rate */
|
|
74
|
+
sampleRate?: number;
|
|
75
|
+
/** Whether to add speaker prefix */
|
|
76
|
+
speakerPrefix?: boolean;
|
|
77
|
+
/** Auto-flush timeout in milliseconds */
|
|
78
|
+
flushTimeoutMs?: number;
|
|
79
|
+
/** Maximum buffer length */
|
|
80
|
+
maxBufferLength?: number;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Audio chunk from streaming TTS.
|
|
84
|
+
*/
|
|
85
|
+
interface AudioChunk {
|
|
86
|
+
/** Raw PCM16 audio as base64 */
|
|
87
|
+
audio: string;
|
|
88
|
+
/** Encoding format */
|
|
89
|
+
encoding: 'pcm_s16le';
|
|
90
|
+
/** Chunk index */
|
|
91
|
+
index: number;
|
|
92
|
+
/** Sample rate */
|
|
93
|
+
sampleRate: number;
|
|
94
|
+
/** Number of samples */
|
|
95
|
+
samples: number;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Final message from TTS generation.
|
|
99
|
+
*/
|
|
100
|
+
interface GenerationStats {
|
|
101
|
+
/** Indicates this is the final message */
|
|
102
|
+
final: true;
|
|
103
|
+
/** Number of chunks generated */
|
|
104
|
+
chunks: number;
|
|
105
|
+
/** Total samples generated */
|
|
106
|
+
totalSamples: number;
|
|
107
|
+
/** Duration of audio in milliseconds */
|
|
108
|
+
durationMs: number;
|
|
109
|
+
/** Generation time in milliseconds */
|
|
110
|
+
generationMs: number;
|
|
111
|
+
/** Time to first audio in milliseconds */
|
|
112
|
+
ttfaMs: number | null;
|
|
113
|
+
/** Real-time factor */
|
|
114
|
+
rtf: number;
|
|
115
|
+
/** Error message if any */
|
|
116
|
+
error?: string;
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Complete audio response from TTS generation.
|
|
120
|
+
*/
|
|
121
|
+
interface AudioResponse {
|
|
122
|
+
/** Raw PCM16 audio bytes as ArrayBuffer */
|
|
123
|
+
audio: ArrayBuffer;
|
|
124
|
+
/** Sample rate */
|
|
125
|
+
sampleRate: number;
|
|
126
|
+
/** Number of samples */
|
|
127
|
+
samples: number;
|
|
128
|
+
/** Duration in milliseconds */
|
|
129
|
+
durationMs: number;
|
|
130
|
+
/** Generation time in milliseconds */
|
|
131
|
+
generationMs: number;
|
|
132
|
+
/** Real-time factor */
|
|
133
|
+
rtf: number;
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Event callbacks for streaming.
|
|
137
|
+
*/
|
|
138
|
+
interface StreamCallbacks {
|
|
139
|
+
/** Called when an audio chunk is received */
|
|
140
|
+
onChunk?: (chunk: AudioChunk) => void;
|
|
141
|
+
/** Called when generation is complete */
|
|
142
|
+
onFinal?: (stats: GenerationStats) => void;
|
|
143
|
+
/** Called on error */
|
|
144
|
+
onError?: (error: Error) => void;
|
|
145
|
+
/** Called when connection opens */
|
|
146
|
+
onOpen?: () => void;
|
|
147
|
+
/** Called when connection closes */
|
|
148
|
+
onClose?: () => void;
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* KugelAudio client options.
|
|
152
|
+
*/
|
|
153
|
+
interface KugelAudioOptions {
|
|
154
|
+
/** Your KugelAudio API key */
|
|
155
|
+
apiKey: string;
|
|
156
|
+
/** API base URL (default: https://api.kugelaudio.com) */
|
|
157
|
+
apiUrl?: string;
|
|
158
|
+
/** TTS server URL (default: https://eu.kugelaudio.com) */
|
|
159
|
+
ttsUrl?: string;
|
|
160
|
+
/** Request timeout in milliseconds (default: 60000) */
|
|
161
|
+
timeout?: number;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* KugelAudio API Client.
|
|
166
|
+
*/
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* Models resource for listing TTS models.
|
|
170
|
+
*/
|
|
171
|
+
declare class ModelsResource {
|
|
172
|
+
private client;
|
|
173
|
+
constructor(client: KugelAudio);
|
|
174
|
+
/**
|
|
175
|
+
* List available TTS models.
|
|
176
|
+
*/
|
|
177
|
+
list(): Promise<Model[]>;
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* Voices resource for managing voices.
|
|
181
|
+
*/
|
|
182
|
+
declare class VoicesResource {
|
|
183
|
+
private client;
|
|
184
|
+
constructor(client: KugelAudio);
|
|
185
|
+
/**
|
|
186
|
+
* List available voices.
|
|
187
|
+
*/
|
|
188
|
+
list(options?: {
|
|
189
|
+
language?: string;
|
|
190
|
+
includePublic?: boolean;
|
|
191
|
+
limit?: number;
|
|
192
|
+
}): Promise<Voice[]>;
|
|
193
|
+
/**
|
|
194
|
+
* Get a specific voice by ID.
|
|
195
|
+
*/
|
|
196
|
+
get(voiceId: number): Promise<Voice>;
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* TTS resource for text-to-speech generation.
|
|
200
|
+
*/
|
|
201
|
+
declare class TTSResource {
|
|
202
|
+
private client;
|
|
203
|
+
constructor(client: KugelAudio);
|
|
204
|
+
/**
|
|
205
|
+
* Generate audio from text with streaming via WebSocket.
|
|
206
|
+
* Returns complete audio after all chunks are received.
|
|
207
|
+
*/
|
|
208
|
+
generate(options: GenerateOptions): Promise<AudioResponse>;
|
|
209
|
+
/**
|
|
210
|
+
* Stream audio from text via WebSocket.
|
|
211
|
+
*/
|
|
212
|
+
stream(options: GenerateOptions, callbacks: StreamCallbacks): Promise<void>;
|
|
213
|
+
private parseError;
|
|
214
|
+
}
|
|
215
|
+
/**
|
|
216
|
+
* KugelAudio API client.
|
|
217
|
+
*
|
|
218
|
+
* @example
|
|
219
|
+
* ```typescript
|
|
220
|
+
* const client = new KugelAudio({ apiKey: 'your_api_key' });
|
|
221
|
+
*
|
|
222
|
+
* // List models
|
|
223
|
+
* const models = await client.models.list();
|
|
224
|
+
*
|
|
225
|
+
* // List voices
|
|
226
|
+
* const voices = await client.voices.list();
|
|
227
|
+
*
|
|
228
|
+
* // Generate audio
|
|
229
|
+
* const audio = await client.tts.generate({
|
|
230
|
+
* text: 'Hello, world!',
|
|
231
|
+
* model: 'kugel-one-turbo',
|
|
232
|
+
* });
|
|
233
|
+
* ```
|
|
234
|
+
*/
|
|
235
|
+
declare class KugelAudio {
|
|
236
|
+
private _apiKey;
|
|
237
|
+
private _apiUrl;
|
|
238
|
+
private _ttsUrl;
|
|
239
|
+
private _timeout;
|
|
240
|
+
/** Models resource */
|
|
241
|
+
readonly models: ModelsResource;
|
|
242
|
+
/** Voices resource */
|
|
243
|
+
readonly voices: VoicesResource;
|
|
244
|
+
/** TTS resource */
|
|
245
|
+
readonly tts: TTSResource;
|
|
246
|
+
constructor(options: KugelAudioOptions);
|
|
247
|
+
/** Get API key */
|
|
248
|
+
get apiKey(): string;
|
|
249
|
+
/** Get TTS URL */
|
|
250
|
+
get ttsUrl(): string;
|
|
251
|
+
/**
|
|
252
|
+
* Make an HTTP request to the API.
|
|
253
|
+
* @internal
|
|
254
|
+
*/
|
|
255
|
+
request<T>(method: string, path: string, body?: unknown): Promise<T>;
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
/**
|
|
259
|
+
* Custom errors for KugelAudio SDK.
|
|
260
|
+
*/
|
|
261
|
+
/**
|
|
262
|
+
* Base error class for KugelAudio SDK.
|
|
263
|
+
*/
|
|
264
|
+
declare class KugelAudioError extends Error {
|
|
265
|
+
readonly statusCode?: number;
|
|
266
|
+
constructor(message: string, statusCode?: number);
|
|
267
|
+
}
|
|
268
|
+
/**
|
|
269
|
+
* Thrown when authentication fails.
|
|
270
|
+
*/
|
|
271
|
+
declare class AuthenticationError extends KugelAudioError {
|
|
272
|
+
constructor(message?: string);
|
|
273
|
+
}
|
|
274
|
+
/**
|
|
275
|
+
* Thrown when rate limit is exceeded.
|
|
276
|
+
*/
|
|
277
|
+
declare class RateLimitError extends KugelAudioError {
|
|
278
|
+
constructor(message?: string);
|
|
279
|
+
}
|
|
280
|
+
/**
|
|
281
|
+
* Thrown when user has insufficient credits.
|
|
282
|
+
*/
|
|
283
|
+
declare class InsufficientCreditsError extends KugelAudioError {
|
|
284
|
+
constructor(message?: string);
|
|
285
|
+
}
|
|
286
|
+
/**
|
|
287
|
+
* Thrown when request validation fails.
|
|
288
|
+
*/
|
|
289
|
+
declare class ValidationError extends KugelAudioError {
|
|
290
|
+
constructor(message: string);
|
|
291
|
+
}
|
|
292
|
+
/**
|
|
293
|
+
* Thrown when connection to server fails.
|
|
294
|
+
*/
|
|
295
|
+
declare class ConnectionError extends KugelAudioError {
|
|
296
|
+
constructor(message?: string);
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
/**
|
|
300
|
+
* Utility functions for KugelAudio SDK.
|
|
301
|
+
*/
|
|
302
|
+
/**
|
|
303
|
+
* Decode base64 string to ArrayBuffer.
|
|
304
|
+
*/
|
|
305
|
+
declare function base64ToArrayBuffer(base64: string): ArrayBuffer;
|
|
306
|
+
/**
|
|
307
|
+
* Decode PCM16 base64 audio to Float32Array.
|
|
308
|
+
*/
|
|
309
|
+
declare function decodePCM16(base64: string): Float32Array;
|
|
310
|
+
/**
|
|
311
|
+
* Create a WAV file from PCM16 audio data.
|
|
312
|
+
*/
|
|
313
|
+
declare function createWavFile(audio: ArrayBuffer, sampleRate: number): ArrayBuffer;
|
|
314
|
+
/**
|
|
315
|
+
* Create a Blob from WAV data for browser use.
|
|
316
|
+
*/
|
|
317
|
+
declare function createWavBlob(audio: ArrayBuffer, sampleRate: number): Blob;
|
|
318
|
+
|
|
319
|
+
export { type AudioChunk, type AudioResponse, AuthenticationError, ConnectionError, type GenerateOptions, type GenerationStats, InsufficientCreditsError, KugelAudio, KugelAudioError, type KugelAudioOptions, type Model, RateLimitError, type StreamCallbacks, type StreamConfig, ValidationError, type Voice, type VoiceAge, type VoiceCategory, type VoiceSex, base64ToArrayBuffer, createWavBlob, createWavFile, decodePCM16 };
|