UNPKG

@tsavo/creatify-api-ts

Version:

TypeScript client for the Creatify AI API

271 lines (265 loc) 10.2 kB
import { C as CreatifyApiOptions, c as ICreatifyApiClientFactory, A as Avatar, T as TextToSpeech, b as CreatifyApiClientFactory, d as AiEditing, e as AiShorts, f as AiScripts, L as LipsyncV2 } from './client-factory-BpS2ubWp.js'; /** * A utility class to simplify avatar video creation */ declare class VideoCreator { private creatify; private avatarApi; private avatarCache; private voiceCache; private avatarsLoaded; private voicesLoaded; /** * Create a new VideoCreator instance * @param apiIdOrOptions Your Creatify API ID or options object * @param apiKey Your Creatify API Key (optional if options object is used) * @param clientFactory Optional factory for creating API clients (useful for testing) */ constructor(apiIdOrOptions: string | CreatifyApiOptions, apiKey?: string, clientFactory?: ICreatifyApiClientFactory); /** * Preload avatars and voices for faster video creation */ preload(): Promise<{ avatars: number; voices: number; }>; /** * Load and cache all available avatars */ loadAvatars(): Promise<Avatar.AvatarInfo[]>; /** * Load and cache all available voices */ loadVoices(): Promise<Avatar.VoiceInfo[] | TextToSpeech.Voice[]>; /** * Find an avatar by name (partial match) * @param name Avatar name to search for */ findAvatarByName(name: string): Promise<Avatar.AvatarInfo | undefined>; /** * Find a voice by name (partial match) * @param name Voice name to search for */ findVoiceByName(name: string): Promise<TextToSpeech.Voice | undefined>; /** * Create a video with a single avatar speaking * @param options Configuration options for the video * @returns The URL of the generated video */ createVideo(options: { avatarName?: string; avatarId?: string; voiceName?: string; voiceId?: string; script: string; aspectRatio?: string; pollInterval?: number; maxPollingAttempts?: number; }): Promise<{ id: string; status: string; url: string; }>; /** * Create a video with multiple avatars having a conversation * @param options Configuration options for the conversation * @returns The URL of the generated video */ createConversation(options: { conversation: Array<{ avatarName?: string; avatarId?: string; voiceName?: string; voiceId?: string; text: string; }>; backgroundUrl?: string; aspectRatio?: string; pollInterval?: number; maxPollingAttempts?: number; }): Promise<{ id: string; status: string; url: string; }>; } /** * Utility class for processing audio with the Creatify Text-to-Speech API */ declare class AudioProcessor { private api; /** * Create a new AudioProcessor * @param apiIdOrOptions API ID or full options object * @param apiKey API key (only required if apiIdOrOptions is a string) */ constructor(apiIdOrOptions: string | CreatifyApiOptions, apiKey?: string); /** * Generate audio from text * @param script Text to convert to speech * @param accentId Voice/accent ID to use * @param waitForCompletion Whether to wait for the task to complete (default: true) * @returns Promise resolving to the audio task result or response */ generateAudio(script: string, accentId: string, waitForCompletion?: boolean): Promise<TextToSpeech.TextToSpeechResultResponse | TextToSpeech.TextToSpeechResponse>; /** * Check the status of an audio generation task * @param id ID of the text-to-speech task * @returns Promise resolving to the task status and result */ checkAudioStatus(id: string): Promise<TextToSpeech.TextToSpeechResultResponse>; /** * Poll for audio generation completion * @param id ID of the text-to-speech task * @param pollInterval Interval in ms between status checks (default: 2000) * @param maxAttempts Maximum number of polling attempts (default: 60) * @returns Promise resolving to the final task result */ waitForAudioCompletion(id: string, pollInterval?: number, maxAttempts?: number): Promise<TextToSpeech.TextToSpeechResultResponse>; /** * List all audio generation tasks * @returns Promise resolving to an array of tasks */ listAudioTasks(): Promise<TextToSpeech.TextToSpeechResultResponse[]>; } /** * Batch processing options */ interface BatchProcessingOptions { /** * Maximum number of concurrent tasks (default: 3) */ concurrency?: number; /** * Whether to continue processing if one task fails (default: false) */ continueOnError?: boolean; /** * Delay between starting new tasks in milliseconds (default: 500) */ taskStartDelay?: number; /** * Maximum number of retries for failed tasks (default: 0) */ maxRetries?: number; } /** * Result of a batch processing operation */ interface BatchResult<T> { /** * Array of successful results */ successes: T[]; /** * Array of errors, with the index of the task that failed */ errors: Array<{ index: number; error: Error | unknown; }>; /** * Whether all tasks were successful */ allSuccessful: boolean; } /** * Utility class for processing multiple API tasks in batch */ declare class BatchProcessor { private api; /** * Create a new BatchProcessor * @param apiIdOrOptions API ID or full options object * @param apiKey API key (only required if apiIdOrOptions is a string) * @param clientFactory Optional client factory for testing purposes */ constructor(apiIdOrOptions: string | CreatifyApiOptions, apiKey?: string, _clientFactory?: CreatifyApiClientFactory); /** * Process an array of tasks in batch with controlled concurrency * @param tasks Array of async functions to execute * @param options Batch processing options * @returns Promise resolving to the batch result */ processBatch<T>(tasks: Array<() => Promise<T>>, options?: BatchProcessingOptions): Promise<BatchResult<T>>; /** * Process an array of avatar video creation tasks in batch * @param avatarTasks Array of avatar tasks with text and avatarId * @param options Batch processing options * @returns Promise resolving to the batch result */ processAvatarBatch(avatarTasks: Array<{ text: string; avatarId: string; voiceId?: string; aspectRatio?: string; }>, options?: BatchProcessingOptions): Promise<BatchResult<Avatar.LipsyncResultResponse>>; /** * Process an array of text-to-speech tasks in batch * @param textToSpeechTasks Array of text-to-speech tasks with script and accent * @param options Batch processing options * @returns Promise resolving to the batch result */ processTextToSpeechBatch(textToSpeechTasks: Array<{ script: string; accent: string; }>, options?: BatchProcessingOptions): Promise<BatchResult<TextToSpeech.TextToSpeechResultResponse>>; /** * Process an array of AI editing tasks in batch * @param aiEditingTasks Array of AI editing tasks with videoUrl and editingStyle * @param options Batch processing options * @returns Promise resolving to the batch result */ processAiEditingBatch(aiEditingTasks: Array<{ videoUrl: string; editingStyle: string; }>, options?: BatchProcessingOptions): Promise<BatchResult<AiEditing.AiEditingResultResponse>>; /** * Process an array of AI Shorts tasks in batch * @param aiShortsTasks Array of AI Shorts tasks with prompt and aspectRatio * @param options Batch processing options * @returns Promise resolving to the batch result */ processAiShortsBatch(aiShortsTasks: Array<{ prompt: string; aspectRatio: string; targetPlatform?: string; targetAudience?: string; language?: string; }>, options?: BatchProcessingOptions): Promise<BatchResult<AiShorts.AiShortsResultResponse>>; /** * Process an array of AI Scripts tasks in batch * @param aiScriptsTasks Array of AI Scripts tasks with prompt and other optional parameters * @param options Batch processing options * @returns Promise resolving to the batch result */ processAiScriptsBatch(aiScriptsTasks: Array<{ prompt: string; targetPlatform?: string; targetAudience?: string; language?: string; scriptLength?: number; }>, options?: BatchProcessingOptions): Promise<BatchResult<AiScripts.AiScriptsResultResponse>>; /** * Process an array of Lipsync v2 tasks in batch * @param lipsyncV2Tasks Array of Lipsync v2 tasks with videoInputs and aspectRatio * @param options Batch processing options * @returns Promise resolving to the batch result */ processLipsyncV2Batch(lipsyncV2Tasks: Array<{ videoInputs: Record<string, unknown>[]; aspectRatio: string; }>, options?: BatchProcessingOptions): Promise<BatchResult<LipsyncV2.LipsyncV2ResultResponse>>; } type index_AudioProcessor = AudioProcessor; declare const index_AudioProcessor: typeof AudioProcessor; type index_BatchProcessingOptions = BatchProcessingOptions; type index_BatchProcessor = BatchProcessor; declare const index_BatchProcessor: typeof BatchProcessor; type index_BatchResult<T> = BatchResult<T>; type index_VideoCreator = VideoCreator; declare const index_VideoCreator: typeof VideoCreator; declare namespace index { export { index_AudioProcessor as AudioProcessor, type index_BatchProcessingOptions as BatchProcessingOptions, index_BatchProcessor as BatchProcessor, type index_BatchResult as BatchResult, index_VideoCreator as VideoCreator }; } export { AudioProcessor as A, BatchProcessor as B, VideoCreator as V, type BatchProcessingOptions as a, type BatchResult as b, index as i };