/** * FastAPI * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) * * The version of the OpenAPI document: 0.1.0 * * * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). * https://openapi-generator.tech * Do not edit the class manually. */ import localVarRequest from 'request'; import http from 'http'; /* tslint:disable:no-unused-locals */ import { AudioOutputFileURLResponse } from '../model/audioOutputFileURLResponse'; import { AudioSeparationRunInfoResponse } from '../model/audioSeparationRunInfoResponse'; import { BodyTranslateTranslatePost } from '../model/bodyTranslateTranslatePost'; import { CreateCustomVoiceOut } from '../model/createCustomVoiceOut'; import { CreateTTSRequestPayload } from '../model/createTTSRequestPayload'; import { CreateTTSStreamRequestPayload } from '../model/createTTSStreamRequestPayload'; import { CreateTextToAudioRequestPayload } from '../model/createTextToAudioRequestPayload'; import { CreateTextToVoiceRequestPayload } from '../model/createTextToVoiceRequestPayload'; import { CreateTranslatedStoryRequestPayload } from '../model/createTranslatedStoryRequestPayload'; import { CreateTranslatedTTSRequestPayload } from '../model/createTranslatedTTSRequestPayload'; import { CreateTranslationStreamRequestPayload } from '../model/createTranslationStreamRequestPayload'; import { DialogueItem } from '../model/dialogueItem'; import { Dictionary } from '../model/dictionary'; import { EndToEndDubbingRequestPayload } from '../model/endToEndDubbingRequestPayload'; import { Gender } from '../model/gender'; import { HTTPValidationError } from '../model/hTTPValidationError'; import { LanguageItem } from '../model/languageItem'; import { Languages } from '../model/languages'; import { OrchestratorPipelineResult } from '../model/orchestratorPipelineResult'; import { OutputType } from '../model/outputType'; import { RunInfoResponse } from '../model/runInfoResponse'; import { StoryRunInfoResponse } from '../model/storyRunInfoResponse'; import { TaskID } from '../model/taskID'; import { TaskStatus } from '../model/taskStatus'; import { TextToVoiceRunInfoResponse } from '../model/textToVoiceRunInfoResponse'; import { TranslationResult } from '../model/translationResult'; import { VoiceItem } from '../model/voiceItem'; import { ObjectSerializer, Authentication, VoidAuth, Interceptor } from '../model/models'; import { HttpBasicAuth, HttpBearerAuth, ApiKeyAuth, OAuth } from '../model/models'; import { HttpError, RequestFile } from './apis'; import fs from 'fs'; const POLL_INTERVAL = 5000; let defaultBasePath = 'https://client.camb.ai/apis'; // =============================================== // This file is autogenerated - Please do not edit // =============================================== export enum ApiKey { APIKeyHeader, } export class CambAI { protected _basePath = defaultBasePath; protected _defaultHeaders : any = {}; protected _useQuerystring : boolean = false; protected authentications = { 'default': new VoidAuth(), 'APIKeyHeader': new ApiKeyAuth('header', 'x-api-key'), } protected interceptors: Interceptor[] = []; constructor(basePath?: string); constructor(basePathOrUsername: string, password?: string, basePath?: string) { if (password) { if (basePath) { this.basePath = basePath; } } else { if (basePathOrUsername) { this.basePath = basePathOrUsername } } } set useQuerystring(value: boolean) { this._useQuerystring = value; } set basePath(basePath: string) { this._basePath = basePath; } set defaultHeaders(defaultHeaders: any) { this._defaultHeaders = defaultHeaders; } get defaultHeaders() { return this._defaultHeaders; } get basePath() { return this._basePath; } public setDefaultAuthentication(auth: Authentication) { this.authentications.default = auth; } public setApiKey(key: ApiKey, value: string) { (this.authentications as any)[ApiKey[key]].apiKey = value; } public addInterceptor(interceptor: Interceptor) { this.interceptors.push(interceptor); } /** * * @summary Create Audio Separation * @param audioFile Media file to processed. AAC, FLAC, MP3 and WAV formats are supported. */ public async createAudioSeparation (audioFile?: RequestFile, options: {headers: {[name: string]: string}} = {headers: {}}) : Promise<{ response: http.IncomingMessage; body: TaskID; }> { const localVarPath = this.basePath + '/audio-separation'; let localVarQueryParameters: any = {}; let localVarHeaderParams: any = (Object).assign({}, this._defaultHeaders); const produces = ['application/json']; // give precedence to 'application/json' if (produces.indexOf('application/json') >= 0) { localVarHeaderParams.Accept = 'application/json'; } else { localVarHeaderParams.Accept = produces.join(','); } let localVarFormParams: any = {}; (Object).assign(localVarHeaderParams, options.headers); let localVarUseFormData = false; if (audioFile !== undefined) { localVarFormParams['audio_file'] = audioFile; } localVarUseFormData = true; let localVarRequestOptions: localVarRequest.Options = { method: 'POST', qs: localVarQueryParameters, headers: localVarHeaderParams, uri: localVarPath, useQuerystring: this._useQuerystring, json: true, }; let authenticationPromise = Promise.resolve(); if (this.authentications.APIKeyHeader.apiKey) { authenticationPromise = authenticationPromise.then(() => this.authentications.APIKeyHeader.applyToRequest(localVarRequestOptions)); } authenticationPromise = authenticationPromise.then(() => this.authentications.default.applyToRequest(localVarRequestOptions)); let interceptorPromise = authenticationPromise; for (const interceptor of this.interceptors) { interceptorPromise = interceptorPromise.then(() => interceptor(localVarRequestOptions)); } return interceptorPromise.then(() => { if (Object.keys(localVarFormParams).length) { if (localVarUseFormData) { (localVarRequestOptions).formData = localVarFormParams; } else { localVarRequestOptions.form = localVarFormParams; } } return new Promise<{ response: http.IncomingMessage; body: TaskID; }>((resolve, reject) => { localVarRequest(localVarRequestOptions, (error, response, body) => { if (error) { reject(error); } else { if (response.statusCode && response.statusCode >= 200 && response.statusCode <= 299) { body = ObjectSerializer.deserialize(body, "TaskID"); resolve({ response: response, body: body }); } else { reject(new HttpError(response, body, response.statusCode)); } } }); }); }); } /** * * @summary Create Custom Voice * @param voiceName The name or label to be assigned to the voice. * @param gender Represents the gender of the speaker in the provided audio. Values are encoded as integers. * @param file The reference audio file that will be used to create the custom voice. The file should have clear speech to ensure optimal cloning accuracy. Supported formats include `.aac`, `.flac`, `.mp3` and `.wav`. * @param description A brief summary of the custom voice—e.g. its intended use, tone or character traits. * @param publishVoiceToMarketPlace Set this to `true` to publish this custom voice to the marketplace for others to use. By making it available in the marketplace you consent to the guidelines and terms & conditions. * @param age The estimated or actual age of the speaker in the reference audio. * @param enhanceAudio If set to `true`, the system will apply audio enhancement techniques such as noise reduction and volume normalization to improve voice clarity. * @param language The language of the reference audio file. This field is optional. */ public async createCustomVoice (voiceName: string, gender: Gender, file: RequestFile, description?: string, publishVoiceToMarketPlace?: boolean, age?: number, enhanceAudio?: boolean, language?: Languages, options: {headers: {[name: string]: string}} = {headers: {}}) : Promise<{ response: http.IncomingMessage; body: CreateCustomVoiceOut; }> { const localVarPath = this.basePath + '/create-custom-voice'; let localVarQueryParameters: any = {}; let localVarHeaderParams: any = (Object).assign({}, this._defaultHeaders); const produces = ['application/json']; // give precedence to 'application/json' if (produces.indexOf('application/json') >= 0) { localVarHeaderParams.Accept = 'application/json'; } else { localVarHeaderParams.Accept = produces.join(','); } let localVarFormParams: any = {}; // verify required parameter 'voiceName' is not null or undefined if (voiceName === null || voiceName === undefined) { throw new Error('Required parameter voiceName was null or undefined when calling createCustomVoice.'); } // verify required parameter 'gender' is not null or undefined if (gender === null || gender === undefined) { throw new Error('Required parameter gender was null or undefined when calling createCustomVoice.'); } // verify required parameter 'file' is not null or undefined if (file === null || file === undefined) { throw new Error('Required parameter file was null or undefined when calling createCustomVoice.'); } (Object).assign(localVarHeaderParams, options.headers); let localVarUseFormData = false; if (voiceName !== undefined) { localVarFormParams['voice_name'] = ObjectSerializer.serialize(voiceName, "string"); } if (gender !== undefined) { localVarFormParams['gender'] = ObjectSerializer.serialize(gender, "Gender"); } if (description !== undefined) { localVarFormParams['description'] = ObjectSerializer.serialize(description, "string"); } if (publishVoiceToMarketPlace !== undefined) { localVarFormParams['publish_voice_to_market_place'] = ObjectSerializer.serialize(publishVoiceToMarketPlace, "boolean"); } if (age !== undefined) { localVarFormParams['age'] = ObjectSerializer.serialize(age, "number"); } if (file !== undefined) { localVarFormParams['file'] = file; } localVarUseFormData = true; if (enhanceAudio !== undefined) { localVarFormParams['enhance_audio'] = ObjectSerializer.serialize(enhanceAudio, "boolean"); } if (language !== undefined) { localVarFormParams['language'] = ObjectSerializer.serialize(language, "Languages"); } let localVarRequestOptions: localVarRequest.Options = { method: 'POST', qs: localVarQueryParameters, headers: localVarHeaderParams, uri: localVarPath, useQuerystring: this._useQuerystring, json: true, }; let authenticationPromise = Promise.resolve(); if (this.authentications.APIKeyHeader.apiKey) { authenticationPromise = authenticationPromise.then(() => this.authentications.APIKeyHeader.applyToRequest(localVarRequestOptions)); } authenticationPromise = authenticationPromise.then(() => this.authentications.default.applyToRequest(localVarRequestOptions)); let interceptorPromise = authenticationPromise; for (const interceptor of this.interceptors) { interceptorPromise = interceptorPromise.then(() => interceptor(localVarRequestOptions)); } return interceptorPromise.then(() => { if (Object.keys(localVarFormParams).length) { if (localVarUseFormData) { (localVarRequestOptions).formData = localVarFormParams; } else { localVarRequestOptions.form = localVarFormParams; } } return new Promise<{ response: http.IncomingMessage; body: CreateCustomVoiceOut; }>((resolve, reject) => { localVarRequest(localVarRequestOptions, (error, response, body) => { if (error) { reject(error); } else { if (response.statusCode && response.statusCode >= 200 && response.statusCode <= 299) { body = ObjectSerializer.deserialize(body, "CreateCustomVoiceOut"); resolve({ response: response, body: body }); } else { reject(new HttpError(response, body, response.statusCode)); } } }); }); }); } /** * Initiate a full end to end dubbing task. * @summary End To End Dubbing * @param endToEndDubbingRequestPayload */ public async createEndToEndDubbing (endToEndDubbingRequestPayload: EndToEndDubbingRequestPayload, options: {headers: {[name: string]: string}} = {headers: {}}) : Promise<{ response: http.IncomingMessage; body: TaskID; }> { const localVarPath = this.basePath + '/dub'; let localVarQueryParameters: any = {}; let localVarHeaderParams: any = (Object).assign({}, this._defaultHeaders); const produces = ['application/json']; // give precedence to 'application/json' if (produces.indexOf('application/json') >= 0) { localVarHeaderParams.Accept = 'application/json'; } else { localVarHeaderParams.Accept = produces.join(','); } let localVarFormParams: any = {}; // verify required parameter 'endToEndDubbingRequestPayload' is not null or undefined if (endToEndDubbingRequestPayload === null || endToEndDubbingRequestPayload === undefined) { throw new Error('Required parameter endToEndDubbingRequestPayload was null or undefined when calling createEndToEndDubbing.'); } (Object).assign(localVarHeaderParams, options.headers); let localVarUseFormData = false; let localVarRequestOptions: localVarRequest.Options = { method: 'POST', qs: localVarQueryParameters, headers: localVarHeaderParams, uri: localVarPath, useQuerystring: this._useQuerystring, json: true, body: ObjectSerializer.serialize(endToEndDubbingRequestPayload, "EndToEndDubbingRequestPayload") }; let authenticationPromise = Promise.resolve(); if (this.authentications.APIKeyHeader.apiKey) { authenticationPromise = authenticationPromise.then(() => this.authentications.APIKeyHeader.applyToRequest(localVarRequestOptions)); } authenticationPromise = authenticationPromise.then(() => this.authentications.default.applyToRequest(localVarRequestOptions)); let interceptorPromise = authenticationPromise; for (const interceptor of this.interceptors) { interceptorPromise = interceptorPromise.then(() => interceptor(localVarRequestOptions)); } return interceptorPromise.then(() => { if (Object.keys(localVarFormParams).length) { if (localVarUseFormData) { (localVarRequestOptions).formData = localVarFormParams; } else { localVarRequestOptions.form = localVarFormParams; } } return new Promise<{ response: http.IncomingMessage; body: TaskID; }>((resolve, reject) => { localVarRequest(localVarRequestOptions, (error, response, body) => { if (error) { reject(error); } else { if (response.statusCode && response.statusCode >= 200 && response.statusCode <= 299) { body = ObjectSerializer.deserialize(body, "TaskID"); resolve({ response: response, body: body }); } else { reject(new HttpError(response, body, response.statusCode)); } } }); }); }); } /** * * @summary Create Story * @param file The text file (`.txt`) or Word document (`.docx`) that its contents will be used for creating a story. * @param sourceLanguage The language of the contents in the input file. * @param title The title of the story. * @param description A brief description of the story. * @param narratorVoiceId Specifies the identifier of the AI voice that will narrate the story. This voice selection determines the tone, accent, and delivery style used to bring the contents of the uploaded .txt or .docx file to life. * @param chosenDictionaries An optional list of dictionary IDs selected by the user. Each entry must be an integer corresponding to a valid dictionary ID. If provided, at least one ID is required. */ public async createStory (file: RequestFile, sourceLanguage: Languages, title?: string, description?: string, narratorVoiceId?: number, chosenDictionaries?: Array, options: {headers: {[name: string]: string}} = {headers: {}}) : Promise<{ response: http.IncomingMessage; body: TaskID; }> { const localVarPath = this.basePath + '/story'; let localVarQueryParameters: any = {}; let localVarHeaderParams: any = (Object).assign({}, this._defaultHeaders); const produces = ['application/json']; // give precedence to 'application/json' if (produces.indexOf('application/json') >= 0) { localVarHeaderParams.Accept = 'application/json'; } else { localVarHeaderParams.Accept = produces.join(','); } let localVarFormParams: any = {}; // verify required parameter 'file' is not null or undefined if (file === null || file === undefined) { throw new Error('Required parameter file was null or undefined when calling createStory.'); } // verify required parameter 'sourceLanguage' is not null or undefined if (sourceLanguage === null || sourceLanguage === undefined) { throw new Error('Required parameter sourceLanguage was null or undefined when calling createStory.'); } (Object).assign(localVarHeaderParams, options.headers); let localVarUseFormData = false; if (file !== undefined) { localVarFormParams['file'] = file; } localVarUseFormData = true; if (title !== undefined) { localVarFormParams['title'] = ObjectSerializer.serialize(title, "string"); } if (description !== undefined) { localVarFormParams['description'] = ObjectSerializer.serialize(description, "string"); } if (sourceLanguage !== undefined) { localVarFormParams['source_language'] = ObjectSerializer.serialize(sourceLanguage, "Languages"); } if (narratorVoiceId !== undefined) { localVarFormParams['narrator_voice_id'] = ObjectSerializer.serialize(narratorVoiceId, "number"); } if (chosenDictionaries !== undefined) { localVarFormParams['chosen_dictionaries'] = ObjectSerializer.serialize(chosenDictionaries, "Array"); } let localVarRequestOptions: localVarRequest.Options = { method: 'POST', qs: localVarQueryParameters, headers: localVarHeaderParams, uri: localVarPath, useQuerystring: this._useQuerystring, json: true, }; let authenticationPromise = Promise.resolve(); if (this.authentications.APIKeyHeader.apiKey) { authenticationPromise = authenticationPromise.then(() => this.authentications.APIKeyHeader.applyToRequest(localVarRequestOptions)); } authenticationPromise = authenticationPromise.then(() => this.authentications.default.applyToRequest(localVarRequestOptions)); let interceptorPromise = authenticationPromise; for (const interceptor of this.interceptors) { interceptorPromise = interceptorPromise.then(() => interceptor(localVarRequestOptions)); } return interceptorPromise.then(() => { if (Object.keys(localVarFormParams).length) { if (localVarUseFormData) { (localVarRequestOptions).formData = localVarFormParams; } else { localVarRequestOptions.form = localVarFormParams; } } return new Promise<{ response: http.IncomingMessage; body: TaskID; }>((resolve, reject) => { localVarRequest(localVarRequestOptions, (error, response, body) => { if (error) { reject(error); } else { if (response.statusCode && response.statusCode >= 200 && response.statusCode <= 299) { body = ObjectSerializer.deserialize(body, "TaskID"); resolve({ response: response, body: body }); } else { reject(new HttpError(response, body, response.statusCode)); } } }); }); }); } /** * * @summary Create Text to Sound * @param createTextToAudioRequestPayload */ public async createTextToSound (createTextToAudioRequestPayload: CreateTextToAudioRequestPayload, options: {headers: {[name: string]: string}} = {headers: {}}) : Promise<{ response: http.IncomingMessage; body: TaskID; }> { const localVarPath = this.basePath + '/text-to-sound'; let localVarQueryParameters: any = {}; let localVarHeaderParams: any = (Object).assign({}, this._defaultHeaders); const produces = ['application/json']; // give precedence to 'application/json' if (produces.indexOf('application/json') >= 0) { localVarHeaderParams.Accept = 'application/json'; } else { localVarHeaderParams.Accept = produces.join(','); } let localVarFormParams: any = {}; // verify required parameter 'createTextToAudioRequestPayload' is not null or undefined if (createTextToAudioRequestPayload === null || createTextToAudioRequestPayload === undefined) { throw new Error('Required parameter createTextToAudioRequestPayload was null or undefined when calling createTextToSound.'); } (Object).assign(localVarHeaderParams, options.headers); let localVarUseFormData = false; let localVarRequestOptions: localVarRequest.Options = { method: 'POST', qs: localVarQueryParameters, headers: localVarHeaderParams, uri: localVarPath, useQuerystring: this._useQuerystring, json: true, body: ObjectSerializer.serialize(createTextToAudioRequestPayload, "CreateTextToAudioRequestPayload") }; let authenticationPromise = Promise.resolve(); if (this.authentications.APIKeyHeader.apiKey) { authenticationPromise = authenticationPromise.then(() => this.authentications.APIKeyHeader.applyToRequest(localVarRequestOptions)); } authenticationPromise = authenticationPromise.then(() => this.authentications.default.applyToRequest(localVarRequestOptions)); let interceptorPromise = authenticationPromise; for (const interceptor of this.interceptors) { interceptorPromise = interceptorPromise.then(() => interceptor(localVarRequestOptions)); } return interceptorPromise.then(() => { if (Object.keys(localVarFormParams).length) { if (localVarUseFormData) { (localVarRequestOptions).formData = localVarFormParams; } else { localVarRequestOptions.form = localVarFormParams; } } return new Promise<{ response: http.IncomingMessage; body: TaskID; }>((resolve, reject) => { localVarRequest(localVarRequestOptions, (error, response, body) => { if (error) { reject(error); } else { if (response.statusCode && response.statusCode >= 200 && response.statusCode <= 299) { body = ObjectSerializer.deserialize(body, "TaskID"); resolve({ response: response, body: body }); } else { reject(new HttpError(response, body, response.statusCode)); } } }); }); }); } /** * * @summary Create Transcription * @param language * @param file Media file for transcription */ public async createTranscription (language: Languages, file: RequestFile, options: {headers: {[name: string]: string}} = {headers: {}}) : Promise<{ response: http.IncomingMessage; body: TaskID; }> { const localVarPath = this.basePath + '/transcribe'; let localVarQueryParameters: any = {}; let localVarHeaderParams: any = (Object).assign({}, this._defaultHeaders); const produces = ['application/json']; // give precedence to 'application/json' if (produces.indexOf('application/json') >= 0) { localVarHeaderParams.Accept = 'application/json'; } else { localVarHeaderParams.Accept = produces.join(','); } let localVarFormParams: any = {}; // verify required parameter 'language' is not null or undefined if (language === null || language === undefined) { throw new Error('Required parameter language was null or undefined when calling createTranscription.'); } // verify required parameter 'file' is not null or undefined if (file === null || file === undefined) { throw new Error('Required parameter file was null or undefined when calling createTranscription.'); } (Object).assign(localVarHeaderParams, options.headers); let localVarUseFormData = false; if (language !== undefined) { localVarFormParams['language'] = ObjectSerializer.serialize(language, "Languages"); } if (file !== undefined) { localVarFormParams['file'] = file; } localVarUseFormData = true; let localVarRequestOptions: localVarRequest.Options = { method: 'POST', qs: localVarQueryParameters, headers: localVarHeaderParams, uri: localVarPath, useQuerystring: this._useQuerystring, json: true, }; let authenticationPromise = Promise.resolve(); if (this.authentications.APIKeyHeader.apiKey) { authenticationPromise = authenticationPromise.then(() => this.authentications.APIKeyHeader.applyToRequest(localVarRequestOptions)); } authenticationPromise = authenticationPromise.then(() => this.authentications.default.applyToRequest(localVarRequestOptions)); let interceptorPromise = authenticationPromise; for (const interceptor of this.interceptors) { interceptorPromise = interceptorPromise.then(() => interceptor(localVarRequestOptions)); } return interceptorPromise.then(() => { if (Object.keys(localVarFormParams).length) { if (localVarUseFormData) { (localVarRequestOptions).formData = localVarFormParams; } else { localVarRequestOptions.form = localVarFormParams; } } return new Promise<{ response: http.IncomingMessage; body: TaskID; }>((resolve, reject) => { localVarRequest(localVarRequestOptions, (error, response, body) => { if (error) { reject(error); } else { if (response.statusCode && response.statusCode >= 200 && response.statusCode <= 299) { body = ObjectSerializer.deserialize(body, "TaskID"); resolve({ response: response, body: body }); } else { reject(new HttpError(response, body, response.statusCode)); } } }); }); }); } /** * * @summary Create Translated Story * @param runId * @param createTranslatedStoryRequestPayload */ public async createTranslatedStory (runId: number, createTranslatedStoryRequestPayload: CreateTranslatedStoryRequestPayload, options: {headers: {[name: string]: string}} = {headers: {}}) : Promise<{ response: http.IncomingMessage; body: TaskID; }> { const localVarPath = this.basePath + '/translated-story/{run_id}' .replace('{' + 'run_id' + '}', encodeURIComponent(String(runId))); let localVarQueryParameters: any = {}; let localVarHeaderParams: any = (Object).assign({}, this._defaultHeaders); const produces = ['application/json']; // give precedence to 'application/json' if (produces.indexOf('application/json') >= 0) { localVarHeaderParams.Accept = 'application/json'; } else { localVarHeaderParams.Accept = produces.join(','); } let localVarFormParams: any = {}; // verify required parameter 'runId' is not null or undefined if (runId === null || runId === undefined) { throw new Error('Required parameter runId was null or undefined when calling createTranslatedStory.'); } // verify required parameter 'createTranslatedStoryRequestPayload' is not null or undefined if (createTranslatedStoryRequestPayload === null || createTranslatedStoryRequestPayload === undefined) { throw new Error('Required parameter createTranslatedStoryRequestPayload was null or undefined when calling createTranslatedStory.'); } (Object).assign(localVarHeaderParams, options.headers); let localVarUseFormData = false; let localVarRequestOptions: localVarRequest.Options = { method: 'POST', qs: localVarQueryParameters, headers: localVarHeaderParams, uri: localVarPath, useQuerystring: this._useQuerystring, json: true, body: ObjectSerializer.serialize(createTranslatedStoryRequestPayload, "CreateTranslatedStoryRequestPayload") }; let authenticationPromise = Promise.resolve(); if (this.authentications.APIKeyHeader.apiKey) { authenticationPromise = authenticationPromise.then(() => this.authentications.APIKeyHeader.applyToRequest(localVarRequestOptions)); } authenticationPromise = authenticationPromise.then(() => this.authentications.default.applyToRequest(localVarRequestOptions)); let interceptorPromise = authenticationPromise; for (const interceptor of this.interceptors) { interceptorPromise = interceptorPromise.then(() => interceptor(localVarRequestOptions)); } return interceptorPromise.then(() => { if (Object.keys(localVarFormParams).length) { if (localVarUseFormData) { (localVarRequestOptions).formData = localVarFormParams; } else { localVarRequestOptions.form = localVarFormParams; } } return new Promise<{ response: http.IncomingMessage; body: TaskID; }>((resolve, reject) => { localVarRequest(localVarRequestOptions, (error, response, body) => { if (error) { reject(error); } else { if (response.statusCode && response.statusCode >= 200 && response.statusCode <= 299) { body = ObjectSerializer.deserialize(body, "TaskID"); resolve({ response: response, body: body }); } else { reject(new HttpError(response, body, response.statusCode)); } } }); }); }); } /** * * @summary Create Translated Tts * @param createTranslatedTTSRequestPayload * @param runId */ public async createTranslatedTts (createTranslatedTTSRequestPayload: CreateTranslatedTTSRequestPayload, runId?: number, options: {headers: {[name: string]: string}} = {headers: {}}) : Promise<{ response: http.IncomingMessage; body: any; }> { const localVarPath = this.basePath + '/translated-tts'; let localVarQueryParameters: any = {}; let localVarHeaderParams: any = (Object).assign({}, this._defaultHeaders); const produces = ['application/json']; // give precedence to 'application/json' if (produces.indexOf('application/json') >= 0) { localVarHeaderParams.Accept = 'application/json'; } else { localVarHeaderParams.Accept = produces.join(','); } let localVarFormParams: any = {}; // verify required parameter 'createTranslatedTTSRequestPayload' is not null or undefined if (createTranslatedTTSRequestPayload === null || createTranslatedTTSRequestPayload === undefined) { throw new Error('Required parameter createTranslatedTTSRequestPayload was null or undefined when calling createTranslatedTts.'); } if (runId !== undefined) { localVarQueryParameters['run_id'] = ObjectSerializer.serialize(runId, "number"); } (Object).assign(localVarHeaderParams, options.headers); let localVarUseFormData = false; let localVarRequestOptions: localVarRequest.Options = { method: 'POST', qs: localVarQueryParameters, headers: localVarHeaderParams, uri: localVarPath, useQuerystring: this._useQuerystring, json: true, body: ObjectSerializer.serialize(createTranslatedTTSRequestPayload, "CreateTranslatedTTSRequestPayload") }; let authenticationPromise = Promise.resolve(); if (this.authentications.APIKeyHeader.apiKey) { authenticationPromise = authenticationPromise.then(() => this.authentications.APIKeyHeader.applyToRequest(localVarRequestOptions)); } authenticationPromise = authenticationPromise.then(() => this.authentications.default.applyToRequest(localVarRequestOptions)); let interceptorPromise = authenticationPromise; for (const interceptor of this.interceptors) { interceptorPromise = interceptorPromise.then(() => interceptor(localVarRequestOptions)); } return interceptorPromise.then(() => { if (Object.keys(localVarFormParams).length) { if (localVarUseFormData) { (localVarRequestOptions).formData = localVarFormParams; } else { localVarRequestOptions.form = localVarFormParams; } } return new Promise<{ response: http.IncomingMessage; body: any; }>((resolve, reject) => { localVarRequest(localVarRequestOptions, (error, response, body) => { if (error) { reject(error); } else { if (response.statusCode && response.statusCode >= 200 && response.statusCode <= 299) { body = ObjectSerializer.deserialize(body, "any"); resolve({ response: response, body: body }); } else { reject(new HttpError(response, body, response.statusCode)); } } }); }); }); } /** * * @summary Create Translation * @param bodyTranslateTranslatePost */ public async createTranslation (bodyTranslateTranslatePost: BodyTranslateTranslatePost, options: {headers: {[name: string]: string}} = {headers: {}}) : Promise<{ response: http.IncomingMessage; body: TaskID; }> { const localVarPath = this.basePath + '/translate'; let localVarQueryParameters: any = {}; let localVarHeaderParams: any = (Object).assign({}, this._defaultHeaders); const produces = ['application/json']; // give precedence to 'application/json' if (produces.indexOf('application/json') >= 0) { localVarHeaderParams.Accept = 'application/json'; } else { localVarHeaderParams.Accept = produces.join(','); } let localVarFormParams: any = {}; // verify required parameter 'bodyTranslateTranslatePost' is not null or undefined if (bodyTranslateTranslatePost === null || bodyTranslateTranslatePost === undefined) { throw new Error('Required parameter bodyTranslateTranslatePost was null or undefined when calling createTranslation.'); } (Object).assign(localVarHeaderParams, options.headers); let localVarUseFormData = false; let localVarRequestOptions: localVarRequest.Options = { method: 'POST', qs: localVarQueryParameters, headers: localVarHeaderParams, uri: localVarPath, useQuerystring: this._useQuerystring, json: true, body: ObjectSerializer.serialize(bodyTranslateTranslatePost, "BodyTranslateTranslatePost") }; let authenticationPromise = Promise.resolve(); if (this.authentications.APIKeyHeader.apiKey) { authenticationPromise = authenticationPromise.then(() => this.authentications.APIKeyHeader.applyToRequest(localVarRequestOptions)); } authenticationPromise = authenticationPromise.then(() => this.authentications.default.applyToRequest(localVarRequestOptions)); let interceptorPromise = authenticationPromise; for (const interceptor of this.interceptors) { interceptorPromise = interceptorPromise.then(() => interceptor(localVarRequestOptions)); } return interceptorPromise.then(() => { if (Object.keys(localVarFormParams).length) { if (localVarUseFormData) { (localVarRequestOptions).formData = localVarFormParams; } else { localVarRequestOptions.form = localVarFormParams; } } return new Promise<{ response: http.IncomingMessage; body: TaskID; }>((resolve, reject) => { localVarRequest(localVarRequestOptions, (error, response, body) => { if (error) { reject(error); } else { if (response.statusCode && response.statusCode >= 200 && response.statusCode <= 299) { body = ObjectSerializer.deserialize(body, "TaskID"); resolve({ response: response, body: body }); } else { reject(new HttpError(response, body, response.statusCode)); } } }); }); }); } /** * Stream real-time text translation between languages * @summary Create Translation Stream * @param createTranslationStreamRequestPayload */ public async createTranslationStream (createTranslationStreamRequestPayload: CreateTranslationStreamRequestPayload, options: {headers: {[name: string]: string}} = {headers: {}}) : Promise<{ response: http.IncomingMessage; body: string; }> { const localVarPath = this.basePath + '/translation/stream'; let localVarQueryParameters: any = {}; let localVarHeaderParams: any = (Object).assign({}, this._defaultHeaders); const produces = ['text/event-stream', 'application/json']; // give precedence to 'application/json' if (produces.indexOf('application/json') >= 0) { localVarHeaderParams.Accept = 'application/json'; } else { localVarHeaderParams.Accept = produces.join(','); } let localVarFormParams: any = {}; // verify required parameter 'createTranslationStreamRequestPayload' is not null or undefined if (createTranslationStreamRequestPayload === null || createTranslationStreamRequestPayload === undefined) { throw new Error('Required parameter createTranslationStreamRequestPayload was null or undefined when calling createTranslationStream.'); } (Object).assign(localVarHeaderParams, options.headers); let localVarUseFormData = false; let localVarRequestOptions: localVarRequest.Options = { method: 'POST', qs: localVarQueryParameters, headers: localVarHeaderParams, uri: localVarPath, useQuerystring: this._useQuerystring, json: true, body: ObjectSerializer.serialize(createTranslationStreamRequestPayload, "CreateTranslationStreamRequestPayload") }; let authenticationPromise = Promise.resolve(); if (this.authentications.APIKeyHeader.apiKey) { authenticationPromise = authenticationPromise.then(() => this.authentications.APIKeyHeader.applyToRequest(localVarRequestOptions)); } authenticationPromise = authenticationPromise.then(() => this.authentications.default.applyToRequest(localVarRequestOptions)); let interceptorPromise = authenticationPromise; for (const interceptor of this.interceptors) { interceptorPromise = interceptorPromise.then(() => interceptor(localVarRequestOptions)); } return interceptorPromise.then(() => { if (Object.keys(localVarFormParams).length) { if (localVarUseFormData) { (localVarRequestOptions).formData = localVarFormParams; } else { localVarRequestOptions.form = localVarFormParams; } } return new Promise<{ response: http.IncomingMessage; body: string; }>((resolve, reject) => { localVarRequest(localVarRequestOptions, (error, response, body) => { if (error) { reject(error); } else { if (response.statusCode && response.statusCode >= 200 && response.statusCode <= 299) { body = ObjectSerializer.deserialize(body, "string"); resolve({ response: response, body: body }); } else { reject(new HttpError(response, body, response.statusCode)); } } }); }); }); } /** * * @summary Create Tts * @param createTTSRequestPayload */ public async createTts (createTTSRequestPayload: CreateTTSRequestPayload, options: {headers: {[name: string]: string}} = {headers: {}}) : Promise<{ response: http.IncomingMessage; body: TaskID; }> { const localVarPath = this.basePath + '/tts'; let localVarQueryParameters: any = {}; let localVarHeaderParams: any = (Object).assign({}, this._defaultHeaders); const produces = ['application/json']; // give precedence to 'application/json' if (produces.indexOf('application/json') >= 0) { localVarHeaderParams.Accept = 'application/json'; } else { localVarHeaderParams.Accept = produces.join(','); } let localVarFormParams: any = {}; // verify required parameter 'createTTSRequestPayload' is not null or undefined if (createTTSRequestPayload === null || createTTSRequestPayload === undefined) { throw new Error('Required parameter createTTSRequestPayload was null or undefined when calling createTts.'); } (Object).assign(localVarHeaderParams, options.headers); let localVarUseFormData = false; let localVarRequestOptions: localVarRequest.Options = { method: 'POST', qs: localVarQueryParameters, headers: localVarHeaderParams, uri: localVarPath, useQuerystring: this._useQuerystring, json: true, body: ObjectSerializer.serialize(createTTSRequestPayload, "CreateTTSRequestPayload") }; let authenticationPromise = Promise.resolve(); if (this.authentications.APIKeyHeader.apiKey) { authenticationPromise = authenticationPromise.then(() => this.authentications.APIKeyHeader.applyToRequest(localVarRequestOptions)); } authenticationPromise = authenticationPromise.then(() => this.authentications.default.applyToRequest(localVarRequestOptions)); let interceptorPromise = authenticationPromise; for (const interceptor of this.interceptors) { interceptorPromise = interceptorPromise.then(() => interceptor(localVarRequestOptions)); } return interceptorPromise.then(() => { if (Object.keys(localVarFormParams).length) { if (localVarUseFormData) { (localVarRequestOptions).formData = localVarFormParams; } else { localVarRequestOptions.form = localVarFormParams; } } return new Promise<{ response: http.IncomingMessage; body: TaskID; }>((resolve, reject) => { localVarRequest(localVarRequestOptions, (error, response, body) => { if (error) { reject(error); } else { if (response.statusCode && response.statusCode >= 200 && response.statusCode <= 299) { body = ObjectSerializer.deserialize(body, "TaskID"); resolve({ response: response, body: body }); } else { reject(new HttpError(response, body, response.statusCode)); } } }); }); }); } /** * * @summary Create Voice from Description * @param createTextToVoiceRequestPayload */ public async createVoiceFromDescription (createTextToVoiceRequestPayload: CreateTextToVoiceRequestPayload, options: {headers: {[name: string]: string}} = {headers: {}}) : Promise<{ response: http.IncomingMessage; body: TaskID; }> { const localVarPath = this.basePath + '/text-to-voice'; let localVarQueryParameters: any = {}; let localVarHeaderParams: any = (Object).assign({}, this._defaultHeaders); const produces = ['application/json']; // give precedence to 'application/json' if (produces.indexOf('application/json') >= 0) { localVarHeaderParams.Accept = 'application/json'; } else { localVarHeaderParams.Accept = produces.join(','); } let localVarFormParams: any = {}; // verify required parameter 'createTextToVoiceRequestPayload' is not null or undefined if (createTextToVoiceRequestPayload === null || createTextToVoiceRequestPayload === undefined) { throw new Error('Required parameter createTextToVoiceRequestPayload was null or undefined when calling createVoiceFromDescription.'); } (Object).assign(localVarHeaderParams, options.headers); let localVarUseFormData = false; let localVarRequestOptions: localVarRequest.Options = { method: 'POST', qs: localVarQueryParameters, headers: localVarHeaderParams, uri: localVarPath, useQuerystring: this._useQuerystring, json: true, body: ObjectSerializer.serialize(createTextToVoiceRequestPayload, "CreateTextToVoiceRequestPayload") }; let authenticationPromise = Promise.resolve(); if (this.authentications.APIKeyHeader.apiKey) { authenticationPromise = authenticationPromise.then(() => this.authentications.APIKeyHeader.applyToRequest(localVarRequestOptions)); } authenticationPromise = authenticationPromise.then(() => this.authentications.default.applyToRequest(localVarRequestOptions)); let interceptorPromise = authenticationPromise; for (const interceptor of this.interceptors) { interceptorPromise = interceptorPromise.then(() => interceptor(localVarRequestOptions)); } return interceptorPromise.then(() => { if (Object.keys(localVarFormParams).length) { if (localVarUseFormData) { (localVarRequestOptions).formData = localVarFormParams; } else { localVarRequestOptions.form = localVarFormParams; } } return new Promise<{ response: http.IncomingMessage; body: TaskID; }>((resolve, reject) => { localVarRequest(localVarRequestOptions, (error, response, body) => { if (error) { reject(error); } else { if (response.statusCode && response.statusCode >= 200 && response.statusCode <= 299) { body = ObjectSerializer.deserialize(body, "TaskID"); resolve({ response: response, body: body }); } else { reject(new HttpError(response, body, response.statusCode)); } } }); }); }); } /** * Get a list of dictionaries in the workspace. * @summary Get Workspace Dictionaries */ public async dictionariesGet (options: {headers: {[name: string]: string}} = {headers: {}}) : Promise<{ response: http.IncomingMessage; body: Array; }> { const localVarPath = this.basePath + '/dictionaries'; let localVarQueryParameters: any = {}; let localVarHeaderParams: any = (Object).assign({}, this._defaultHeaders); const produces = ['application/json']; // give precedence to 'application/json' if (produces.indexOf('application/json') >= 0) { localVarHeaderParams.Accept = 'application/json'; } else { localVarHeaderParams.Accept = produces.join(','); } let localVarFormParams: any = {}; (Object).assign(localVarHeaderParams, options.headers); let localVarUseFormData = false; let localVarRequestOptions: localVarRequest.Options = { method: 'GET', qs: localVarQueryParameters, headers: localVarHeaderParams, uri: localVarPath, useQuerystring: this._useQuerystring, json: true, }; let authenticationPromise = Promise.resolve(); if (this.authentications.APIKeyHeader.apiKey) { authenticationPromise = authenticationPromise.then(() => this.authentications.APIKeyHeader.applyToRequest(localVarRequestOptions)); } authenticationPromise = authenticationPromise.then(() => this.authentications.default.applyToRequest(localVarRequestOptions)); let interceptorPromise = authenticationPromise; for (const interceptor of this.interceptors) { interceptorPromise = interceptorPromise.then(() => interceptor(localVarRequestOptions)); } return interceptorPromise.then(() => { if (Object.keys(localVarFormParams).length) { if (localVarUseFormData) { (localVarRequestOptions).formData = localVarFormParams; } else { localVarRequestOptions.form = localVarFormParams; } } return new Promise<{ response: http.IncomingMessage; body: Array; }>((resolve, reject) => { localVarRequest(localVarRequestOptions, (error, response, body) => { if (error) { reject(error); } else { if (response.statusCode && response.statusCode >= 200 && response.statusCode <= 299) { body = ObjectSerializer.deserialize(body, "Array"); resolve({ response: response, body: body }); } else { reject(new HttpError(response, body, response.statusCode)); } } }); }); }); } /** * * @summary Get Audio Separation Run Info * @param runId */ public async getAudioSeparationRunInfoById (runId: number, options: {headers: {[name: string]: string}} = {headers: {}}) : Promise<{ response: http.IncomingMessage; body: AudioSeparationRunInfoResponse; }> { const localVarPath = this.basePath + '/audio-separation-result/{run_id}' .replace('{' + 'run_id' + '}', encodeURIComponent(String(runId))); let localVarQueryParameters: any = {}; let localVarHeaderParams: any = (Object).assign({}, this._defaultHeaders); const produces = ['application/json']; // give precedence to 'application/json' if (produces.indexOf('application/json') >= 0) { localVarHeaderParams.Accept = 'application/json'; } else { localVarHeaderParams.Accept = produces.join(','); } let localVarFormParams: any = {}; // verify required parameter 'runId' is not null or undefined if (runId === null || runId === undefined) { throw new Error('Required parameter runId was null or undefined when calling getAudioSeparationRunInfoById.'); } (Object).assign(localVarHeaderParams, options.headers); let localVarUseFormData = false; let localVarRequestOptions: localVarRequest.Options = { method: 'GET', qs: localVarQueryParameters, headers: localVarHeaderParams, uri: localVarPath, useQuerystring: this._useQuerystring, json: true, }; let authenticationPromise = Promise.resolve(); if (this.authentications.APIKeyHeader.apiKey) { authenticationPromise = authenticationPromise.then(() => this.authentications.APIKeyHeader.applyToRequest(localVarRequestOptions)); } authenticationPromise = authenticationPromise.then(() => this.authentications.default.applyToRequest(localVarRequestOptions)); let interceptorPromise = authenticationPromise; for (const interceptor of this.interceptors) { interceptorPromise = interceptorPromise.then(() => interceptor(localVarRequestOptions)); } return interceptorPromise.then(() => { if (Object.keys(localVarFormParams).length) { if (localVarUseFormData) { (localVarRequestOptions).formData = localVarFormParams; } else { localVarRequestOptions.form = localVarFormParams; } } return new Promise<{ response: http.IncomingMessage; body: AudioSeparationRunInfoResponse; }>((resolve, reject) => { localVarRequest(localVarRequestOptions, (error, response, body) => { if (error) { reject(error); } else { if (response.statusCode && response.statusCode >= 200 && response.statusCode <= 299) { body = ObjectSerializer.deserialize(body, "AudioSeparationRunInfoResponse"); resolve({ response: response, body: body }); } else { reject(new HttpError(response, body, response.statusCode)); } } }); }); }); } /** * * @summary Get Audio Separation Status * @param taskId */ public async getAudioSeparationStatusById (taskId: string, options: {headers: {[name: string]: string}} = {headers: {}}) : Promise<{ response: http.IncomingMessage; body: TaskStatus; }> { const localVarPath = this.basePath + '/audio-separation/{task_id}' .replace('{' + 'task_id' + '}', encodeURIComponent(String(taskId))); let localVarQueryParameters: any = {}; let localVarHeaderParams: any = (Object).assign({}, this._defaultHeaders); const produces = ['application/json']; // give precedence to 'application/json' if (produces.indexOf('application/json') >= 0) { localVarHeaderParams.Accept = 'application/json'; } else { localVarHeaderParams.Accept = produces.join(','); } let localVarFormParams: any = {}; // verify required parameter 'taskId' is not null or undefined if (taskId === null || taskId === undefined) { throw new Error('Required parameter taskId was null or undefined when calling getAudioSeparationStatusById.'); } (Object).assign(localVarHeaderParams, options.headers); let localVarUseFormData = false; let localVarRequestOptions: localVarRequest.Options = { method: 'GET', qs: localVarQueryParameters, headers: localVarHeaderParams, uri: localVarPath, useQuerystring: this._useQuerystring, json: true, }; let authenticationPromise = Promise.resolve(); if (this.authentications.APIKeyHeader.apiKey) { authenticationPromise = authenticationPromise.then(() => this.authentications.APIKeyHeader.applyToRequest(localVarRequestOptions)); } authenticationPromise = authenticationPromise.then(() => this.authentications.default.applyToRequest(localVarRequestOptions)); let interceptorPromise = authenticationPromise; for (const interceptor of this.interceptors) { interceptorPromise = interceptorPromise.then(() => interceptor(localVarRequestOptions)); } return interceptorPromise.then(() => { if (Object.keys(localVarFormParams).length) { if (localVarUseFormData) { (localVarRequestOptions).formData = localVarFormParams; } else { localVarRequestOptions.form = localVarFormParams; } } return new Promise<{ response: http.IncomingMessage; body: TaskStatus; }>((resolve, reject) => { localVarRequest(localVarRequestOptions, (error, response, body) => { if (error) { reject(error); } else { if (response.statusCode && response.statusCode >= 200 && response.statusCode <= 299) { body = ObjectSerializer.deserialize(body, "TaskStatus"); resolve({ response: response, body: body }); } else { reject(new HttpError(response, body, response.statusCode)); } } }); }); }); } /** * * @summary Get Dubbed Run Info * @param runId The unique identifier for the run, which was generated during the end to end dub creation process and returned upon task completion. */ public async getDubbedRunInfoById (runId: number, options: {headers: {[name: string]: string}} = {headers: {}}) : Promise<{ response: http.IncomingMessage; body: RunInfoResponse; }> { const localVarPath = this.basePath + '/dub-result/{run_id}' .replace('{' + 'run_id' + '}', encodeURIComponent(String(runId))); let localVarQueryParameters: any = {}; let localVarHeaderParams: any = (Object).assign({}, this._defaultHeaders); const produces = ['application/json']; // give precedence to 'application/json' if (produces.indexOf('application/json') >= 0) { localVarHeaderParams.Accept = 'application/json'; } else { localVarHeaderParams.Accept = produces.join(','); } let localVarFormParams: any = {}; // verify required parameter 'runId' is not null or undefined if (runId === null || runId === undefined) { throw new Error('Required parameter runId was null or undefined when calling getDubbedRunInfoById.'); } (Object).assign(localVarHeaderParams, options.headers); let localVarUseFormData = false; let localVarRequestOptions: localVarRequest.Options = { method: 'GET', qs: localVarQueryParameters, headers: localVarHeaderParams, uri: localVarPath, useQuerystring: this._useQuerystring, json: true, }; let authenticationPromise = Promise.resolve(); if (this.authentications.APIKeyHeader.apiKey) { authenticationPromise = authenticationPromise.then(() => this.authentications.APIKeyHeader.applyToRequest(localVarRequestOptions)); } authenticationPromise = authenticationPromise.then(() => this.authentications.default.applyToRequest(localVarRequestOptions)); let interceptorPromise = authenticationPromise; for (const interceptor of this.interceptors) { interceptorPromise = interceptorPromise.then(() => interceptor(localVarRequestOptions)); } return interceptorPromise.then(() => { if (Object.keys(localVarFormParams).length) { if (localVarUseFormData) { (localVarRequestOptions).formData = localVarFormParams; } else { localVarRequestOptions.form = localVarFormParams; } } return new Promise<{ response: http.IncomingMessage; body: RunInfoResponse; }>((resolve, reject) => { localVarRequest(localVarRequestOptions, (error, response, body) => { if (error) { reject(error); } else { if (response.statusCode && response.statusCode >= 200 && response.statusCode <= 299) { body = ObjectSerializer.deserialize(body, "RunInfoResponse"); resolve({ response: response, body: body }); } else { reject(new HttpError(response, body, response.statusCode)); } } }); }); }); } /** * * @summary Get End To End Dubbing Status * @param taskId */ public async getEndToEndDubbingStatusById (taskId: string, options: {headers: {[name: string]: string}} = {headers: {}}) : Promise<{ response: http.IncomingMessage; body: OrchestratorPipelineResult; }> { const localVarPath = this.basePath + '/dub/{task_id}' .replace('{' + 'task_id' + '}', encodeURIComponent(String(taskId))); let localVarQueryParameters: any = {}; let localVarHeaderParams: any = (Object).assign({}, this._defaultHeaders); const produces = ['application/json']; // give precedence to 'application/json' if (produces.indexOf('application/json') >= 0) { localVarHeaderParams.Accept = 'application/json'; } else { localVarHeaderParams.Accept = produces.join(','); } let localVarFormParams: any = {}; // verify required parameter 'taskId' is not null or undefined if (taskId === null || taskId === undefined) { throw new Error('Required parameter taskId was null or undefined when calling getEndToEndDubbingStatusById.'); } (Object).assign(localVarHeaderParams, options.headers); let localVarUseFormData = false; let localVarRequestOptions: localVarRequest.Options = { method: 'GET', qs: localVarQueryParameters, headers: localVarHeaderParams, uri: localVarPath, useQuerystring: this._useQuerystring, json: true, }; let authenticationPromise = Promise.resolve(); if (this.authentications.APIKeyHeader.apiKey) { authenticationPromise = authenticationPromise.then(() => this.authentications.APIKeyHeader.applyToRequest(localVarRequestOptions)); } authenticationPromise = authenticationPromise.then(() => this.authentications.default.applyToRequest(localVarRequestOptions)); let interceptorPromise = authenticationPromise; for (const interceptor of this.interceptors) { interceptorPromise = interceptorPromise.then(() => interceptor(localVarRequestOptions)); } return interceptorPromise.then(() => { if (Object.keys(localVarFormParams).length) { if (localVarUseFormData) { (localVarRequestOptions).formData = localVarFormParams; } else { localVarRequestOptions.form = localVarFormParams; } } return new Promise<{ response: http.IncomingMessage; body: OrchestratorPipelineResult; }>((resolve, reject) => { localVarRequest(localVarRequestOptions, (error, response, body) => { if (error) { reject(error); } else { if (response.statusCode && response.statusCode >= 200 && response.statusCode <= 299) { body = ObjectSerializer.deserialize(body, "OrchestratorPipelineResult"); resolve({ response: response, body: body }); } else { reject(new HttpError(response, body, response.statusCode)); } } }); }); }); } /** * * @summary Get Source Languages */ public async getSourceLanguages (options: {headers: {[name: string]: string}} = {headers: {}}) : Promise<{ response: http.IncomingMessage; body: Array; }> { const localVarPath = this.basePath + '/source-languages'; let localVarQueryParameters: any = {}; let localVarHeaderParams: any = (Object).assign({}, this._defaultHeaders); const produces = ['application/json']; // give precedence to 'application/json' if (produces.indexOf('application/json') >= 0) { localVarHeaderParams.Accept = 'application/json'; } else { localVarHeaderParams.Accept = produces.join(','); } let localVarFormParams: any = {}; (Object).assign(localVarHeaderParams, options.headers); let localVarUseFormData = false; let localVarRequestOptions: localVarRequest.Options = { method: 'GET', qs: localVarQueryParameters, headers: localVarHeaderParams, uri: localVarPath, useQuerystring: this._useQuerystring, json: true, }; let authenticationPromise = Promise.resolve(); if (this.authentications.APIKeyHeader.apiKey) { authenticationPromise = authenticationPromise.then(() => this.authentications.APIKeyHeader.applyToRequest(localVarRequestOptions)); } authenticationPromise = authenticationPromise.then(() => this.authentications.default.applyToRequest(localVarRequestOptions)); let interceptorPromise = authenticationPromise; for (const interceptor of this.interceptors) { interceptorPromise = interceptorPromise.then(() => interceptor(localVarRequestOptions)); } return interceptorPromise.then(() => { if (Object.keys(localVarFormParams).length) { if (localVarUseFormData) { (localVarRequestOptions).formData = localVarFormParams; } else { localVarRequestOptions.form = localVarFormParams; } } return new Promise<{ response: http.IncomingMessage; body: Array; }>((resolve, reject) => { localVarRequest(localVarRequestOptions, (error, response, body) => { if (error) { reject(error); } else { if (response.statusCode && response.statusCode >= 200 && response.statusCode <= 299) { body = ObjectSerializer.deserialize(body, "Array"); resolve({ response: response, body: body }); } else { reject(new HttpError(response, body, response.statusCode)); } } }); }); }); } /** * * @summary Get Story Run Info * @param runId * @param includeTranscript */ public async getStoryRunInfoById (runId: number, includeTranscript?: boolean, options: {headers: {[name: string]: string}} = {headers: {}}) : Promise<{ response: http.IncomingMessage; body: StoryRunInfoResponse; }> { const localVarPath = this.basePath + '/story-result/{run_id}' .replace('{' + 'run_id' + '}', encodeURIComponent(String(runId))); let localVarQueryParameters: any = {}; let localVarHeaderParams: any = (Object).assign({}, this._defaultHeaders); const produces = ['application/json']; // give precedence to 'application/json' if (produces.indexOf('application/json') >= 0) { localVarHeaderParams.Accept = 'application/json'; } else { localVarHeaderParams.Accept = produces.join(','); } let localVarFormParams: any = {}; // verify required parameter 'runId' is not null or undefined if (runId === null || runId === undefined) { throw new Error('Required parameter runId was null or undefined when calling getStoryRunInfoById.'); } if (includeTranscript !== undefined) { localVarQueryParameters['include_transcript'] = ObjectSerializer.serialize(includeTranscript, "boolean"); } (Object).assign(localVarHeaderParams, options.headers); let localVarUseFormData = false; let localVarRequestOptions: localVarRequest.Options = { method: 'GET', qs: localVarQueryParameters, headers: localVarHeaderParams, uri: localVarPath, useQuerystring: this._useQuerystring, json: true, }; let authenticationPromise = Promise.resolve(); if (this.authentications.APIKeyHeader.apiKey) { authenticationPromise = authenticationPromise.then(() => this.authentications.APIKeyHeader.applyToRequest(localVarRequestOptions)); } authenticationPromise = authenticationPromise.then(() => this.authentications.default.applyToRequest(localVarRequestOptions)); let interceptorPromise = authenticationPromise; for (const interceptor of this.interceptors) { interceptorPromise = interceptorPromise.then(() => interceptor(localVarRequestOptions)); } return interceptorPromise.then(() => { if (Object.keys(localVarFormParams).length) { if (localVarUseFormData) { (localVarRequestOptions).formData = localVarFormParams; } else { localVarRequestOptions.form = localVarFormParams; } } return new Promise<{ response: http.IncomingMessage; body: StoryRunInfoResponse; }>((resolve, reject) => { localVarRequest(localVarRequestOptions, (error, response, body) => { if (error) { reject(error); } else { if (response.statusCode && response.statusCode >= 200 && response.statusCode <= 299) { body = ObjectSerializer.deserialize(body, "StoryRunInfoResponse"); resolve({ response: response, body: body }); } else { reject(new HttpError(response, body, response.statusCode)); } } }); }); }); } /** * * @summary Get Story Status * @param taskId */ public async getStoryStatusById (taskId: string, options: {headers: {[name: string]: string}} = {headers: {}}) : Promise<{ response: http.IncomingMessage; body: OrchestratorPipelineResult; }> { const localVarPath = this.basePath + '/story/{task_id}' .replace('{' + 'task_id' + '}', encodeURIComponent(String(taskId))); let localVarQueryParameters: any = {}; let localVarHeaderParams: any = (Object).assign({}, this._defaultHeaders); const produces = ['application/json']; // give precedence to 'application/json' if (produces.indexOf('application/json') >= 0) { localVarHeaderParams.Accept = 'application/json'; } else { localVarHeaderParams.Accept = produces.join(','); } let localVarFormParams: any = {}; // verify required parameter 'taskId' is not null or undefined if (taskId === null || taskId === undefined) { throw new Error('Required parameter taskId was null or undefined when calling getStoryStatusById.'); } (Object).assign(localVarHeaderParams, options.headers); let localVarUseFormData = false; let localVarRequestOptions: localVarRequest.Options = { method: 'GET', qs: localVarQueryParameters, headers: localVarHeaderParams, uri: localVarPath, useQuerystring: this._useQuerystring, json: true, }; let authenticationPromise = Promise.resolve(); if (this.authentications.APIKeyHeader.apiKey) { authenticationPromise = authenticationPromise.then(() => this.authentications.APIKeyHeader.applyToRequest(localVarRequestOptions)); } authenticationPromise = authenticationPromise.then(() => this.authentications.default.applyToRequest(localVarRequestOptions)); let interceptorPromise = authenticationPromise; for (const interceptor of this.interceptors) { interceptorPromise = interceptorPromise.then(() => interceptor(localVarRequestOptions)); } return interceptorPromise.then(() => { if (Object.keys(localVarFormParams).length) { if (localVarUseFormData) { (localVarRequestOptions).formData = localVarFormParams; } else { localVarRequestOptions.form = localVarFormParams; } } return new Promise<{ response: http.IncomingMessage; body: OrchestratorPipelineResult; }>((resolve, reject) => { localVarRequest(localVarRequestOptions, (error, response, body) => { if (error) { reject(error); } else { if (response.statusCode && response.statusCode >= 200 && response.statusCode <= 299) { body = ObjectSerializer.deserialize(body, "OrchestratorPipelineResult"); resolve({ response: response, body: body }); } else { reject(new HttpError(response, body, response.statusCode)); } } }); }); }); } /** * * @summary Get Target Languages */ public async getTargetLanguages (options: {headers: {[name: string]: string}} = {headers: {}}) : Promise<{ response: http.IncomingMessage; body: Array; }> { const localVarPath = this.basePath + '/target-languages'; let localVarQueryParameters: any = {}; let localVarHeaderParams: any = (Object).assign({}, this._defaultHeaders); const produces = ['application/json']; // give precedence to 'application/json' if (produces.indexOf('application/json') >= 0) { localVarHeaderParams.Accept = 'application/json'; } else { localVarHeaderParams.Accept = produces.join(','); } let localVarFormParams: any = {}; (Object).assign(localVarHeaderParams, options.headers); let localVarUseFormData = false; let localVarRequestOptions: localVarRequest.Options = { method: 'GET', qs: localVarQueryParameters, headers: localVarHeaderParams, uri: localVarPath, useQuerystring: this._useQuerystring, json: true, }; let authenticationPromise = Promise.resolve(); if (this.authentications.APIKeyHeader.apiKey) { authenticationPromise = authenticationPromise.then(() => this.authentications.APIKeyHeader.applyToRequest(localVarRequestOptions)); } authenticationPromise = authenticationPromise.then(() => this.authentications.default.applyToRequest(localVarRequestOptions)); let interceptorPromise = authenticationPromise; for (const interceptor of this.interceptors) { interceptorPromise = interceptorPromise.then(() => interceptor(localVarRequestOptions)); } return interceptorPromise.then(() => { if (Object.keys(localVarFormParams).length) { if (localVarUseFormData) { (localVarRequestOptions).formData = localVarFormParams; } else { localVarRequestOptions.form = localVarFormParams; } } return new Promise<{ response: http.IncomingMessage; body: Array; }>((resolve, reject) => { localVarRequest(localVarRequestOptions, (error, response, body) => { if (error) { reject(error); } else { if (response.statusCode && response.statusCode >= 200 && response.statusCode <= 299) { body = ObjectSerializer.deserialize(body, "Array"); resolve({ response: response, body: body }); } else { reject(new HttpError(response, body, response.statusCode)); } } }); }); }); } /** * * @summary Get Text To Audio Status * @param taskId */ public async getTextToAudioStatusById (taskId: string, options: {headers: {[name: string]: string}} = {headers: {}}) : Promise<{ response: http.IncomingMessage; body: OrchestratorPipelineResult; }> { const localVarPath = this.basePath + '/text-to-sound/{task_id}' .replace('{' + 'task_id' + '}', encodeURIComponent(String(taskId))); let localVarQueryParameters: any = {}; let localVarHeaderParams: any = (Object).assign({}, this._defaultHeaders); const produces = ['application/json']; // give precedence to 'application/json' if (produces.indexOf('application/json') >= 0) { localVarHeaderParams.Accept = 'application/json'; } else { localVarHeaderParams.Accept = produces.join(','); } let localVarFormParams: any = {}; // verify required parameter 'taskId' is not null or undefined if (taskId === null || taskId === undefined) { throw new Error('Required parameter taskId was null or undefined when calling getTextToAudioStatusById.'); } (Object).assign(localVarHeaderParams, options.headers); let localVarUseFormData = false; let localVarRequestOptions: localVarRequest.Options = { method: 'GET', qs: localVarQueryParameters, headers: localVarHeaderParams, uri: localVarPath, useQuerystring: this._useQuerystring, json: true, }; let authenticationPromise = Promise.resolve(); if (this.authentications.APIKeyHeader.apiKey) { authenticationPromise = authenticationPromise.then(() => this.authentications.APIKeyHeader.applyToRequest(localVarRequestOptions)); } authenticationPromise = authenticationPromise.then(() => this.authentications.default.applyToRequest(localVarRequestOptions)); let interceptorPromise = authenticationPromise; for (const interceptor of this.interceptors) { interceptorPromise = interceptorPromise.then(() => interceptor(localVarRequestOptions)); } return interceptorPromise.then(() => { if (Object.keys(localVarFormParams).length) { if (localVarUseFormData) { (localVarRequestOptions).formData = localVarFormParams; } else { localVarRequestOptions.form = localVarFormParams; } } return new Promise<{ response: http.IncomingMessage; body: OrchestratorPipelineResult; }>((resolve, reject) => { localVarRequest(localVarRequestOptions, (error, response, body) => { if (error) { reject(error); } else { if (response.statusCode && response.statusCode >= 200 && response.statusCode <= 299) { body = ObjectSerializer.deserialize(body, "OrchestratorPipelineResult"); resolve({ response: response, body: body }); } else { reject(new HttpError(response, body, response.statusCode)); } } }); }); }); } /** * * @summary Get Text to Sound Run Result * @param runId The unique identifier for the run, which was generated during the text to an audio effect creation process and returned upon task completion. */ public async getTextToSoundRunResultById (runId: number, options: {headers: {[name: string]: string}} = {headers: {}}) : Promise<{ response: http.IncomingMessage; body: Buffer; }> { const localVarPath = this.basePath + '/text-to-sound-result/{run_id}' .replace('{' + 'run_id' + '}', encodeURIComponent(String(runId))); let localVarQueryParameters: any = {}; let localVarHeaderParams: any = (Object).assign({}, this._defaultHeaders); // give precedence to 'audio/wav' for binary data localVarHeaderParams.Accept = 'audio/wav, audio/mp3, audio/flac, audio/aac'; let localVarFormParams: any = {}; // verify required parameter 'runId' is not null or undefined if (runId === null || runId === undefined) { throw new Error('Required parameter runId was null or undefined when calling getTextToSoundRunResultById.'); } (Object).assign(localVarHeaderParams, options.headers); let localVarUseFormData = false; let localVarRequestOptions: localVarRequest.Options = { method: 'GET', qs: localVarQueryParameters, headers: localVarHeaderParams, uri: localVarPath, useQuerystring: this._useQuerystring, encoding: null, }; let authenticationPromise = Promise.resolve(); if (this.authentications.APIKeyHeader.apiKey) { authenticationPromise = authenticationPromise.then(() => this.authentications.APIKeyHeader.applyToRequest(localVarRequestOptions)); } authenticationPromise = authenticationPromise.then(() => this.authentications.default.applyToRequest(localVarRequestOptions)); let interceptorPromise = authenticationPromise; for (const interceptor of this.interceptors) { interceptorPromise = interceptorPromise.then(() => interceptor(localVarRequestOptions)); } return interceptorPromise.then(() => { if (Object.keys(localVarFormParams).length) { if (localVarUseFormData) { (localVarRequestOptions).formData = localVarFormParams; } else { localVarRequestOptions.form = localVarFormParams; } } return new Promise<{ response: http.IncomingMessage; body: Buffer; }>((resolve, reject) => { localVarRequest(localVarRequestOptions, (error, response, body) => { if (error) { reject(error); } else { if (response.statusCode && response.statusCode >= 200 && response.statusCode <= 299) { // body is already a Buffer due to encoding: null, no need to deserialize resolve({ response: response, body: body }); } else { reject(new HttpError(response, body, response.statusCode)); } } }); }); }); } /** * * @summary Get Text-to-Voice Run Result * @param runId The unique identifier for the run, which was generated during the text to voice creation process and returned upon task completion. */ public async getTextToVoiceRunResultById (runId: number, options: {headers: {[name: string]: string}} = {headers: {}}) : Promise<{ response: http.IncomingMessage; body: TextToVoiceRunInfoResponse; }> { const localVarPath = this.basePath + '/text-to-voice-result/{run_id}' .replace('{' + 'run_id' + '}', encodeURIComponent(String(runId))); let localVarQueryParameters: any = {}; let localVarHeaderParams: any = (Object).assign({}, this._defaultHeaders); const produces = ['application/json']; // give precedence to 'application/json' if (produces.indexOf('application/json') >= 0) { localVarHeaderParams.Accept = 'application/json'; } else { localVarHeaderParams.Accept = produces.join(','); } let localVarFormParams: any = {}; // verify required parameter 'runId' is not null or undefined if (runId === null || runId === undefined) { throw new Error('Required parameter runId was null or undefined when calling getTextToVoiceRunResultById.'); } (Object).assign(localVarHeaderParams, options.headers); let localVarUseFormData = false; let localVarRequestOptions: localVarRequest.Options = { method: 'GET', qs: localVarQueryParameters, headers: localVarHeaderParams, uri: localVarPath, useQuerystring: this._useQuerystring, json: true, }; let authenticationPromise = Promise.resolve(); if (this.authentications.APIKeyHeader.apiKey) { authenticationPromise = authenticationPromise.then(() => this.authentications.APIKeyHeader.applyToRequest(localVarRequestOptions)); } authenticationPromise = authenticationPromise.then(() => this.authentications.default.applyToRequest(localVarRequestOptions)); let interceptorPromise = authenticationPromise; for (const interceptor of this.interceptors) { interceptorPromise = interceptorPromise.then(() => interceptor(localVarRequestOptions)); } return interceptorPromise.then(() => { if (Object.keys(localVarFormParams).length) { if (localVarUseFormData) { (localVarRequestOptions).formData = localVarFormParams; } else { localVarRequestOptions.form = localVarFormParams; } } return new Promise<{ response: http.IncomingMessage; body: TextToVoiceRunInfoResponse; }>((resolve, reject) => { localVarRequest(localVarRequestOptions, (error, response, body) => { if (error) { reject(error); } else { if (response.statusCode && response.statusCode >= 200 && response.statusCode <= 299) { body = ObjectSerializer.deserialize(body, "TextToVoiceRunInfoResponse"); resolve({ response: response, body: body }); } else { reject(new HttpError(response, body, response.statusCode)); } } }); }); }); } /** * Get the result for your transcription only project by using the run_id * @summary Get Transcription Result * @param runId The unique identifier for the run, which was generated during the transcription creation process and returned upon task completion. * @param wordLevelTimestamps */ public async getTranscriptionResultById (runId: number, wordLevelTimestamps?: boolean, options: {headers: {[name: string]: string}} = {headers: {}}) : Promise<{ response: http.IncomingMessage; body: Array; }> { const localVarPath = this.basePath + '/transcription-result/{run_id}' .replace('{' + 'run_id' + '}', encodeURIComponent(String(runId))); let localVarQueryParameters: any = {}; let localVarHeaderParams: any = (Object).assign({}, this._defaultHeaders); const produces = ['application/json']; // give precedence to 'application/json' if (produces.indexOf('application/json') >= 0) { localVarHeaderParams.Accept = 'application/json'; } else { localVarHeaderParams.Accept = produces.join(','); } let localVarFormParams: any = {}; // verify required parameter 'runId' is not null or undefined if (runId === null || runId === undefined) { throw new Error('Required parameter runId was null or undefined when calling getTranscriptionResultById.'); } if (wordLevelTimestamps !== undefined) { localVarQueryParameters['word_level_timestamps'] = ObjectSerializer.serialize(wordLevelTimestamps, "boolean"); } (Object).assign(localVarHeaderParams, options.headers); let localVarUseFormData = false; let localVarRequestOptions: localVarRequest.Options = { method: 'GET', qs: localVarQueryParameters, headers: localVarHeaderParams, uri: localVarPath, useQuerystring: this._useQuerystring, json: true, }; let authenticationPromise = Promise.resolve(); if (this.authentications.APIKeyHeader.apiKey) { authenticationPromise = authenticationPromise.then(() => this.authentications.APIKeyHeader.applyToRequest(localVarRequestOptions)); } authenticationPromise = authenticationPromise.then(() => this.authentications.default.applyToRequest(localVarRequestOptions)); let interceptorPromise = authenticationPromise; for (const interceptor of this.interceptors) { interceptorPromise = interceptorPromise.then(() => interceptor(localVarRequestOptions)); } return interceptorPromise.then(() => { if (Object.keys(localVarFormParams).length) { if (localVarUseFormData) { (localVarRequestOptions).formData = localVarFormParams; } else { localVarRequestOptions.form = localVarFormParams; } } return new Promise<{ response: http.IncomingMessage; body: Array; }>((resolve, reject) => { localVarRequest(localVarRequestOptions, (error, response, body) => { if (error) { reject(error); } else { if (response.statusCode && response.statusCode >= 200 && response.statusCode <= 299) { body = ObjectSerializer.deserialize(body, "Array"); resolve({ response: response, body: body }); } else { reject(new HttpError(response, body, response.statusCode)); } } }); }); }); } /** * * @summary Create Transcription Task Status * @param taskId */ public async getTranscriptionTaskStatusById (taskId: string, options: {headers: {[name: string]: string}} = {headers: {}}) : Promise<{ response: http.IncomingMessage; body: OrchestratorPipelineResult; }> { const localVarPath = this.basePath + '/transcribe/{task_id}' .replace('{' + 'task_id' + '}', encodeURIComponent(String(taskId))); let localVarQueryParameters: any = {}; let localVarHeaderParams: any = (Object).assign({}, this._defaultHeaders); const produces = ['application/json']; // give precedence to 'application/json' if (produces.indexOf('application/json') >= 0) { localVarHeaderParams.Accept = 'application/json'; } else { localVarHeaderParams.Accept = produces.join(','); } let localVarFormParams: any = {}; // verify required parameter 'taskId' is not null or undefined if (taskId === null || taskId === undefined) { throw new Error('Required parameter taskId was null or undefined when calling getTranscriptionTaskStatusById.'); } (Object).assign(localVarHeaderParams, options.headers); let localVarUseFormData = false; let localVarRequestOptions: localVarRequest.Options = { method: 'GET', qs: localVarQueryParameters, headers: localVarHeaderParams, uri: localVarPath, useQuerystring: this._useQuerystring, json: true, }; let authenticationPromise = Promise.resolve(); if (this.authentications.APIKeyHeader.apiKey) { authenticationPromise = authenticationPromise.then(() => this.authentications.APIKeyHeader.applyToRequest(localVarRequestOptions)); } authenticationPromise = authenticationPromise.then(() => this.authentications.default.applyToRequest(localVarRequestOptions)); let interceptorPromise = authenticationPromise; for (const interceptor of this.interceptors) { interceptorPromise = interceptorPromise.then(() => interceptor(localVarRequestOptions)); } return interceptorPromise.then(() => { if (Object.keys(localVarFormParams).length) { if (localVarUseFormData) { (localVarRequestOptions).formData = localVarFormParams; } else { localVarRequestOptions.form = localVarFormParams; } } return new Promise<{ response: http.IncomingMessage; body: OrchestratorPipelineResult; }>((resolve, reject) => { localVarRequest(localVarRequestOptions, (error, response, body) => { if (error) { reject(error); } else { if (response.statusCode && response.statusCode >= 200 && response.statusCode <= 299) { body = ObjectSerializer.deserialize(body, "OrchestratorPipelineResult"); resolve({ response: response, body: body }); } else { reject(new HttpError(response, body, response.statusCode)); } } }); }); }); } /** * * @summary Get Translated Story Run Info * @param runId * @param targetLanguage * @param includeTranscript */ public async getTranslatedStoryRunInfo (runId: number, targetLanguage: Languages, includeTranscript?: boolean, options: {headers: {[name: string]: string}} = {headers: {}}) : Promise<{ response: http.IncomingMessage; body: StoryRunInfoResponse; }> { const localVarPath = this.basePath + '/translated-story-result/{run_id}/{target_language}' .replace('{' + 'run_id' + '}', encodeURIComponent(String(runId))) .replace('{' + 'target_language' + '}', encodeURIComponent(String(targetLanguage))); let localVarQueryParameters: any = {}; let localVarHeaderParams: any = (Object).assign({}, this._defaultHeaders); const produces = ['application/json']; // give precedence to 'application/json' if (produces.indexOf('application/json') >= 0) { localVarHeaderParams.Accept = 'application/json'; } else { localVarHeaderParams.Accept = produces.join(','); } let localVarFormParams: any = {}; // verify required parameter 'runId' is not null or undefined if (runId === null || runId === undefined) { throw new Error('Required parameter runId was null or undefined when calling getTranslatedStoryRunInfo.'); } // verify required parameter 'targetLanguage' is not null or undefined if (targetLanguage === null || targetLanguage === undefined) { throw new Error('Required parameter targetLanguage was null or undefined when calling getTranslatedStoryRunInfo.'); } if (includeTranscript !== undefined) { localVarQueryParameters['include_transcript'] = ObjectSerializer.serialize(includeTranscript, "boolean"); } (Object).assign(localVarHeaderParams, options.headers); let localVarUseFormData = false; let localVarRequestOptions: localVarRequest.Options = { method: 'GET', qs: localVarQueryParameters, headers: localVarHeaderParams, uri: localVarPath, useQuerystring: this._useQuerystring, json: true, }; let authenticationPromise = Promise.resolve(); if (this.authentications.APIKeyHeader.apiKey) { authenticationPromise = authenticationPromise.then(() => this.authentications.APIKeyHeader.applyToRequest(localVarRequestOptions)); } authenticationPromise = authenticationPromise.then(() => this.authentications.default.applyToRequest(localVarRequestOptions)); let interceptorPromise = authenticationPromise; for (const interceptor of this.interceptors) { interceptorPromise = interceptorPromise.then(() => interceptor(localVarRequestOptions)); } return interceptorPromise.then(() => { if (Object.keys(localVarFormParams).length) { if (localVarUseFormData) { (localVarRequestOptions).formData = localVarFormParams; } else { localVarRequestOptions.form = localVarFormParams; } } return new Promise<{ response: http.IncomingMessage; body: StoryRunInfoResponse; }>((resolve, reject) => { localVarRequest(localVarRequestOptions, (error, response, body) => { if (error) { reject(error); } else { if (response.statusCode && response.statusCode >= 200 && response.statusCode <= 299) { body = ObjectSerializer.deserialize(body, "StoryRunInfoResponse"); resolve({ response: response, body: body }); } else { reject(new HttpError(response, body, response.statusCode)); } } }); }); }); } /** * * @summary Get Translated Story Status * @param taskId */ public async getTranslatedStoryStatusById (taskId: string, options: {headers: {[name: string]: string}} = {headers: {}}) : Promise<{ response: http.IncomingMessage; body: OrchestratorPipelineResult; }> { const localVarPath = this.basePath + '/translated-story/{task_id}' .replace('{' + 'task_id' + '}', encodeURIComponent(String(taskId))); let localVarQueryParameters: any = {}; let localVarHeaderParams: any = (Object).assign({}, this._defaultHeaders); const produces = ['application/json']; // give precedence to 'application/json' if (produces.indexOf('application/json') >= 0) { localVarHeaderParams.Accept = 'application/json'; } else { localVarHeaderParams.Accept = produces.join(','); } let localVarFormParams: any = {}; // verify required parameter 'taskId' is not null or undefined if (taskId === null || taskId === undefined) { throw new Error('Required parameter taskId was null or undefined when calling getTranslatedStoryStatusById.'); } (Object).assign(localVarHeaderParams, options.headers); let localVarUseFormData = false; let localVarRequestOptions: localVarRequest.Options = { method: 'GET', qs: localVarQueryParameters, headers: localVarHeaderParams, uri: localVarPath, useQuerystring: this._useQuerystring, json: true, }; let authenticationPromise = Promise.resolve(); if (this.authentications.APIKeyHeader.apiKey) { authenticationPromise = authenticationPromise.then(() => this.authentications.APIKeyHeader.applyToRequest(localVarRequestOptions)); } authenticationPromise = authenticationPromise.then(() => this.authentications.default.applyToRequest(localVarRequestOptions)); let interceptorPromise = authenticationPromise; for (const interceptor of this.interceptors) { interceptorPromise = interceptorPromise.then(() => interceptor(localVarRequestOptions)); } return interceptorPromise.then(() => { if (Object.keys(localVarFormParams).length) { if (localVarUseFormData) { (localVarRequestOptions).formData = localVarFormParams; } else { localVarRequestOptions.form = localVarFormParams; } } return new Promise<{ response: http.IncomingMessage; body: OrchestratorPipelineResult; }>((resolve, reject) => { localVarRequest(localVarRequestOptions, (error, response, body) => { if (error) { reject(error); } else { if (response.statusCode && response.statusCode >= 200 && response.statusCode <= 299) { body = ObjectSerializer.deserialize(body, "OrchestratorPipelineResult"); resolve({ response: response, body: body }); } else { reject(new HttpError(response, body, response.statusCode)); } } }); }); }); } /** * * @summary Create Translated Tts Task Status * @param taskId */ public async getTranslatedTtsTaskStatusById (taskId: string, options: {headers: {[name: string]: string}} = {headers: {}}) : Promise<{ response: http.IncomingMessage; body: OrchestratorPipelineResult; }> { const localVarPath = this.basePath + '/translated-tts/{task_id}' .replace('{' + 'task_id' + '}', encodeURIComponent(String(taskId))); let localVarQueryParameters: any = {}; let localVarHeaderParams: any = (Object).assign({}, this._defaultHeaders); const produces = ['application/json']; // give precedence to 'application/json' if (produces.indexOf('application/json') >= 0) { localVarHeaderParams.Accept = 'application/json'; } else { localVarHeaderParams.Accept = produces.join(','); } let localVarFormParams: any = {}; // verify required parameter 'taskId' is not null or undefined if (taskId === null || taskId === undefined) { throw new Error('Required parameter taskId was null or undefined when calling getTranslatedTtsTaskStatusById.'); } (Object).assign(localVarHeaderParams, options.headers); let localVarUseFormData = false; let localVarRequestOptions: localVarRequest.Options = { method: 'GET', qs: localVarQueryParameters, headers: localVarHeaderParams, uri: localVarPath, useQuerystring: this._useQuerystring, json: true, }; let authenticationPromise = Promise.resolve(); if (this.authentications.APIKeyHeader.apiKey) { authenticationPromise = authenticationPromise.then(() => this.authentications.APIKeyHeader.applyToRequest(localVarRequestOptions)); } authenticationPromise = authenticationPromise.then(() => this.authentications.default.applyToRequest(localVarRequestOptions)); let interceptorPromise = authenticationPromise; for (const interceptor of this.interceptors) { interceptorPromise = interceptorPromise.then(() => interceptor(localVarRequestOptions)); } return interceptorPromise.then(() => { if (Object.keys(localVarFormParams).length) { if (localVarUseFormData) { (localVarRequestOptions).formData = localVarFormParams; } else { localVarRequestOptions.form = localVarFormParams; } } return new Promise<{ response: http.IncomingMessage; body: OrchestratorPipelineResult; }>((resolve, reject) => { localVarRequest(localVarRequestOptions, (error, response, body) => { if (error) { reject(error); } else { if (response.statusCode && response.statusCode >= 200 && response.statusCode <= 299) { body = ObjectSerializer.deserialize(body, "OrchestratorPipelineResult"); resolve({ response: response, body: body }); } else { reject(new HttpError(response, body, response.statusCode)); } } }); }); }); } /** * Get the result for your translation only project by using the run_id * @summary Get Translation Result * @param runId The unique identifier for the run, which was generated during the translation creation process and returned upon task completion. */ public async getTranslationResultById (runId: number, options: {headers: {[name: string]: string}} = {headers: {}}) : Promise<{ response: http.IncomingMessage; body: TranslationResult; }> { const localVarPath = this.basePath + '/translation-result/{run_id}' .replace('{' + 'run_id' + '}', encodeURIComponent(String(runId))); let localVarQueryParameters: any = {}; let localVarHeaderParams: any = (Object).assign({}, this._defaultHeaders); const produces = ['application/json']; // give precedence to 'application/json' if (produces.indexOf('application/json') >= 0) { localVarHeaderParams.Accept = 'application/json'; } else { localVarHeaderParams.Accept = produces.join(','); } let localVarFormParams: any = {}; // verify required parameter 'runId' is not null or undefined if (runId === null || runId === undefined) { throw new Error('Required parameter runId was null or undefined when calling getTranslationResultById.'); } (Object).assign(localVarHeaderParams, options.headers); let localVarUseFormData = false; let localVarRequestOptions: localVarRequest.Options = { method: 'GET', qs: localVarQueryParameters, headers: localVarHeaderParams, uri: localVarPath, useQuerystring: this._useQuerystring, json: true, }; let authenticationPromise = Promise.resolve(); if (this.authentications.APIKeyHeader.apiKey) { authenticationPromise = authenticationPromise.then(() => this.authentications.APIKeyHeader.applyToRequest(localVarRequestOptions)); } authenticationPromise = authenticationPromise.then(() => this.authentications.default.applyToRequest(localVarRequestOptions)); let interceptorPromise = authenticationPromise; for (const interceptor of this.interceptors) { interceptorPromise = interceptorPromise.then(() => interceptor(localVarRequestOptions)); } return interceptorPromise.then(() => { if (Object.keys(localVarFormParams).length) { if (localVarUseFormData) { (localVarRequestOptions).formData = localVarFormParams; } else { localVarRequestOptions.form = localVarFormParams; } } return new Promise<{ response: http.IncomingMessage; body: TranslationResult; }>((resolve, reject) => { localVarRequest(localVarRequestOptions, (error, response, body) => { if (error) { reject(error); } else { if (response.statusCode && response.statusCode >= 200 && response.statusCode <= 299) { body = ObjectSerializer.deserialize(body, "TranslationResult"); resolve({ response: response, body: body }); } else { reject(new HttpError(response, body, response.statusCode)); } } }); }); }); } /** * * @summary Create translation Task Status * @param taskId */ public async getTranslationTaskStatusById (taskId: string, options: {headers: {[name: string]: string}} = {headers: {}}) : Promise<{ response: http.IncomingMessage; body: OrchestratorPipelineResult; }> { const localVarPath = this.basePath + '/translate/{task_id}' .replace('{' + 'task_id' + '}', encodeURIComponent(String(taskId))); let localVarQueryParameters: any = {}; let localVarHeaderParams: any = (Object).assign({}, this._defaultHeaders); const produces = ['application/json']; // give precedence to 'application/json' if (produces.indexOf('application/json') >= 0) { localVarHeaderParams.Accept = 'application/json'; } else { localVarHeaderParams.Accept = produces.join(','); } let localVarFormParams: any = {}; // verify required parameter 'taskId' is not null or undefined if (taskId === null || taskId === undefined) { throw new Error('Required parameter taskId was null or undefined when calling getTranslationTaskStatusById.'); } (Object).assign(localVarHeaderParams, options.headers); let localVarUseFormData = false; let localVarRequestOptions: localVarRequest.Options = { method: 'GET', qs: localVarQueryParameters, headers: localVarHeaderParams, uri: localVarPath, useQuerystring: this._useQuerystring, json: true, }; let authenticationPromise = Promise.resolve(); if (this.authentications.APIKeyHeader.apiKey) { authenticationPromise = authenticationPromise.then(() => this.authentications.APIKeyHeader.applyToRequest(localVarRequestOptions)); } authenticationPromise = authenticationPromise.then(() => this.authentications.default.applyToRequest(localVarRequestOptions)); let interceptorPromise = authenticationPromise; for (const interceptor of this.interceptors) { interceptorPromise = interceptorPromise.then(() => interceptor(localVarRequestOptions)); } return interceptorPromise.then(() => { if (Object.keys(localVarFormParams).length) { if (localVarUseFormData) { (localVarRequestOptions).formData = localVarFormParams; } else { localVarRequestOptions.form = localVarFormParams; } } return new Promise<{ response: http.IncomingMessage; body: OrchestratorPipelineResult; }>((resolve, reject) => { localVarRequest(localVarRequestOptions, (error, response, body) => { if (error) { reject(error); } else { if (response.statusCode && response.statusCode >= 200 && response.statusCode <= 299) { body = ObjectSerializer.deserialize(body, "OrchestratorPipelineResult"); resolve({ response: response, body: body }); } else { reject(new HttpError(response, body, response.statusCode)); } } }); }); }); } /** * * @summary Get Tts Result * @param id */ public async getTtsResultById (id: string, options: {headers: {[name: string]: string}} = {headers: {}}) : Promise<{ response: http.IncomingMessage; body: OrchestratorPipelineResult; }> { const localVarPath = this.basePath + '/tts/{id}' .replace('{' + 'id' + '}', encodeURIComponent(String(id))); let localVarQueryParameters: any = {}; let localVarHeaderParams: any = (Object).assign({}, this._defaultHeaders); const produces = ['application/json']; // give precedence to 'application/json' if (produces.indexOf('application/json') >= 0) { localVarHeaderParams.Accept = 'application/json'; } else { localVarHeaderParams.Accept = produces.join(','); } let localVarFormParams: any = {}; // verify required parameter 'id' is not null or undefined if (id === null || id === undefined) { throw new Error('Required parameter id was null or undefined when calling getTtsResultById.'); } (Object).assign(localVarHeaderParams, options.headers); let localVarUseFormData = false; let localVarRequestOptions: localVarRequest.Options = { method: 'GET', qs: localVarQueryParameters, headers: localVarHeaderParams, uri: localVarPath, useQuerystring: this._useQuerystring, json: true, }; let authenticationPromise = Promise.resolve(); if (this.authentications.APIKeyHeader.apiKey) { authenticationPromise = authenticationPromise.then(() => this.authentications.APIKeyHeader.applyToRequest(localVarRequestOptions)); } authenticationPromise = authenticationPromise.then(() => this.authentications.default.applyToRequest(localVarRequestOptions)); let interceptorPromise = authenticationPromise; for (const interceptor of this.interceptors) { interceptorPromise = interceptorPromise.then(() => interceptor(localVarRequestOptions)); } return interceptorPromise.then(() => { if (Object.keys(localVarFormParams).length) { if (localVarUseFormData) { (localVarRequestOptions).formData = localVarFormParams; } else { localVarRequestOptions.form = localVarFormParams; } } return new Promise<{ response: http.IncomingMessage; body: OrchestratorPipelineResult; }>((resolve, reject) => { localVarRequest(localVarRequestOptions, (error, response, body) => { if (error) { reject(error); } else { if (response.statusCode && response.statusCode >= 200 && response.statusCode <= 299) { body = ObjectSerializer.deserialize(body, "OrchestratorPipelineResult"); resolve({ response: response, body: body }); } else { reject(new HttpError(response, body, response.statusCode)); } } }); }); }); } /** * * @summary Get Tts Run Info * @param runId * @param outputType The type of the Text-to-Speech output to return. Either streamable audio bytes or a URL to the generated file. */ public async getTtsRunInfoById (runId: number, outputType?: OutputType, options: {headers: {[name: string]: string}} = {headers: {}}) : Promise<{ response: http.IncomingMessage; body: string; }> { const localVarPath = this.basePath + '/tts-result/{run_id}' .replace('{' + 'run_id' + '}', encodeURIComponent(String(runId))); let localVarQueryParameters: any = {}; let localVarHeaderParams: any = (Object).assign({}, this._defaultHeaders); const produces = ['audio/flac', 'application/json']; // give precedence to 'application/json' if (produces.indexOf('application/json') >= 0) { localVarHeaderParams.Accept = 'application/json'; } else { localVarHeaderParams.Accept = produces.join(','); } let localVarFormParams: any = {}; // verify required parameter 'runId' is not null or undefined if (runId === null || runId === undefined) { throw new Error('Required parameter runId was null or undefined when calling getTtsRunInfoById.'); } if (outputType !== undefined) { localVarQueryParameters['output_type'] = ObjectSerializer.serialize(outputType, "OutputType"); } (Object).assign(localVarHeaderParams, options.headers); let localVarUseFormData = false; let localVarRequestOptions: localVarRequest.Options = { method: 'GET', qs: localVarQueryParameters, headers: localVarHeaderParams, uri: localVarPath, useQuerystring: this._useQuerystring, json: true, }; let authenticationPromise = Promise.resolve(); if (this.authentications.APIKeyHeader.apiKey) { authenticationPromise = authenticationPromise.then(() => this.authentications.APIKeyHeader.applyToRequest(localVarRequestOptions)); } authenticationPromise = authenticationPromise.then(() => this.authentications.default.applyToRequest(localVarRequestOptions)); let interceptorPromise = authenticationPromise; for (const interceptor of this.interceptors) { interceptorPromise = interceptorPromise.then(() => interceptor(localVarRequestOptions)); } return interceptorPromise.then(() => { if (Object.keys(localVarFormParams).length) { if (localVarUseFormData) { (localVarRequestOptions).formData = localVarFormParams; } else { localVarRequestOptions.form = localVarFormParams; } } return new Promise<{ response: http.IncomingMessage; body: string; }>((resolve, reject) => { localVarRequest(localVarRequestOptions, (error, response, body) => { if (error) { reject(error); } else { if (response.statusCode && response.statusCode >= 200 && response.statusCode <= 299) { body = ObjectSerializer.deserialize(body, "string"); resolve({ response: response, body: body }); } else { reject(new HttpError(response, body, response.statusCode)); } } }); }); }); } /** * * @summary List Voices */ public async listVoices (options: {headers: {[name: string]: string}} = {headers: {}}) : Promise<{ response: http.IncomingMessage; body: Array; }> { const localVarPath = this.basePath + '/list-voices'; let localVarQueryParameters: any = {}; let localVarHeaderParams: any = (Object).assign({}, this._defaultHeaders); const produces = ['application/json']; // give precedence to 'application/json' if (produces.indexOf('application/json') >= 0) { localVarHeaderParams.Accept = 'application/json'; } else { localVarHeaderParams.Accept = produces.join(','); } let localVarFormParams: any = {}; (Object).assign(localVarHeaderParams, options.headers); let localVarUseFormData = false; let localVarRequestOptions: localVarRequest.Options = { method: 'GET', qs: localVarQueryParameters, headers: localVarHeaderParams, uri: localVarPath, useQuerystring: this._useQuerystring, json: true, }; let authenticationPromise = Promise.resolve(); if (this.authentications.APIKeyHeader.apiKey) { authenticationPromise = authenticationPromise.then(() => this.authentications.APIKeyHeader.applyToRequest(localVarRequestOptions)); } authenticationPromise = authenticationPromise.then(() => this.authentications.default.applyToRequest(localVarRequestOptions)); let interceptorPromise = authenticationPromise; for (const interceptor of this.interceptors) { interceptorPromise = interceptorPromise.then(() => interceptor(localVarRequestOptions)); } return interceptorPromise.then(() => { if (Object.keys(localVarFormParams).length) { if (localVarUseFormData) { (localVarRequestOptions).formData = localVarFormParams; } else { localVarRequestOptions.form = localVarFormParams; } } return new Promise<{ response: http.IncomingMessage; body: Array; }>((resolve, reject) => { localVarRequest(localVarRequestOptions, (error, response, body) => { if (error) { reject(error); } else { if (response.statusCode && response.statusCode >= 200 && response.statusCode <= 299) { body = ObjectSerializer.deserialize(body, "Array"); resolve({ response: response, body: body }); } else { reject(new HttpError(response, body, response.statusCode)); } } }); }); }); } /** * Get the status of a text-to-voice task by its ID. * @summary Get Text-to-Voice Task Status * @param taskId */ public async textToVoiceTaskIdGet (taskId: string, options: {headers: {[name: string]: string}} = {headers: {}}) : Promise<{ response: http.IncomingMessage; body: OrchestratorPipelineResult; }> { const localVarPath = this.basePath + '/text-to-voice/{task_id}' .replace('{' + 'task_id' + '}', encodeURIComponent(String(taskId))); let localVarQueryParameters: any = {}; let localVarHeaderParams: any = (Object).assign({}, this._defaultHeaders); const produces = ['application/json']; // give precedence to 'application/json' if (produces.indexOf('application/json') >= 0) { localVarHeaderParams.Accept = 'application/json'; } else { localVarHeaderParams.Accept = produces.join(','); } let localVarFormParams: any = {}; // verify required parameter 'taskId' is not null or undefined if (taskId === null || taskId === undefined) { throw new Error('Required parameter taskId was null or undefined when calling textToVoiceTaskIdGet.'); } (Object).assign(localVarHeaderParams, options.headers); let localVarUseFormData = false; let localVarRequestOptions: localVarRequest.Options = { method: 'GET', qs: localVarQueryParameters, headers: localVarHeaderParams, uri: localVarPath, useQuerystring: this._useQuerystring, json: true, }; let authenticationPromise = Promise.resolve(); if (this.authentications.APIKeyHeader.apiKey) { authenticationPromise = authenticationPromise.then(() => this.authentications.APIKeyHeader.applyToRequest(localVarRequestOptions)); } authenticationPromise = authenticationPromise.then(() => this.authentications.default.applyToRequest(localVarRequestOptions)); let interceptorPromise = authenticationPromise; for (const interceptor of this.interceptors) { interceptorPromise = interceptorPromise.then(() => interceptor(localVarRequestOptions)); } return interceptorPromise.then(() => { if (Object.keys(localVarFormParams).length) { if (localVarUseFormData) { (localVarRequestOptions).formData = localVarFormParams; } else { localVarRequestOptions.form = localVarFormParams; } } return new Promise<{ response: http.IncomingMessage; body: OrchestratorPipelineResult; }>((resolve, reject) => { localVarRequest(localVarRequestOptions, (error, response, body) => { if (error) { reject(error); } else { if (response.statusCode && response.statusCode >= 200 && response.statusCode <= 299) { body = ObjectSerializer.deserialize(body, "OrchestratorPipelineResult"); resolve({ response: response, body: body }); } else { reject(new HttpError(response, body, response.statusCode)); } } }); }); }); } /** * Generic polling function that waits for a task to complete * * @param checkStatusFn Function that checks the status of the task and returns a result * @param isCompleteFn Function that determines if the task is complete based on the result * @param timeout Maximum time to wait in seconds * @param verbose Whether to log status updates * @returns The final result from checkStatusFn * @throws Error if the timeout is reached */ public async pollForCompletion( checkStatusFn: () => Promise, isCompleteFn: (result: T) => boolean, timeout: number, verbose: boolean = false, taskName: string = "Task" ): Promise { const startTime = Date.now(); while (Date.now() - startTime < timeout * 1000) { if (verbose) { const elapsed = (Date.now() - startTime) / 1000; const remaining = Math.max(0, timeout - elapsed); console.log(`Checking status... (elapsed: ${elapsed.toFixed(1)}s, remaining: ${remaining.toFixed(1)}s)`); } try { const result = await checkStatusFn(); if (isCompleteFn(result)) { return result; } else if (verbose) { const status = (result as any).body?.status || "UNKNOWN"; console.log(`Still processing... (status: ${status})`); } } catch (error: any) { if (verbose) { console.log(`Error checking status: ${error.message}`); } } // Wait before next poll await new Promise(resolve => setTimeout(resolve, POLL_INTERVAL)); } throw new Error(`${taskName} did not complete within ${timeout} seconds`); } /** * Convert text to audio and return the audio bytes or save to file. * * This is a convenience method that combines createTextToSound, getTextToAudioStatusById, * and getTextToSoundRunResultById into a single call. * * @param prompt The text prompt to convert to audio * @param duration The desired duration of the audio in seconds * @param timeout Maximum time to wait for processing in seconds (default: 60) * @param saveToFile Optional file path to save the audio to * @param verbose Whether to print status updates during processing * * @returns If saveToFile is provided: Returns a string confirming the file was saved * Otherwise: Returns the audio as a Buffer * * @throws Error if there's an error with the API call * @throws Error if the processing doesn't complete within the timeout period * @throws Error if there's an error saving the file */ public async textToAudio( prompt: string, duration: number, timeout: number = 60, saveToFile?: string, verbose: boolean = false ): Promise { // Create the request payload const requestPayload = new CreateTextToAudioRequestPayload(); requestPayload.prompt = prompt; requestPayload.duration = duration; if (verbose) { console.log(`Submitting text-to-audio request for prompt: '${prompt.substring(0, 30)}...' with duration: ${duration}`); } const taskIdObj = await this.createTextToSound(requestPayload); const taskIdStr = taskIdObj.body.taskId!; if (verbose) { console.log(`Request submitted. Task ID: ${taskIdStr}`); console.log(`Waiting for processing to complete (timeout: ${timeout} seconds)...`); } // Use the polling function to wait for completion const result = await this.pollForCompletion( () => this.getTextToAudioStatusById(taskIdStr), (result) => result.body.runId !== undefined && result.body.status === TaskStatus.Success, timeout, verbose, "Text-to-audio request" ); if (verbose) { console.log(`Processing complete! Run ID: ${result.body.runId}`); console.log("Retrieving audio..."); } // Get the audio data const audioData = await this.getTextToSoundRunResultById(result.body.runId!); if (saveToFile) { try { fs.writeFileSync(saveToFile, audioData.body); if (verbose) { console.log(`Audio saved to file: ${saveToFile}`); } return `Audio saved to ${saveToFile}`; } catch (error: any) { throw new Error(`Failed to save audio to file: ${error.message}`); } } return audioData.body; } /** * Convert text to voice using a voice description and return the result. * * This is a convenience method that combines createVoiceFromDescription, textToVoiceTaskIdGet, * and getTextToVoiceRunResultById into a single call. * * @param text The text to convert to speech * @param voiceDescription Description of the voice to generate * @param timeout Maximum time to wait for processing in seconds (default: 60) * @param verbose Whether to print status updates during processing * * @returns A dictionary with the voice generation result (typically containing URLs to the generated audio) * * @throws Error if there's an error with the API call * @throws Error if the processing doesn't complete within the timeout period */ public async textToVoice( text: string, voiceDescription: string, timeout: number = 60, verbose: boolean = false ): Promise { // Create the request payload const requestPayload = new CreateTextToVoiceRequestPayload(); requestPayload.text = text; requestPayload.voiceDescription = voiceDescription; if (verbose) { console.log(`Submitting text-to-voice request for text: '${text.substring(0, 30)}...'`); console.log(`Voice description: '${voiceDescription.substring(0, 50)}...'`); } const taskIdObj = await this.createVoiceFromDescription(requestPayload); const taskIdStr = taskIdObj.body.taskId!; if (verbose) { console.log(`Request submitted. Task ID: ${taskIdStr}`); console.log(`Waiting for processing to complete (timeout: ${timeout} seconds)...`); } // Use the polling function to wait for completion const result = await this.pollForCompletion( () => this.textToVoiceTaskIdGet(taskIdStr), (result) => result.body.runId !== undefined && result.body.status === TaskStatus.Success, timeout, verbose, "Text-to-voice request" ); if (verbose) { console.log(`Processing complete! Run ID: ${result.body.runId}`); console.log(`Retrieving voice result...`); } const response = await this.getTextToVoiceRunResultById(result.body.runId!); return response.body; } /** * Get TTS run info with raw binary data (without JSON parsing). * This method is used internally for file saving when OutputType.RawBytes is requested. * * @param runId The run ID * @param outputType The output type * @returns Promise with binary data as Buffer */ private async getTtsRunInfoByIdRaw(runId: number, outputType: OutputType): Promise<{ response: http.IncomingMessage; body: Buffer; }> { const localVarPath = this.basePath + '/tts-result/{run_id}' .replace('{' + 'run_id' + '}', encodeURIComponent(String(runId))); let localVarQueryParameters: any = {}; let localVarHeaderParams: any = (Object).assign({}, this._defaultHeaders); // For raw bytes, we want audio content, not JSON if (outputType === OutputType.RawBytes) { localVarHeaderParams.Accept = 'audio/flac, audio/wav, audio/mp3, audio/aac'; } else { localVarHeaderParams.Accept = 'application/json'; } let localVarFormParams: any = {}; if (outputType !== undefined) { localVarQueryParameters['output_type'] = ObjectSerializer.serialize(outputType, "OutputType"); } let localVarUseFormData = false; let localVarRequestOptions: localVarRequest.Options = { method: 'GET', qs: localVarQueryParameters, headers: localVarHeaderParams, uri: localVarPath, useQuerystring: this._useQuerystring, encoding: null, // Important: This tells request to return a Buffer instead of string json: false, // Important: Don't parse as JSON }; let authenticationPromise = Promise.resolve(); if (this.authentications.APIKeyHeader.apiKey) { authenticationPromise = authenticationPromise.then(() => this.authentications.APIKeyHeader.applyToRequest(localVarRequestOptions)); } authenticationPromise = authenticationPromise.then(() => this.authentications.default.applyToRequest(localVarRequestOptions)); let interceptorPromise = authenticationPromise; for (const interceptor of this.interceptors) { interceptorPromise = interceptorPromise.then(() => interceptor(localVarRequestOptions)); } return interceptorPromise.then(() => { if (Object.keys(localVarFormParams).length) { if (localVarUseFormData) { (localVarRequestOptions).formData = localVarFormParams; } else { localVarRequestOptions.form = localVarFormParams; } } return new Promise<{ response: http.IncomingMessage; body: Buffer; }>((resolve, reject) => { localVarRequest(localVarRequestOptions, (error, response, body) => { if (error) { reject(error); } else { if (response.statusCode && response.statusCode >= 200 && response.statusCode <= 299) { resolve({ response: response, body: body }); } else { reject(new HttpError(response, body, response.statusCode)); } } }); }); }); } /** * Convert text to speech and return the audio URL, bytes, or save to file. * * This is a convenience method that combines createTts, getTtsResultById, * and getTtsRunInfoById into a single call. * * @param text The text to convert to speech * @param voiceId The ID of the voice to use * @param language The language ID (default: Languages.NUMBER_1) * @param timeout Maximum time to wait for processing in seconds (default: 60) * @param outputType Type of output to return (default: OutputType.Url) * @param saveToFile Optional file path to save the audio to (works with BYTES output type) * @param verbose Whether to print status updates during processing * * @returns If outputType is FILE_URL: Returns the URL string or dict with URL * If outputType is BYTES: Returns the audio bytes or saves to file if saveToFile is provided * * @throws Error if there's an error with the API call * @throws Error if the processing doesn't complete within the timeout period * @throws Error if there's an error saving the file */ public async textToSpeech( text: string, voiceId: number, language: Languages = Languages.NUMBER_1, timeout: number = 60, outputType: OutputType = OutputType.FileUrl, saveToFile?: string, verbose: boolean = false ): Promise { // Create the request payload const requestPayload = new CreateTTSRequestPayload(); requestPayload.text = text; requestPayload.voiceId = voiceId; requestPayload.language = language; // Submit the TTS request if (verbose) { console.log(`Submitting TTS request for text: '${text.substring(0, 30)}...' with voice ID: ${voiceId}`); } const taskIdObj = await this.createTts(requestPayload); const taskIdStr = taskIdObj.body.taskId!; if (verbose) { console.log(`Request submitted. Task ID: ${taskIdStr}`); console.log(`Waiting for processing to complete (timeout: ${timeout} seconds)...`); } // Use the polling function to wait for completion const result = await this.pollForCompletion( () => this.getTtsResultById(taskIdStr), (result) => result.body.runId !== undefined && result.body.status === TaskStatus.Success, timeout, verbose, "TTS request" ); if (verbose) { console.log(`Processing complete! Run ID: ${result.body.runId}`); console.log(`Retrieving audio with output type: ${outputType}`); } if (outputType === OutputType.RawBytes) { // Use raw method for binary data const response = await this.getTtsRunInfoByIdRaw(result.body.runId!, outputType); if (saveToFile) { try { fs.writeFileSync(saveToFile, response.body); if (verbose) { console.log(`Audio saved to file: ${saveToFile}`); } return `Audio saved to ${saveToFile}`; } catch (error: any) { throw new Error(`Failed to save audio to file: ${error.message}`); } } return response.body; } else { const response = await this.getTtsRunInfoById(result.body.runId!, outputType); return response.body; } } /** * End-to-end dubbing convenience method that combines createEndToEndDubbing, * getEndToEndDubbingStatusById, and getDubbedRunInfoById into a single call. * * This is a convenience method that handles the entire dubbing workflow automatically. * * @param videoUrl The URL of the media file to be used for the end-to-end dubbing task * @param sourceLanguage The original language of the media file * @param targetLanguages The list of desired languages that the media file will be dubbed to * @param timeout Maximum time to wait for processing in seconds (default: 300) * @param verbose Whether to print status updates during processing * * @returns A dictionary containing the dubbing result, typically including URLs to the generated audio files * * @throws Error if there's an error with the API call * @throws Error if the processing doesn't complete within the timeout period * @throws Error if the dubbing process fails */ public async endToEndDubbing( videoUrl: string, sourceLanguage: Languages, targetLanguages?: Array, timeout: number = 300, verbose: boolean = false ): Promise { // Create the request payload const requestPayload = new EndToEndDubbingRequestPayload(); requestPayload.videoUrl = videoUrl; requestPayload.sourceLanguage = sourceLanguage; if (targetLanguages) { requestPayload.targetLanguages = targetLanguages; } if (verbose) { console.log(`Submitting end-to-end dubbing request for video: '${videoUrl}'`); console.log(`Source language: ${sourceLanguage}, Target languages: ${targetLanguages ? targetLanguages.join(', ') : 'default'}`); } const taskIdObj = await this.createEndToEndDubbing(requestPayload); const taskIdStr = taskIdObj.body.taskId!; if (verbose) { console.log(`Request submitted. Task ID: ${taskIdStr}`); console.log(`Waiting for processing to complete (timeout: ${timeout} seconds)...`); } // Use the polling function to wait for completion const result = await this.pollForCompletion( () => this.getEndToEndDubbingStatusById(taskIdStr), (result) => result.body.runId !== undefined && ( result.body.status === TaskStatus.Success || result.body.status === TaskStatus.Error || result.body.status === TaskStatus.Timeout || result.body.status === TaskStatus.PaymentRequired ), timeout, verbose, "End-to-end dubbing request" ); // Check if the task completed successfully if (result.body.status === TaskStatus.Error) { throw new Error(`End-to-end dubbing failed with ERROR status. Task ID: ${taskIdStr}`); } else if (result.body.status === TaskStatus.Timeout) { throw new Error(`End-to-end dubbing failed with TIMEOUT status. Task ID: ${taskIdStr}`); } else if (result.body.status === TaskStatus.PaymentRequired) { throw new Error(`End-to-end dubbing failed with PAYMENT_REQUIRED status. Task ID: ${taskIdStr}`); } if (verbose) { console.log(`Processing complete! Run ID: ${result.body.runId}`); console.log(`Retrieving dubbing result...`); } const response = await this.getDubbedRunInfoById(result.body.runId!); return response.body; } }