@cartesia/cartesia-js 1.0.1 → 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,41 +1,48 @@
1
1
  import { Client } from "../lib/client";
2
- import type { CloneOptions, CloneResponse, CreateVoice, Voice } from "../types";
2
+ import type {
3
+ CloneOptions,
4
+ CloneResponse,
5
+ CreateVoice,
6
+ UpdateVoice,
7
+ Voice,
8
+ } from "../types";
3
9
 
4
10
  export default class Voices extends Client {
5
11
  async list(): Promise<Voice[]> {
6
- const response = await this.fetch("/voices");
12
+ const response = await this._fetch("/voices");
7
13
  return response.json();
8
14
  }
9
15
 
10
16
  async get(voiceId: string): Promise<Voice> {
11
- const response = await this.fetch(`/voices/${voiceId}`);
17
+ const response = await this._fetch(`/voices/${voiceId}`);
12
18
  return response.json();
13
19
  }
14
20
 
15
21
  async create(voice: CreateVoice): Promise<Voice> {
16
- const response = await this.fetch("/voices", {
22
+ const response = await this._fetch("/voices", {
17
23
  method: "POST",
18
24
  body: JSON.stringify(voice),
19
25
  });
20
26
  return response.json() as Promise<Voice>;
21
27
  }
22
28
 
23
- async clone(options: CloneOptions): Promise<CloneResponse> {
24
- if (options.mode === "url") {
25
- const response = await this.fetch(
26
- `/voices/clone/url?link=${options.link}`,
27
- {
28
- method: "POST",
29
- },
30
- );
31
- return response.json();
32
- }
29
+ async update(id: string, voice: UpdateVoice): Promise<Voice> {
30
+ const response = await this._fetch(`/voices/${id}`, {
31
+ method: "PATCH",
32
+ body: JSON.stringify(voice),
33
+ });
34
+ return response.json() as Promise<Voice>;
35
+ }
33
36
 
37
+ async clone(options: CloneOptions): Promise<CloneResponse> {
34
38
  if (options.mode === "clip") {
35
39
  const formData = new FormData();
36
40
  formData.append("clip", options.clip);
41
+ if (options.enhance !== undefined) {
42
+ formData.append("enhance", options.enhance.toString());
43
+ }
37
44
 
38
- const response = await this.fetch("/voices/clone/clip", {
45
+ const response = await this._fetch("/voices/clone/clip", {
39
46
  method: "POST",
40
47
  body: formData,
41
48
  });
@@ -1,34 +0,0 @@
1
- import {
2
- BASE_URL,
3
- CARTESIA_VERSION,
4
- constructApiUrl
5
- } from "./chunk-2BFEKY3F.js";
6
- import {
7
- __spreadProps,
8
- __spreadValues
9
- } from "./chunk-GHY2WEOK.js";
10
-
11
- // src/lib/client.ts
12
- import fetch from "cross-fetch";
13
- var Client = class {
14
- constructor(options = {}) {
15
- if (!(options.apiKey || process.env.CARTESIA_API_KEY)) {
16
- throw new Error("Missing Cartesia API key.");
17
- }
18
- this.apiKey = options.apiKey || process.env.CARTESIA_API_KEY;
19
- this.baseUrl = options.baseUrl || BASE_URL;
20
- }
21
- fetch(path, options = {}) {
22
- const url = constructApiUrl(this.baseUrl, path);
23
- return fetch(url.toString(), __spreadProps(__spreadValues({}, options), {
24
- headers: __spreadValues({
25
- "X-API-Key": this.apiKey,
26
- "Cartesia-Version": CARTESIA_VERSION
27
- }, options.headers)
28
- }));
29
- }
30
- };
31
-
32
- export {
33
- Client
34
- };