subformer 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.
@@ -0,0 +1,403 @@
1
+ /**
2
+ * Type definitions for Subformer SDK
3
+ */
4
+ /** Job execution state */
5
+ type JobState = "queued" | "active" | "completed" | "failed" | "cancelled";
6
+ /** Type of background job */
7
+ type JobType = "video-dubbing" | "voice-cloning" | "voice-synthesis" | "dub-studio-render-video";
8
+ /** Source type for dubbing jobs */
9
+ type DubSource = "youtube" | "tiktok" | "instagram" | "facebook" | "x" | "url";
10
+ /** Supported languages for dubbing */
11
+ type Language = "af-ZA" | "ar-SA" | "az-AZ" | "be-BY" | "bg-BG" | "bn-IN" | "bs-BA" | "ca-ES" | "cs-CZ" | "cy-GB" | "da-DK" | "de-DE" | "el-GR" | "en-US" | "es-ES" | "et-EE" | "fa-IR" | "fi-FI" | "fil-PH" | "fr-FR" | "gl-ES" | "gu-IN" | "he-IL" | "hi-IN" | "hr-HR" | "hu-HU" | "hy-AM" | "id-ID" | "is-IS" | "it-IT" | "ja-JP" | "jv-ID" | "ka-GE" | "kk-KZ" | "km-KH" | "kn-IN" | "ko-KR" | "la-VA" | "lt-LT" | "lv-LV" | "mk-MK" | "ml-IN" | "mn-MN" | "mr-IN" | "ms-MY" | "mt-MT" | "my-MM" | "nl-NL" | "no-NO" | "pa-IN" | "pl-PL" | "pt-BR" | "ro-RO" | "ru-RU" | "sk-SK" | "sl-SI" | "sq-AL" | "sr-RS" | "sv-SE" | "sw-KE" | "ta-IN" | "te-IN" | "th-TH" | "tl-PH" | "tr-TR" | "uk-UA" | "ur-PK" | "uz-UZ" | "vi-VN" | "zh-CN" | "zh-TW";
12
+ /** Progress information for a job */
13
+ interface JobProgress {
14
+ /** Progress percentage (0-100) */
15
+ progress: number;
16
+ /** Current status message */
17
+ message?: string;
18
+ /** Current processing step */
19
+ step?: string;
20
+ }
21
+ /** Metadata for a job */
22
+ interface JobMetadata {
23
+ title?: string;
24
+ thumbnailUrl?: string;
25
+ duration?: number;
26
+ sourceUrl?: string;
27
+ sourceType?: string;
28
+ originalLanguage?: string;
29
+ }
30
+ /** A background job */
31
+ interface Job {
32
+ id: string;
33
+ type: JobType;
34
+ userId: string;
35
+ state: JobState;
36
+ input?: unknown;
37
+ output?: unknown;
38
+ metadata?: JobMetadata | null;
39
+ createdAt: Date;
40
+ progress?: JobProgress | null;
41
+ processedOn?: Date | null;
42
+ finishedOn?: Date | null;
43
+ creditUsed?: number | null;
44
+ }
45
+ /** A saved voice in the voice library */
46
+ interface Voice {
47
+ id: string;
48
+ name: string;
49
+ audioUrl: string;
50
+ gender: "male" | "female";
51
+ duration: number;
52
+ createdAt: Date;
53
+ }
54
+ /** Target voice using a preset */
55
+ interface PresetVoice {
56
+ mode: "preset";
57
+ presetVoiceId: string;
58
+ }
59
+ /** Target voice using an uploaded audio file */
60
+ interface UploadedVoice {
61
+ mode: "upload";
62
+ targetAudioUrl: string;
63
+ }
64
+ /** Target voice for cloning or synthesis */
65
+ type TargetVoice = PresetVoice | UploadedVoice;
66
+ /** Paginated list of jobs */
67
+ interface PaginatedJobs {
68
+ data: Job[];
69
+ total: number;
70
+ }
71
+ /** Options for creating a dubbing job */
72
+ interface DubOptions {
73
+ /** Source type */
74
+ source: DubSource;
75
+ /** URL of the video to dub */
76
+ url: string;
77
+ /** Target language for dubbing */
78
+ language: Language | string;
79
+ /** Disable watermark (requires paid plan) */
80
+ disableWatermark?: boolean;
81
+ }
82
+ /** Options for listing jobs */
83
+ interface ListJobsOptions {
84
+ /** Number of items to skip */
85
+ offset?: number;
86
+ /** Maximum number of items to return */
87
+ limit?: number;
88
+ /** Filter by job type */
89
+ type?: JobType;
90
+ }
91
+ /** Options for waiting on a job */
92
+ interface WaitForJobOptions {
93
+ /** Seconds between status checks */
94
+ pollInterval?: number;
95
+ /** Maximum seconds to wait (undefined for no timeout) */
96
+ timeout?: number;
97
+ }
98
+ /** Options for voice cloning */
99
+ interface CloneVoiceOptions {
100
+ /** URL of the source audio to transform */
101
+ sourceAudioUrl: string;
102
+ /** Target voice (preset or uploaded) */
103
+ targetVoice: TargetVoice;
104
+ }
105
+ /** Options for voice synthesis */
106
+ interface SynthesizeVoiceOptions {
107
+ /** Text to synthesize */
108
+ text: string;
109
+ /** Target voice (preset or uploaded) */
110
+ targetVoice: TargetVoice;
111
+ }
112
+ /** Options for creating a voice */
113
+ interface CreateVoiceOptions {
114
+ /** Voice name */
115
+ name: string;
116
+ /** URL of the voice audio sample */
117
+ audioUrl: string;
118
+ /** Voice gender */
119
+ gender: "male" | "female";
120
+ /** Duration of audio sample in milliseconds */
121
+ duration: number;
122
+ }
123
+ /** Options for updating a voice */
124
+ interface UpdateVoiceOptions {
125
+ /** Voice ID */
126
+ voiceId: string;
127
+ /** New voice name */
128
+ name?: string;
129
+ /** New voice gender */
130
+ gender?: "male" | "female";
131
+ }
132
+ /** Options for generating a voice upload URL */
133
+ interface GenerateVoiceUploadUrlOptions {
134
+ /** Name of the file to upload */
135
+ fileName: string;
136
+ /** MIME type of the file */
137
+ contentType: string;
138
+ }
139
+ /** Presigned upload URL response */
140
+ interface UploadUrl {
141
+ uploadUrl: string;
142
+ fileUrl: string;
143
+ key: string;
144
+ }
145
+ /** Usage data for active subscription */
146
+ interface UsageData {
147
+ usedCredits: number;
148
+ planCredits: number;
149
+ totalEvents: number;
150
+ currentPlan: string;
151
+ periodStart: Date;
152
+ periodEnd: Date;
153
+ }
154
+ /** Current billing usage */
155
+ interface Usage {
156
+ type: string;
157
+ data: UsageData;
158
+ }
159
+ /** Daily usage statistics */
160
+ interface DailyUsage {
161
+ date: string;
162
+ "video-dubbing": number;
163
+ "voice-cloning": number;
164
+ "voice-synthesis": number;
165
+ "dub-studio-render-video": number;
166
+ }
167
+ /** User profile information */
168
+ interface User {
169
+ id: string;
170
+ name?: string | null;
171
+ email: string;
172
+ emailVerified: boolean;
173
+ image?: string | null;
174
+ preferredTargetLanguage?: string | null;
175
+ }
176
+ /** Rate limit status */
177
+ interface RateLimit {
178
+ remaining: number;
179
+ limit: number;
180
+ reset: number;
181
+ bucket: string;
182
+ }
183
+ /** Options for updating user profile */
184
+ interface UpdateUserOptions {
185
+ /** New name */
186
+ name: string;
187
+ /** New email */
188
+ email: string;
189
+ }
190
+
191
+ /**
192
+ * Subformer API client
193
+ */
194
+
195
+ interface SubformerOptions {
196
+ /** Your Subformer API key */
197
+ apiKey: string;
198
+ /** Base URL for the API (default: https://api.subformer.com/v1) */
199
+ baseUrl?: string;
200
+ /** Request timeout in milliseconds (default: 30000) */
201
+ timeout?: number;
202
+ }
203
+ /**
204
+ * Subformer API client for video dubbing, voice cloning, and text-to-speech.
205
+ *
206
+ * @example
207
+ * ```typescript
208
+ * import { Subformer } from 'subformer';
209
+ *
210
+ * const client = new Subformer({ apiKey: 'sk_subformer_...' });
211
+ *
212
+ * // Create a dubbing job
213
+ * const job = await client.dub({
214
+ * source: 'youtube',
215
+ * url: 'https://youtube.com/watch?v=VIDEO_ID',
216
+ * language: 'es-ES'
217
+ * });
218
+ *
219
+ * // Wait for completion
220
+ * const result = await client.waitForJob(job.id);
221
+ * console.log('Done!', result.output);
222
+ * ```
223
+ */
224
+ declare class Subformer {
225
+ private readonly apiKey;
226
+ private readonly baseUrl;
227
+ private readonly timeout;
228
+ constructor(options: SubformerOptions);
229
+ private request;
230
+ private handleError;
231
+ private transformDates;
232
+ /**
233
+ * Create a video dubbing job.
234
+ *
235
+ * @param options - Dubbing options
236
+ * @returns The created job
237
+ *
238
+ * @example
239
+ * ```typescript
240
+ * const job = await client.dub({
241
+ * source: 'youtube',
242
+ * url: 'https://youtube.com/watch?v=dQw4w9WgXcQ',
243
+ * language: 'es-ES'
244
+ * });
245
+ * ```
246
+ */
247
+ dub(options: DubOptions): Promise<Job>;
248
+ /**
249
+ * Get list of supported languages for dubbing.
250
+ *
251
+ * @returns List of language codes
252
+ */
253
+ getLanguages(): Promise<Language[]>;
254
+ /**
255
+ * Get a job by ID.
256
+ *
257
+ * @param jobId - The job ID
258
+ * @returns The job
259
+ */
260
+ getJob(jobId: string): Promise<Job>;
261
+ /**
262
+ * List jobs for the authenticated user.
263
+ *
264
+ * @param options - List options
265
+ * @returns Paginated list of jobs
266
+ */
267
+ listJobs(options?: ListJobsOptions): Promise<PaginatedJobs>;
268
+ /**
269
+ * Delete jobs by IDs.
270
+ *
271
+ * @param jobIds - List of job IDs to delete (max 50)
272
+ * @returns True if successful
273
+ */
274
+ deleteJobs(jobIds: string[]): Promise<boolean>;
275
+ /**
276
+ * Wait for a job to complete.
277
+ *
278
+ * @param jobId - The job ID
279
+ * @param options - Wait options
280
+ * @returns The completed job
281
+ * @throws {Error} If the job doesn't complete within the timeout
282
+ */
283
+ waitForJob(jobId: string, options?: WaitForJobOptions): Promise<Job>;
284
+ /**
285
+ * Create a voice cloning job.
286
+ *
287
+ * @param options - Voice cloning options
288
+ * @returns The created job
289
+ */
290
+ cloneVoice(options: CloneVoiceOptions): Promise<Job>;
291
+ /**
292
+ * Create a voice synthesis (text-to-speech) job.
293
+ *
294
+ * @param options - Voice synthesis options
295
+ * @returns The created job
296
+ */
297
+ synthesizeVoice(options: SynthesizeVoiceOptions): Promise<Job>;
298
+ /**
299
+ * List all voices in the user's voice library.
300
+ *
301
+ * @returns List of voices
302
+ */
303
+ listVoices(): Promise<Voice[]>;
304
+ /**
305
+ * Get a voice by ID.
306
+ *
307
+ * @param voiceId - The voice ID
308
+ * @returns The voice
309
+ */
310
+ getVoice(voiceId: string): Promise<Voice>;
311
+ /**
312
+ * Create a new voice in the voice library.
313
+ *
314
+ * @param options - Create voice options
315
+ * @returns The created voice
316
+ */
317
+ createVoice(options: CreateVoiceOptions): Promise<Voice>;
318
+ /**
319
+ * Update a voice in the voice library.
320
+ *
321
+ * @param options - Update voice options
322
+ * @returns The updated voice
323
+ */
324
+ updateVoice(options: UpdateVoiceOptions): Promise<Voice>;
325
+ /**
326
+ * Delete a voice from the voice library.
327
+ *
328
+ * @param voiceId - The voice ID
329
+ * @returns True if successful
330
+ */
331
+ deleteVoice(voiceId: string): Promise<boolean>;
332
+ /**
333
+ * Generate a presigned URL for uploading voice audio.
334
+ *
335
+ * @param options - Upload URL options
336
+ * @returns Upload URL details
337
+ */
338
+ generateVoiceUploadUrl(options: GenerateVoiceUploadUrlOptions): Promise<UploadUrl>;
339
+ /**
340
+ * Get current billing period usage statistics.
341
+ *
342
+ * @returns Current usage including credits, plan limits, and subscription details
343
+ */
344
+ getUsage(): Promise<Usage>;
345
+ /**
346
+ * Get daily usage statistics for the past 30 days.
347
+ *
348
+ * @returns List of daily usage records grouped by task type
349
+ */
350
+ getUsageHistory(): Promise<DailyUsage[]>;
351
+ /**
352
+ * Get the currently authenticated user's profile.
353
+ *
354
+ * @returns User profile information
355
+ */
356
+ getMe(): Promise<User>;
357
+ /**
358
+ * Update the currently authenticated user's profile.
359
+ *
360
+ * @param options - Update user options
361
+ * @returns Updated user profile
362
+ */
363
+ updateMe(options: UpdateUserOptions): Promise<User>;
364
+ /**
365
+ * Get the current rate limit status for creating dubbing jobs.
366
+ *
367
+ * @returns Rate limit status including remaining count and limit
368
+ */
369
+ getRateLimit(): Promise<RateLimit>;
370
+ }
371
+
372
+ /**
373
+ * Exceptions for Subformer SDK
374
+ */
375
+ /** Base error for Subformer SDK */
376
+ declare class SubformerError extends Error {
377
+ readonly statusCode?: number;
378
+ readonly code?: string;
379
+ readonly data?: unknown;
380
+ constructor(message: string, options?: {
381
+ statusCode?: number;
382
+ code?: string;
383
+ data?: unknown;
384
+ });
385
+ }
386
+ /** Raised when API authentication fails */
387
+ declare class AuthenticationError extends SubformerError {
388
+ constructor(message?: string);
389
+ }
390
+ /** Raised when a resource is not found */
391
+ declare class NotFoundError extends SubformerError {
392
+ constructor(message?: string);
393
+ }
394
+ /** Raised when rate limit is exceeded */
395
+ declare class RateLimitError extends SubformerError {
396
+ constructor(message?: string);
397
+ }
398
+ /** Raised when request validation fails */
399
+ declare class ValidationError extends SubformerError {
400
+ constructor(message: string, data?: unknown);
401
+ }
402
+
403
+ export { AuthenticationError, type CloneVoiceOptions, type CreateVoiceOptions, type DailyUsage, type DubOptions, type DubSource, type GenerateVoiceUploadUrlOptions, type Job, type JobMetadata, type JobProgress, type JobState, type JobType, type Language, type ListJobsOptions, NotFoundError, type PaginatedJobs, type PresetVoice, type RateLimit, RateLimitError, Subformer, SubformerError, type SubformerOptions, type SynthesizeVoiceOptions, type TargetVoice, type UpdateUserOptions, type UpdateVoiceOptions, type UploadUrl, type UploadedVoice, type Usage, type UsageData, type User, ValidationError, type Voice, type WaitForJobOptions };