diff --git a/.fernignore b/.fernignore index 084a8eb..4723d18 100644 --- a/.fernignore +++ b/.fernignore @@ -1 +1,5 @@ # Specify files that shouldn't be modified by Fern + +src/wrapper +src/core/websocket +src/serialization/resources/tts/types/OutputFormat.ts \ No newline at end of file diff --git a/jest.config.js b/jest.config.js index 35d6e65..eaddc00 100644 --- a/jest.config.js +++ b/jest.config.js @@ -1,5 +1,15 @@ /** @type {import('jest').Config} */ module.exports = { - preset: "ts-jest", - testEnvironment: "node", -}; + preset: 'ts-jest/presets/default-esm', + testEnvironment: 'node', + extensionsToTreatAsEsm: ['.ts'], + globals: { + 'ts-jest': { + useESM: true, + }, + }, + transformIgnorePatterns: [ + '/node_modules/(?!(emittery)/)', + ], + }; + \ No newline at end of file diff --git a/reference.md b/reference.md index 1b1f3ae..a64a99d 100644 --- a/reference.md +++ b/reference.md @@ -58,17 +58,17 @@ await client.apiStatus.get(); ```typescript await client.tts.bytes({ - model_id: "sonic-english", + modelId: "sonic-english", transcript: "Hello, world!", voice: { mode: "id", id: "694f9389-aac1-45b6-b726-9d9369183238", }, language: "en", - output_format: { + outputFormat: { container: "mp3", - sample_rate: 44100, - bit_rate: 128000, + sampleRate: 44100, + bitRate: 128000, }, }); ``` @@ -119,18 +119,18 @@ await client.tts.bytes({ ```typescript const response = await client.tts.sse({ - model_id: "string", + modelId: "string", transcript: "string", voice: { mode: "id", id: "string", - __experimental_controls: { + experimentalControls: { speed: 1.1, emotion: "anger:lowest", }, }, language: "en", - output_format: { + outputFormat: { container: "raw", }, duration: 1.1, @@ -205,10 +205,10 @@ This endpoint is priced at 15 characters per second of input audio. ```typescript await client.voiceChanger.bytes(fs.createReadStream("/path/to/your/file"), { - "voice[id]": "694f9389-aac1-45b6-b726-9d9369183238", - "output_format[container]": "mp3", - "output_format[sample_rate]": 44100, - "output_format[bit_rate]": 128000, + voiceId: "694f9389-aac1-45b6-b726-9d9369183238", + outputFormatContainer: "mp3", + outputFormatSampleRate: 44100, + outputFormatBitRate: 128000, }); ``` @@ -266,10 +266,10 @@ await client.voiceChanger.bytes(fs.createReadStream("/path/to/your/file"), { ```typescript const response = await client.voiceChanger.sse(fs.createReadStream("/path/to/your/file"), { - "voice[id]": "694f9389-aac1-45b6-b726-9d9369183238", - "output_format[container]": "mp3", - "output_format[sample_rate]": 44100, - "output_format[bit_rate]": 128000, + voiceId: "694f9389-aac1-45b6-b726-9d9369183238", + outputFormatContainer: "mp3", + outputFormatSampleRate: 44100, + outputFormatBitRate: 128000, }); for await (const item of response) { console.log(item); @@ -383,7 +383,7 @@ await client.voices.create({ 1, 1, 1, 1, 1, 1, 1, ], language: "en", - base_voice_id: "string", + baseVoiceId: "string", }); ``` @@ -597,7 +597,7 @@ await client.voices.localize({ 1, 1, 1, 1, 1, 1, 1, ], language: "en", - original_speaker_gender: "male", + originalSpeakerGender: "male", dialect: "au", }); ``` diff --git a/src/api/resources/apiStatus/client/Client.ts b/src/api/resources/apiStatus/client/Client.ts index 2147892..4089c6c 100644 --- a/src/api/resources/apiStatus/client/Client.ts +++ b/src/api/resources/apiStatus/client/Client.ts @@ -5,6 +5,7 @@ import * as environments from "../../../../environments"; import * as core from "../../../../core"; import * as Cartesia from "../../../index"; +import * as serializers from "../../../../serialization/index"; import * as errors from "../../../../errors/index"; export declare namespace ApiStatus { @@ -58,7 +59,13 @@ export class ApiStatus { abortSignal: requestOptions?.abortSignal, }); if (_response.ok) { - return _response.body as Cartesia.ApiInfo; + return serializers.ApiInfo.parseOrThrow(_response.body, { + unrecognizedObjectKeys: "passthrough", + allowUnrecognizedUnionMembers: true, + allowUnrecognizedEnumValues: true, + skipValidation: true, + breadcrumbsPrefix: ["response"], + }); } if (_response.error.reason === "status-code") { diff --git a/src/api/resources/tts/client/Client.ts b/src/api/resources/tts/client/Client.ts index 896e661..bd4b42d 100644 --- a/src/api/resources/tts/client/Client.ts +++ b/src/api/resources/tts/client/Client.ts @@ -6,9 +6,9 @@ import * as environments from "../../../../environments"; import * as core from "../../../../core"; import * as Cartesia from "../../../index"; import * as stream from "stream"; +import * as serializers from "../../../../serialization/index"; import urlJoin from "url-join"; import * as errors from "../../../../errors/index"; -import * as serializers from "../../../../serialization/index"; export declare namespace Tts { interface Options { @@ -53,7 +53,7 @@ export class Tts { }, contentType: "application/json", requestType: "json", - body: request, + body: serializers.TtsRequest.jsonOrThrow(request, { unrecognizedObjectKeys: "strip" }), responseType: "streaming", timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, @@ -107,7 +107,7 @@ export class Tts { }, contentType: "application/json", requestType: "json", - body: request, + body: serializers.TtsRequest.jsonOrThrow(request, { unrecognizedObjectKeys: "strip" }), responseType: "sse", timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, diff --git a/src/api/resources/tts/types/CancelContextRequest.ts b/src/api/resources/tts/types/CancelContextRequest.ts index 31c7bd4..f5622ad 100644 --- a/src/api/resources/tts/types/CancelContextRequest.ts +++ b/src/api/resources/tts/types/CancelContextRequest.ts @@ -6,7 +6,7 @@ import * as Cartesia from "../../../index"; export interface CancelContextRequest { /** The ID of the context to cancel. */ - context_id: Cartesia.ContextId; + contextId: Cartesia.ContextId; /** Whether to cancel the context, so that no more messages are generated for that context. */ cancel: true; } diff --git a/src/api/resources/tts/types/GenerationRequest.ts b/src/api/resources/tts/types/GenerationRequest.ts index 8ac66ce..0dce467 100644 --- a/src/api/resources/tts/types/GenerationRequest.ts +++ b/src/api/resources/tts/types/GenerationRequest.ts @@ -6,22 +6,22 @@ import * as Cartesia from "../../../index"; export interface GenerationRequest { /** The ID of the model to use for the generation. See [Models](/build-with-sonic/models) for available models. */ - model_id: string; + modelId: string; transcript: string; voice: Cartesia.TtsRequestVoiceSpecifier; language?: Cartesia.SupportedLanguage; - output_format: Cartesia.WebSocketRawOutputFormat; + outputFormat: Cartesia.WebSocketRawOutputFormat; /** * The maximum duration of the audio in seconds. You do not usually need to specify this. * If the duration is not appropriate for the length of the transcript, the output audio may be truncated. */ duration?: number; - context_id: Cartesia.ContextId; + contextId: Cartesia.ContextId; /** * Whether this input may be followed by more inputs. * If not specified, this defaults to `false`. */ continue?: boolean; /** Whether to return word-level timestamps. */ - add_timestamps?: boolean; + addTimestamps?: boolean; } diff --git a/src/api/resources/tts/types/Mp3OutputFormat.ts b/src/api/resources/tts/types/Mp3OutputFormat.ts index 7031390..4ca41a6 100644 --- a/src/api/resources/tts/types/Mp3OutputFormat.ts +++ b/src/api/resources/tts/types/Mp3OutputFormat.ts @@ -3,6 +3,6 @@ */ export interface Mp3OutputFormat { - sample_rate: number; - bit_rate: number; + sampleRate: number; + bitRate: number; } diff --git a/src/api/resources/tts/types/RawOutputFormat.ts b/src/api/resources/tts/types/RawOutputFormat.ts index 83118fa..0f32735 100644 --- a/src/api/resources/tts/types/RawOutputFormat.ts +++ b/src/api/resources/tts/types/RawOutputFormat.ts @@ -6,5 +6,5 @@ import * as Cartesia from "../../../index"; export interface RawOutputFormat { encoding: Cartesia.RawEncoding; - sample_rate: number; + sampleRate: number; } diff --git a/src/api/resources/tts/types/TtsRequest.ts b/src/api/resources/tts/types/TtsRequest.ts index 7778620..154f6d1 100644 --- a/src/api/resources/tts/types/TtsRequest.ts +++ b/src/api/resources/tts/types/TtsRequest.ts @@ -6,11 +6,11 @@ import * as Cartesia from "../../../index"; export interface TtsRequest { /** The ID of the model to use for the generation. See [Models](/build-with-sonic/models) for available models. */ - model_id: string; + modelId: string; transcript: string; voice: Cartesia.TtsRequestVoiceSpecifier; language?: Cartesia.SupportedLanguage; - output_format: Cartesia.OutputFormat; + outputFormat: Cartesia.OutputFormat; /** * The maximum duration of the audio in seconds. You do not usually need to specify this. * If the duration is not appropriate for the length of the transcript, the output audio may be truncated. diff --git a/src/api/resources/tts/types/TtsRequestEmbeddingSpecifier.ts b/src/api/resources/tts/types/TtsRequestEmbeddingSpecifier.ts index 2bf19d5..b85fc8e 100644 --- a/src/api/resources/tts/types/TtsRequestEmbeddingSpecifier.ts +++ b/src/api/resources/tts/types/TtsRequestEmbeddingSpecifier.ts @@ -7,5 +7,5 @@ import * as Cartesia from "../../../index"; export interface TtsRequestEmbeddingSpecifier { mode: "embedding"; embedding: Cartesia.Embedding; - __experimental_controls?: Cartesia.Controls; + experimentalControls?: Cartesia.Controls; } diff --git a/src/api/resources/tts/types/TtsRequestIdSpecifier.ts b/src/api/resources/tts/types/TtsRequestIdSpecifier.ts index b53f481..ffdce30 100644 --- a/src/api/resources/tts/types/TtsRequestIdSpecifier.ts +++ b/src/api/resources/tts/types/TtsRequestIdSpecifier.ts @@ -7,5 +7,5 @@ import * as Cartesia from "../../../index"; export interface TtsRequestIdSpecifier { mode: "id"; id: Cartesia.VoiceId; - __experimental_controls?: Cartesia.Controls; + experimentalControls?: Cartesia.Controls; } diff --git a/src/api/resources/tts/types/WebSocketBaseResponse.ts b/src/api/resources/tts/types/WebSocketBaseResponse.ts index 6a6e4c6..62279a6 100644 --- a/src/api/resources/tts/types/WebSocketBaseResponse.ts +++ b/src/api/resources/tts/types/WebSocketBaseResponse.ts @@ -5,7 +5,7 @@ import * as Cartesia from "../../../index"; export interface WebSocketBaseResponse { - context_id?: Cartesia.ContextId; - status_code: number; + contextId?: Cartesia.ContextId; + statusCode: number; done: boolean; } diff --git a/src/api/resources/tts/types/WebSocketChunkResponse.ts b/src/api/resources/tts/types/WebSocketChunkResponse.ts index 0be3498..1e1c82e 100644 --- a/src/api/resources/tts/types/WebSocketChunkResponse.ts +++ b/src/api/resources/tts/types/WebSocketChunkResponse.ts @@ -6,5 +6,5 @@ import * as Cartesia from "../../../index"; export interface WebSocketChunkResponse extends Cartesia.WebSocketBaseResponse { data: string; - step_time: number; + stepTime: number; } diff --git a/src/api/resources/tts/types/WebSocketRawOutputFormat.ts b/src/api/resources/tts/types/WebSocketRawOutputFormat.ts index 79bd10d..17a25a7 100644 --- a/src/api/resources/tts/types/WebSocketRawOutputFormat.ts +++ b/src/api/resources/tts/types/WebSocketRawOutputFormat.ts @@ -7,5 +7,5 @@ import * as Cartesia from "../../../index"; export interface WebSocketRawOutputFormat { container: "raw"; encoding: Cartesia.RawEncoding; - sample_rate: number; + sampleRate: number; } diff --git a/src/api/resources/tts/types/WebSocketResponse.ts b/src/api/resources/tts/types/WebSocketResponse.ts index a43b3de..861851b 100644 --- a/src/api/resources/tts/types/WebSocketResponse.ts +++ b/src/api/resources/tts/types/WebSocketResponse.ts @@ -7,7 +7,7 @@ import * as Cartesia from "../../../index"; export type WebSocketResponse = | Cartesia.WebSocketResponse.Chunk | Cartesia.WebSocketResponse.Done - | Cartesia.WebSocketResponse.Timestamp + | Cartesia.WebSocketResponse.Timestamps | Cartesia.WebSocketResponse.Error_; export declare namespace WebSocketResponse { @@ -19,8 +19,8 @@ export declare namespace WebSocketResponse { type: "done"; } - interface Timestamp extends Cartesia.WebSocketTimestampResponse { - type: "timestamp"; + interface Timestamps extends Cartesia.WebSocketTimestampsResponse { + type: "timestamps"; } interface Error_ extends Cartesia.WebSocketErrorResponse { diff --git a/src/api/resources/tts/types/WebSocketTimestampResponse.ts b/src/api/resources/tts/types/WebSocketTimestampResponse.ts deleted file mode 100644 index b3b7cae..0000000 --- a/src/api/resources/tts/types/WebSocketTimestampResponse.ts +++ /dev/null @@ -1,9 +0,0 @@ -/** - * This file was auto-generated by Fern from our API Definition. - */ - -import * as Cartesia from "../../../index"; - -export interface WebSocketTimestampResponse extends Cartesia.WebSocketBaseResponse { - word_timestamps?: Cartesia.WordTimestamps; -} diff --git a/src/api/resources/tts/types/WebSocketTtsOutput.ts b/src/api/resources/tts/types/WebSocketTtsOutput.ts index 0b41146..73e2863 100644 --- a/src/api/resources/tts/types/WebSocketTtsOutput.ts +++ b/src/api/resources/tts/types/WebSocketTtsOutput.ts @@ -5,7 +5,7 @@ import * as Cartesia from "../../../index"; export interface WebSocketTtsOutput { - word_timestamps?: Cartesia.WordTimestamps; + wordTimestamps?: Cartesia.WordTimestamps; audio?: unknown; - context_id?: Cartesia.ContextId; + contextId?: Cartesia.ContextId; } diff --git a/src/api/resources/tts/types/WebSocketTtsRequest.ts b/src/api/resources/tts/types/WebSocketTtsRequest.ts index 04231f7..c0d3d8f 100644 --- a/src/api/resources/tts/types/WebSocketTtsRequest.ts +++ b/src/api/resources/tts/types/WebSocketTtsRequest.ts @@ -6,12 +6,12 @@ import * as Cartesia from "../../../index"; export interface WebSocketTtsRequest { /** The ID of the model to use for the generation. See [Models](/build-with-sonic/models) for available models. */ - model_id: string; - output_format: Cartesia.OutputFormat; + modelId: string; + outputFormat?: Cartesia.OutputFormat; transcript?: string; voice: Cartesia.TtsRequestVoiceSpecifier; duration?: number; language?: string; - add_timestamps: boolean; - context_id?: string; + addTimestamps?: boolean; + contextId?: string; } diff --git a/src/api/resources/tts/types/index.ts b/src/api/resources/tts/types/index.ts index 0c32ea2..5212040 100644 --- a/src/api/resources/tts/types/index.ts +++ b/src/api/resources/tts/types/index.ts @@ -3,8 +3,9 @@ export * from "./WebSocketBaseResponse"; export * from "./WebSocketResponse"; export * from "./WebSocketErrorResponse"; export * from "./WebSocketChunkResponse"; -export * from "./WebSocketTimestampResponse"; +export * from "./WebSocketTimestampsResponse"; export * from "./WebSocketTtsOutput"; +export * from "./WebSocketStreamOptions"; export * from "./WordTimestamps"; export * from "./WebSocketDoneResponse"; export * from "./CancelContextRequest"; diff --git a/src/api/resources/voiceChanger/client/Client.ts b/src/api/resources/voiceChanger/client/Client.ts index 4171289..e3ccb2d 100644 --- a/src/api/resources/voiceChanger/client/Client.ts +++ b/src/api/resources/voiceChanger/client/Client.ts @@ -48,15 +48,15 @@ export class VoiceChanger { ): Promise { const _request = await core.newFormData(); await _request.appendFile("clip", clip); - await _request.append("voice[id]", request.voice[id]); - await _request.append("output_format[container]", request.output_format[container]); - await _request.append("output_format[sample_rate]", request.output_format[sample_rate].toString()); - if (request.output_format[encoding] != null) { - await _request.append("output_format[encoding]", request.output_format[encoding]); + await _request.append("voice[id]", request.voiceId); + await _request.append("output_format[container]", request.outputFormatContainer); + await _request.append("output_format[sample_rate]", request.outputFormatSampleRate.toString()); + if (request.outputFormatEncoding != null) { + await _request.append("output_format[encoding]", request.outputFormatEncoding); } - if (request.output_format[bit_rate] != null) { - await _request.append("output_format[bit_rate]", request.output_format[bit_rate].toString()); + if (request.outputFormatBitRate != null) { + await _request.append("output_format[bit_rate]", request.outputFormatBitRate.toString()); } const _maybeEncodedRequest = await _request.getRequest(); @@ -118,15 +118,15 @@ export class VoiceChanger { ): Promise> { const _request = await core.newFormData(); await _request.appendFile("clip", clip); - await _request.append("voice[id]", request.voice[id]); - await _request.append("output_format[container]", request.output_format[container]); - await _request.append("output_format[sample_rate]", request.output_format[sample_rate].toString()); - if (request.output_format[encoding] != null) { - await _request.append("output_format[encoding]", request.output_format[encoding]); + await _request.append("voice[id]", request.voiceId); + await _request.append("output_format[container]", request.outputFormatContainer); + await _request.append("output_format[sample_rate]", request.outputFormatSampleRate.toString()); + if (request.outputFormatEncoding != null) { + await _request.append("output_format[encoding]", request.outputFormatEncoding); } - if (request.output_format[bit_rate] != null) { - await _request.append("output_format[bit_rate]", request.output_format[bit_rate].toString()); + if (request.outputFormatBitRate != null) { + await _request.append("output_format[bit_rate]", request.outputFormatBitRate.toString()); } const _maybeEncodedRequest = await _request.getRequest(); diff --git a/src/api/resources/voiceChanger/client/requests/VoiceChangerBytesRequest.ts b/src/api/resources/voiceChanger/client/requests/VoiceChangerBytesRequest.ts index ecda6ea..d86f3bd 100644 --- a/src/api/resources/voiceChanger/client/requests/VoiceChangerBytesRequest.ts +++ b/src/api/resources/voiceChanger/client/requests/VoiceChangerBytesRequest.ts @@ -7,40 +7,40 @@ import * as Cartesia from "../../../../index"; /** * @example * { - * "voice[id]": "694f9389-aac1-45b6-b726-9d9369183238", - * "output_format[container]": "mp3", - * "output_format[sample_rate]": 44100, - * "output_format[bit_rate]": 128000 + * voiceId: "694f9389-aac1-45b6-b726-9d9369183238", + * outputFormatContainer: "mp3", + * outputFormatSampleRate: 44100, + * outputFormatBitRate: 128000 * } * * @example * { - * "voice[id]": "694f9389-aac1-45b6-b726-9d9369183238", - * "output_format[container]": "wav", - * "output_format[sample_rate]": 44100, - * "output_format[encoding]": "pcm_f32le" + * voiceId: "694f9389-aac1-45b6-b726-9d9369183238", + * outputFormatContainer: "wav", + * outputFormatSampleRate: 44100, + * outputFormatEncoding: "pcm_f32le" * } * * @example * { - * "voice[id]": "694f9389-aac1-45b6-b726-9d9369183238", - * "output_format[container]": "raw", - * "output_format[sample_rate]": 44100, - * "output_format[encoding]": "pcm_f32le" + * voiceId: "694f9389-aac1-45b6-b726-9d9369183238", + * outputFormatContainer: "raw", + * outputFormatSampleRate: 44100, + * outputFormatEncoding: "pcm_f32le" * } */ export interface VoiceChangerBytesRequest { - "voice[id]": string; - "output_format[container]": Cartesia.OutputFormatContainer; - "output_format[sample_rate]": number; + voiceId: string; + outputFormatContainer: Cartesia.OutputFormatContainer; + outputFormatSampleRate: number; /** * Required for `raw` and `wav` containers. * */ - "output_format[encoding]"?: Cartesia.RawEncoding; + outputFormatEncoding?: Cartesia.RawEncoding; /** * Required for `mp3` containers. * */ - "output_format[bit_rate]"?: number; + outputFormatBitRate?: number; } diff --git a/src/api/resources/voiceChanger/client/requests/VoiceChangerSseRequest.ts b/src/api/resources/voiceChanger/client/requests/VoiceChangerSseRequest.ts index 6fa915c..b912610 100644 --- a/src/api/resources/voiceChanger/client/requests/VoiceChangerSseRequest.ts +++ b/src/api/resources/voiceChanger/client/requests/VoiceChangerSseRequest.ts @@ -7,40 +7,40 @@ import * as Cartesia from "../../../../index"; /** * @example * { - * "voice[id]": "694f9389-aac1-45b6-b726-9d9369183238", - * "output_format[container]": "mp3", - * "output_format[sample_rate]": 44100, - * "output_format[bit_rate]": 128000 + * voiceId: "694f9389-aac1-45b6-b726-9d9369183238", + * outputFormatContainer: "mp3", + * outputFormatSampleRate: 44100, + * outputFormatBitRate: 128000 * } * * @example * { - * "voice[id]": "694f9389-aac1-45b6-b726-9d9369183238", - * "output_format[container]": "wav", - * "output_format[sample_rate]": 44100, - * "output_format[encoding]": "pcm_f32le" + * voiceId: "694f9389-aac1-45b6-b726-9d9369183238", + * outputFormatContainer: "wav", + * outputFormatSampleRate: 44100, + * outputFormatEncoding: "pcm_f32le" * } * * @example * { - * "voice[id]": "694f9389-aac1-45b6-b726-9d9369183238", - * "output_format[container]": "raw", - * "output_format[sample_rate]": 44100, - * "output_format[encoding]": "pcm_f32le" + * voiceId: "694f9389-aac1-45b6-b726-9d9369183238", + * outputFormatContainer: "raw", + * outputFormatSampleRate: 44100, + * outputFormatEncoding: "pcm_f32le" * } */ export interface VoiceChangerSseRequest { - "voice[id]": string; - "output_format[container]": Cartesia.OutputFormatContainer; - "output_format[sample_rate]": number; + voiceId: string; + outputFormatContainer: Cartesia.OutputFormatContainer; + outputFormatSampleRate: number; /** * Required for `raw` and `wav` containers. * */ - "output_format[encoding]"?: Cartesia.RawEncoding; + outputFormatEncoding?: Cartesia.RawEncoding; /** * Required for `mp3` containers. * */ - "output_format[bit_rate]"?: number; + outputFormatBitRate?: number; } diff --git a/src/api/resources/voices/client/Client.ts b/src/api/resources/voices/client/Client.ts index fce721b..9b0e4b1 100644 --- a/src/api/resources/voices/client/Client.ts +++ b/src/api/resources/voices/client/Client.ts @@ -6,6 +6,7 @@ import * as environments from "../../../../environments"; import * as core from "../../../../core"; import * as Cartesia from "../../../index"; import urlJoin from "url-join"; +import * as serializers from "../../../../serialization/index"; import * as errors from "../../../../errors/index"; import * as fs from "fs"; import { Blob } from "buffer"; @@ -64,7 +65,13 @@ export class Voices { abortSignal: requestOptions?.abortSignal, }); if (_response.ok) { - return _response.body as Cartesia.Voice[]; + return serializers.voices.list.Response.parseOrThrow(_response.body, { + unrecognizedObjectKeys: "passthrough", + allowUnrecognizedUnionMembers: true, + allowUnrecognizedEnumValues: true, + skipValidation: true, + breadcrumbsPrefix: ["response"], + }); } if (_response.error.reason === "status-code") { @@ -99,7 +106,7 @@ export class Voices { * description: "string", * embedding: [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], * language: "en", - * base_voice_id: "string" + * baseVoiceId: "string" * }) */ public async create( @@ -124,13 +131,19 @@ export class Voices { }, contentType: "application/json", requestType: "json", - body: request, + body: serializers.CreateVoiceRequest.jsonOrThrow(request, { unrecognizedObjectKeys: "strip" }), timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, }); if (_response.ok) { - return _response.body as Cartesia.Voice; + return serializers.Voice.parseOrThrow(_response.body, { + unrecognizedObjectKeys: "passthrough", + allowUnrecognizedUnionMembers: true, + allowUnrecognizedEnumValues: true, + skipValidation: true, + breadcrumbsPrefix: ["response"], + }); } if (_response.error.reason === "status-code") { @@ -166,7 +179,7 @@ export class Voices { const _response = await (this._options.fetcher ?? core.fetcher)({ url: urlJoin( (await core.Supplier.get(this._options.environment)) ?? environments.CartesiaEnvironment.Production, - `/voices/${encodeURIComponent(id)}` + `/voices/${encodeURIComponent(serializers.VoiceId.jsonOrThrow(id))}` ), method: "DELETE", headers: { @@ -230,7 +243,7 @@ export class Voices { const _response = await (this._options.fetcher ?? core.fetcher)({ url: urlJoin( (await core.Supplier.get(this._options.environment)) ?? environments.CartesiaEnvironment.Production, - `/voices/${encodeURIComponent(id)}` + `/voices/${encodeURIComponent(serializers.VoiceId.jsonOrThrow(id))}` ), method: "PATCH", headers: { @@ -245,13 +258,19 @@ export class Voices { }, contentType: "application/json", requestType: "json", - body: request, + body: serializers.UpdateVoiceRequest.jsonOrThrow(request, { unrecognizedObjectKeys: "strip" }), timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, }); if (_response.ok) { - return _response.body as Cartesia.Voice; + return serializers.Voice.parseOrThrow(_response.body, { + unrecognizedObjectKeys: "passthrough", + allowUnrecognizedUnionMembers: true, + allowUnrecognizedEnumValues: true, + skipValidation: true, + breadcrumbsPrefix: ["response"], + }); } if (_response.error.reason === "status-code") { @@ -287,7 +306,7 @@ export class Voices { const _response = await (this._options.fetcher ?? core.fetcher)({ url: urlJoin( (await core.Supplier.get(this._options.environment)) ?? environments.CartesiaEnvironment.Production, - `/voices/${encodeURIComponent(id)}` + `/voices/${encodeURIComponent(serializers.VoiceId.jsonOrThrow(id))}` ), method: "GET", headers: { @@ -307,7 +326,13 @@ export class Voices { abortSignal: requestOptions?.abortSignal, }); if (_response.ok) { - return _response.body as Cartesia.Voice; + return serializers.Voice.parseOrThrow(_response.body, { + unrecognizedObjectKeys: "passthrough", + allowUnrecognizedUnionMembers: true, + allowUnrecognizedEnumValues: true, + skipValidation: true, + breadcrumbsPrefix: ["response"], + }); } if (_response.error.reason === "status-code") { @@ -340,7 +365,7 @@ export class Voices { * await client.voices.localize({ * embedding: [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], * language: "en", - * original_speaker_gender: "male", + * originalSpeakerGender: "male", * dialect: "au" * }) */ @@ -366,13 +391,19 @@ export class Voices { }, contentType: "application/json", requestType: "json", - body: request, + body: serializers.LocalizeVoiceRequest.jsonOrThrow(request, { unrecognizedObjectKeys: "strip" }), timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, }); if (_response.ok) { - return _response.body as Cartesia.EmbeddingResponse; + return serializers.EmbeddingResponse.parseOrThrow(_response.body, { + unrecognizedObjectKeys: "passthrough", + allowUnrecognizedUnionMembers: true, + allowUnrecognizedEnumValues: true, + skipValidation: true, + breadcrumbsPrefix: ["response"], + }); } if (_response.error.reason === "status-code") { @@ -431,13 +462,19 @@ export class Voices { }, contentType: "application/json", requestType: "json", - body: request, + body: serializers.MixVoicesRequest.jsonOrThrow(request, { unrecognizedObjectKeys: "strip" }), timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, }); if (_response.ok) { - return _response.body as Cartesia.EmbeddingResponse; + return serializers.EmbeddingResponse.parseOrThrow(_response.body, { + unrecognizedObjectKeys: "passthrough", + allowUnrecognizedUnionMembers: true, + allowUnrecognizedEnumValues: true, + skipValidation: true, + breadcrumbsPrefix: ["response"], + }); } if (_response.error.reason === "status-code") { @@ -508,7 +545,13 @@ export class Voices { abortSignal: requestOptions?.abortSignal, }); if (_response.ok) { - return _response.body as Cartesia.EmbeddingResponse; + return serializers.EmbeddingResponse.parseOrThrow(_response.body, { + unrecognizedObjectKeys: "passthrough", + allowUnrecognizedUnionMembers: true, + allowUnrecognizedEnumValues: true, + skipValidation: true, + breadcrumbsPrefix: ["response"], + }); } if (_response.error.reason === "status-code") { diff --git a/src/api/resources/voices/types/CreateVoiceRequest.ts b/src/api/resources/voices/types/CreateVoiceRequest.ts index e51f9b6..71824f9 100644 --- a/src/api/resources/voices/types/CreateVoiceRequest.ts +++ b/src/api/resources/voices/types/CreateVoiceRequest.ts @@ -10,6 +10,6 @@ export interface CreateVoiceRequest { /** The description of the voice. */ description: string; embedding: Cartesia.Embedding; - language: Cartesia.SupportedLanguage; - base_voice_id?: Cartesia.BaseVoiceId; + language?: Cartesia.SupportedLanguage; + baseVoiceId?: Cartesia.BaseVoiceId; } diff --git a/src/api/resources/voices/types/LocalizeVoiceRequest.ts b/src/api/resources/voices/types/LocalizeVoiceRequest.ts index 529aed3..768e437 100644 --- a/src/api/resources/voices/types/LocalizeVoiceRequest.ts +++ b/src/api/resources/voices/types/LocalizeVoiceRequest.ts @@ -7,6 +7,6 @@ import * as Cartesia from "../../../index"; export interface LocalizeVoiceRequest { embedding: Cartesia.Embedding; language: Cartesia.LocalizeTargetLanguage; - original_speaker_gender: Cartesia.Gender; - dialect: Cartesia.LocalizeDialect; + originalSpeakerGender: Cartesia.Gender; + dialect?: Cartesia.LocalizeDialect; } diff --git a/src/api/resources/voices/types/Voice.ts b/src/api/resources/voices/types/Voice.ts index b582a53..523cde1 100644 --- a/src/api/resources/voices/types/Voice.ts +++ b/src/api/resources/voices/types/Voice.ts @@ -7,16 +7,16 @@ import * as Cartesia from "../../../index"; export interface Voice { id: Cartesia.VoiceId; /** The ID of the user who owns the voice. */ - user_id?: string; + userId?: string; /** Whether the voice is publicly accessible. */ - is_public: boolean; + isPublic: boolean; /** The name of the voice. */ name: string; /** The description of the voice. */ description: string; /** The date and time the voice was created. */ - created_at: string; + createdAt: Date; embedding: Cartesia.Embedding; language: Cartesia.SupportedLanguage; - base_voice_id?: Cartesia.BaseVoiceId; + baseVoiceId?: Cartesia.BaseVoiceId; } diff --git a/src/core/index.ts b/src/core/index.ts index 722f2e3..b6b4fe1 100644 --- a/src/core/index.ts +++ b/src/core/index.ts @@ -2,3 +2,4 @@ export * from "./fetcher"; export * from "./runtime"; export * from "./streaming-fetcher"; export * from "./form-data-utils"; +export * as serialization from "./schemas"; diff --git a/yarn.lock b/yarn.lock index c5586bb..d27bab1 100644 --- a/yarn.lock +++ b/yarn.lock @@ -663,11 +663,11 @@ form-data "^4.0.0" "@types/node@*": - version "22.9.1" - resolved "https://registry.yarnpkg.com/@types/node/-/node-22.9.1.tgz#bdf91c36e0e7ecfb7257b2d75bf1b206b308ca71" - integrity sha512-p8Yy/8sw1caA8CdRIQBG5tiLHmxtQKObCijiAa9Ez+d4+PRffM4054xbju0msf+cvhJpnFEeNjxmVT/0ipktrg== + version "22.10.0" + resolved "https://registry.yarnpkg.com/@types/node/-/node-22.10.0.tgz#89bfc9e82496b9c7edea3382583fa94f75896e81" + integrity sha512-XC70cRZVElFHfIUB40FgZOBbgJYFKKMa5nb9lxcwYstFG/Mi+/Y0bGS+rs6Dmhmkpq4pnNiLiuZAbc02YCOnmA== dependencies: - undici-types "~6.19.8" + undici-types "~6.20.0" "@types/node@17.0.33": version "17.0.33" @@ -1102,9 +1102,9 @@ camelcase@^6.2.0: integrity sha512-Gmy6FhYlCY7uOElZUSbxo2UCDH8owEk996gkbrpsgGtrJLM3J7jGxl9Ic7Qwwj4ivOE5AWZWRMecDdF7hqGjFA== caniuse-lite@^1.0.30001669: - version "1.0.30001680" - resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001680.tgz#5380ede637a33b9f9f1fc6045ea99bd142f3da5e" - integrity sha512-rPQy70G6AGUMnbwS1z6Xg+RkHYPAi18ihs47GH0jcxIG7wArmPgY3XbS2sRdBbxJljp3thdT8BIqv9ccCypiPA== + version "1.0.30001684" + resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001684.tgz#0eca437bab7d5f03452ff0ef9de8299be6b08e16" + integrity sha512-G1LRwLIQjBQoyq0ZJGqGIJUXzJ8irpbjHLpVRXDvBEScFJ9b17sgK6vlx0GAJFE21okD7zXl08rRRUfq6HdoEQ== chalk@^4.0.0, chalk@^4.1.0: version "4.1.2" @@ -1294,9 +1294,9 @@ domexception@^4.0.0: webidl-conversions "^7.0.0" electron-to-chromium@^1.5.41: - version "1.5.63" - resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.5.63.tgz#69444d592fbbe628d129866c2355691ea93eda3e" - integrity sha512-ddeXKuY9BHo/mw145axlyWjlJ1UBt4WK3AlvkT7W2AbqfRQoacVoRUCF6wL3uIx/8wT9oLKXzI+rFqHHscByaA== + version "1.5.65" + resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.5.65.tgz#e2b9d84d31e187a847e3ccdcfb415ddd4a3d1ea7" + integrity sha512-PWVzBjghx7/wop6n22vS2MLU8tKGd4Q91aCEGhG/TYmW6PP5OcSXcdnxTe1NNt0T66N8D6jxh4kC8UsdzOGaIw== emittery@^0.13.1: version "0.13.1" @@ -2544,9 +2544,9 @@ prompts@^2.0.1: sisteransi "^1.0.5" psl@^1.1.33: - version "1.10.0" - resolved "https://registry.yarnpkg.com/psl/-/psl-1.10.0.tgz#1450f7e16f922c3beeb7bd9db3f312635018fa15" - integrity sha512-KSKHEbjAnpUuAUserOq0FxGXCUrzC3WniuSJhvdbs102rL55266ZcHBqLWOsG30spQMlPdpy7icATiAQehg/iA== + version "1.13.0" + resolved "https://registry.yarnpkg.com/psl/-/psl-1.13.0.tgz#8b2357f13ef3cf546af3f52de00543a94da86cfa" + integrity sha512-BFwmFXiJoFqlUpZ5Qssolv15DMyc84gTBds1BjsV1BfXEo1UyyD7GsmN67n7J77uRhoSNW1AXtXKPLcBFQn9Aw== dependencies: punycode "^2.3.1" @@ -2962,10 +2962,10 @@ typescript@4.6.4: resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.6.4.tgz#caa78bbc3a59e6a5c510d35703f6a09877ce45e9" integrity sha512-9ia/jWHIEbo49HfjrLGfKbZSuWo9iTMwXO+Ca3pRsSpbsMbc7/IU8NKdCZVRRBafVPGnoJeFL76ZOAA84I9fEg== -undici-types@~6.19.8: - version "6.19.8" - resolved "https://registry.yarnpkg.com/undici-types/-/undici-types-6.19.8.tgz#35111c9d1437ab83a7cdc0abae2f26d88eda0a02" - integrity sha512-ve2KP6f/JnbPBFyobGHuerC9g1FYGn/F8n1LWTwNxCEzd6IfqTwUQcNXgEtmmQ6DlRrC1hrSrBnCZPokRrDHjw== +undici-types@~6.20.0: + version "6.20.0" + resolved "https://registry.yarnpkg.com/undici-types/-/undici-types-6.20.0.tgz#8171bf22c1f588d1554d55bf204bc624af388433" + integrity sha512-Ny6QZ2Nju20vw1SRHe3d9jVu6gJ+4e3+MMpqu7pqE5HT6WsTSlce++GQmK5UXS8mzV8DSYHrQH+Xrf2jVcuKNg== universalify@^0.2.0: version "0.2.0"