From db29ea75cb6850af6748092eb62618f4a296b3c2 Mon Sep 17 00:00:00 2001 From: dsinghvi Date: Wed, 11 Dec 2024 20:54:59 -0500 Subject: [PATCH] fix: bytes returns arraybuffer --- .fernignore | 6 ++++++ src/api/resources/tts/client/Client.ts | 6 +++--- src/api/resources/voiceChanger/client/Client.ts | 6 +++--- src/core/fetcher/Fetcher.ts | 2 +- src/core/fetcher/getResponseBody.ts | 2 ++ 5 files changed, 15 insertions(+), 7 deletions(-) diff --git a/.fernignore b/.fernignore index 7abede4..c57216b 100644 --- a/.fernignore +++ b/.fernignore @@ -7,3 +7,9 @@ src/index.ts src/core/websocket src/serialization/resources/tts/types/OutputFormat.ts + +# arraybuffer +src/api/resources/tts/client/Client.ts +src/api/resources/voiceChanger/client/Client.ts +src/core/fetcher/Fetcher.ts +src/core/fetcher/getResponseBody.ts diff --git a/src/api/resources/tts/client/Client.ts b/src/api/resources/tts/client/Client.ts index c2ae294..38627be 100644 --- a/src/api/resources/tts/client/Client.ts +++ b/src/api/resources/tts/client/Client.ts @@ -34,8 +34,8 @@ export declare namespace Tts { export class Tts { constructor(protected readonly _options: Tts.Options = {}) {} - public async bytes(request: Cartesia.TtsRequest, requestOptions?: Tts.RequestOptions): Promise { - const _response = await (this._options.fetcher ?? core.fetcher)({ + public async bytes(request: Cartesia.TtsRequest, requestOptions?: Tts.RequestOptions): Promise { + const _response = await (this._options.fetcher ?? core.fetcher)({ url: urlJoin( (await core.Supplier.get(this._options.environment)) ?? environments.CartesiaEnvironment.Production, "/tts/bytes" @@ -54,7 +54,7 @@ export class Tts { contentType: "application/json", requestType: "json", body: serializers.TtsRequest.jsonOrThrow(request, { unrecognizedObjectKeys: "strip" }), - responseType: "streaming", + responseType: "arraybuffer", timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, diff --git a/src/api/resources/voiceChanger/client/Client.ts b/src/api/resources/voiceChanger/client/Client.ts index e2b479b..a31878b 100644 --- a/src/api/resources/voiceChanger/client/Client.ts +++ b/src/api/resources/voiceChanger/client/Client.ts @@ -45,7 +45,7 @@ export class VoiceChanger { clip: File | fs.ReadStream | Blob, request: Cartesia.VoiceChangerBytesRequest, requestOptions?: VoiceChanger.RequestOptions - ): Promise { + ): Promise { const _request = await core.newFormData(); await _request.appendFile("clip", clip); await _request.append("voice[id]", request.voiceId); @@ -60,7 +60,7 @@ export class VoiceChanger { } const _maybeEncodedRequest = await _request.getRequest(); - const _response = await (this._options.fetcher ?? core.fetcher)({ + const _response = await (this._options.fetcher ?? core.fetcher)({ url: urlJoin( (await core.Supplier.get(this._options.environment)) ?? environments.CartesiaEnvironment.Production, "/voice-changer/bytes" @@ -80,7 +80,7 @@ export class VoiceChanger { requestType: "file", duplex: _maybeEncodedRequest.duplex, body: _maybeEncodedRequest.body, - responseType: "streaming", + responseType: "arraybuffer", timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, diff --git a/src/core/fetcher/Fetcher.ts b/src/core/fetcher/Fetcher.ts index d67bc04..8f9d530 100644 --- a/src/core/fetcher/Fetcher.ts +++ b/src/core/fetcher/Fetcher.ts @@ -21,7 +21,7 @@ export declare namespace Fetcher { withCredentials?: boolean; abortSignal?: AbortSignal; requestType?: "json" | "file" | "bytes"; - responseType?: "json" | "blob" | "sse" | "streaming" | "text"; + responseType?: "json" | "blob" | "sse" | "streaming" | "text" | "arraybuffer"; duplex?: "half"; } diff --git a/src/core/fetcher/getResponseBody.ts b/src/core/fetcher/getResponseBody.ts index a7a9c50..4e3a830 100644 --- a/src/core/fetcher/getResponseBody.ts +++ b/src/core/fetcher/getResponseBody.ts @@ -7,6 +7,8 @@ export async function getResponseBody(response: Response, responseType?: string) return response.body; } else if (response.body != null && responseType === "streaming") { return chooseStreamWrapper(response.body); + } else if (response.body != null && responseType === "arraybuffer") { + return await response.arrayBuffer(); } else if (response.body != null && responseType === "text") { return await response.text(); } else {