cartesia 0.0.1

A Rust library for the Cartesia API.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
openapi: 3.0.0

info:
  title: Cartesia REST API
  version: "2024-06-10"

servers:
  - url: "https://api.cartesia.ai"

security:
  - APIKeyHeader: []

paths:
  "/tts/bytes":
    post:
      summary: Stream Speech (Bytes)
      description: |-
        Generate audio from a transcript using a given voice and model. The audio is streamed out as raw bytes.
      parameters:
        - $ref: "#/components/parameters/Cartesia-Version"
      requestBody:
        $ref: "#/components/requestBodies/TTSRequest"
      responses:
        "200":
          description: A stream of audio data.
          content:
            application/octet-stream:
              schema:
                type: string
                format: binary
                description: Binary audio data. The underlying bytes will be in the requested output format.
        default:
          $ref: "#/components/responses/Error"
  "/tts/sse":
    post:
      summary: Stream Speech (Server-Sent Events)
      description: |-
        Generate audio from a transcript using a given voice and model. The audio is streamed out as Server-Sent Events.
      parameters:
        - $ref: "#/components/parameters/Cartesia-Version"
      requestBody:
        $ref: "#/components/requestBodies/TTSRequest"
      responses:
        "200":
          description: A stream of audio data.
          content:
            text/event-stream:
              schema:
                oneOf:
                  - $ref: "#/components/schemas/JSONChunkResponse"
                  - $ref: "#/components/schemas/JSONDoneResponse"
                  - $ref: "#/components/schemas/JSONErrorResponse"
                discriminator:
                  propertyName: status_code
        default:
          $ref: "#/components/responses/Error"

  "/voices":
    get:
      summary: List Voices
      description: |-
        List all voices available to the user, that is, public voices and the user's own voices.
      parameters:
        - $ref: "#/components/parameters/Cartesia-Version"
      responses:
        "200":
          description: List of voices.
          content:
            application/json:
              schema:
                title: Voice List
                type: array
                items:
                  $ref: "#/components/schemas/Voice"
    post:
      summary: Create Voice
      description: |-
        Create a new voice with a given name, description, and embedding.
      parameters:
        - $ref: "#/components/parameters/Cartesia-Version"
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required:
                - name
                - description
                - embedding
              properties:
                name:
                  "$ref": "#/components/schemas/VoiceName"
                description:
                  "$ref": "#/components/schemas/VoiceDescription"
                embedding:
                  "$ref": "#/components/schemas/VoiceEmbedding"
      responses:
        "201":
          description: The created voice.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Voice"
        default:
          $ref: "#/components/responses/Error"

  "/voices/{id}":
    get:
      summary: Get Voice
      parameters:
        - $ref: "#/components/parameters/Cartesia-Version"
        - in: path
          name: id
          required: true
          schema:
            "$ref": "#/components/schemas/VoiceId"
      responses:
        "200":
          description: The voice.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Voice"
        default:
          $ref: "#/components/responses/Error"
    delete:
      summary: Delete Voice
      parameters:
        - $ref: "#/components/parameters/Cartesia-Version"
        - in: path
          name: id
          required: true
          schema:
            "$ref": "#/components/schemas/VoiceId"
      responses:
        "204":
          description: Voice deleted.
        default:
          $ref: "#/components/responses/Error"

  "/voices/clone/clip":
    post:
      summary: Clone Voice (Clip)
      description: |-
        Clones a voice from an audio clip uploaded as a file. The clip is uploaded using multipart/form-data with a `clip` field containing the audio file.
      operationId: clone_voice_from_clip
      parameters:
        - $ref: "#/components/parameters/Cartesia-Version"
      requestBody:
        required: true
        content:
          multipart/form-data:
            schema:
              type: object
              properties:
                clip:
                  type: string
                  format: binary
      responses:
        "200":
          $ref: "#/components/responses/VoiceEmbeddingResponse"
        default:
          $ref: "#/components/responses/Error"

  "/voices/clone/url":
    post:
      summary: Clone Voice (URL)
      description: |-
        Clone a voice from an online URL. Currently only supports YouTube.
      parameters:
        - $ref: "#/components/parameters/Cartesia-Version"
        - required: true
          schema:
            type: string
            title: Link
            description: The URL of the video to clone the voice from.
            example: "https://www.youtube.com/watch?v=dQw4w9WgXcQ"
          name: link
          in: query
      responses:
        "200":
          $ref: "#/components/responses/VoiceEmbeddingResponse"
        default:
          $ref: "#/components/responses/Error"

  "/":
    get:
      security: []
      summary: API Status and Version
      description: Returns the server's version and a status message which can be useful for sanity checking.
      responses:
        "200":
          description: Everything OK.
          content:
            application/json:
              schema:
                type: object
                properties:
                  version:
                    type: string
                    title: version
                  status:
                    type: boolean
                    title: ok
        default:
          $ref: "#/components/responses/Error"

components:
  securitySchemes:
    APIKeyHeader:
      type: apiKey
      in: header
      name: X-API-Key

  parameters:
    Cartesia-Version:
      in: header
      name: Cartesia-Version
      description: The version of the Cartesia API to use.
      required: true
      schema:
        type: string
      example: "2024-06-10"

  requestBodies:
    TTSRequest:
      required: true
      content:
        application/json:
          schema:
            title: TTS Request
            type: object
            required:
              - model_id
              - transcript
              - voice
              - output_format
            properties:
              model_id:
                title: Model ID
                type: string
                example: sonic-english
              transcript:
                title: Transcript
                type: string
                example: "Hello, world! I'm generating audio on Cartesia."
              duration:
                title: Duration
                description: The maximum duration of the audio in seconds.
                type: integer
              voice:
                title: Voice
                description: The voice to use for the speech. Can be either an ID or an embedding, specified by the `mode` field.
                oneOf:
                  - type: object
                    properties:
                      mode:
                        type: string
                        enum: [id]
                      id:
                        "$ref": "#/components/schemas/VoiceId"
                    example:
                      mode: "id"
                      id: &voiceID "a0e99841-438c-4a64-b679-ae501e7d6091"
                  - type: object
                    properties:
                      mode:
                        type: string
                        enum: [embedding]
                      embedding:
                        "$ref": "#/components/schemas/VoiceEmbedding"
                    example:
                      mode: "embedding"
                      embedding:
                        &voiceEmbedding [
                          -0.033633083,
                          0.072083704,
                          -0.01807767,
                          -0.083488315,
                          -0.04407617,
                          0.0022592682,
                          0.070505895,
                          0.023946615,
                          -0.04788024,
                          -0.06388413,
                          -0.0716355,
                          -0.0022612812,
                          -0.0053448505,
                          -0.07848381,
                          0.0348162,
                          -0.053745482,
                          -0.092399485,
                          -0.02950225,
                          0.028591828,
                          -0.10556894,
                          0.023313355,
                          0.06224387,
                          0.0362463,
                          0.029258432,
                          0.10769641,
                          0.043595582,
                          -0.058543224,
                          -0.080402784,
                          -0.0953816,
                          -0.008988032,
                          -0.0028981369,
                          -0.004752721,
                          -0.20742874,
                          0.058907595,
                          0.08813939,
                          -0.06192675,
                          0.099082634,
                          -0.09661578,
                          -0.0077761724,
                          -0.013982456,
                          -0.025798267,
                          0.04467142,
                          0.026222011,
                          0.023023574,
                          0.011227064,
                          -0.17462021,
                          -0.09880612,
                          -0.1521035,
                          -0.060464993,
                          -0.04735665,
                          -0.09725187,
                          -0.006127679,
                          0.15818526,
                          -0.039493002,
                          -0.067719474,
                          0.0066190436,
                          -0.10636633,
                          0.17073768,
                          -0.051717706,
                          0.03186961,
                          -0.020547207,
                          -0.02244247,
                          0.013196935,
                          -0.06431055,
                          -0.115360335,
                          0.016918058,
                          -0.033195216,
                          0.11255181,
                          0.020366343,
                          -0.041032124,
                          0.08780918,
                          -0.040567942,
                          0.057276532,
                          0.05848221,
                          -0.077479474,
                          -0.073524915,
                          -0.01913317,
                          -0.029291833,
                          0.11210393,
                          -0.09859328,
                          0.2152541,
                          -0.022976823,
                          0.028627992,
                          -0.039598297,
                          0.041829932,
                          -0.05593181,
                          -0.06444655,
                          -0.018057477,
                          -0.008098263,
                          0.05994528,
                          0.10430693,
                          -0.13121894,
                          -0.06512868,
                          -0.026126215,
                          0.046727825,
                          -0.17180993,
                          -0.10577226,
                          -0.08610466,
                          0.008862588,
                          0.09547498,
                          -0.010965332,
                          -0.061217085,
                          -0.038954042,
                          0.019930292,
                          -0.017192135,
                          0.007296275,
                          0.03273872,
                          0.04389937,
                          -0.056483064,
                          0.003420891,
                          -0.10319067,
                          -0.015706042,
                          0.1308774,
                          -0.0018035866,
                          -0.03582506,
                          0.077131025,
                          0.013398928,
                          0.003188886,
                          0.12039741,
                          -0.033974767,
                          0.06899378,
                          -0.059775922,
                          -0.026934423,
                          0.028482193,
                          0.100996524,
                          0.004498743,
                          -0.02291186,
                          0.078752205,
                          -0.0063796206,
                          0.04206536,
                          0.05721349,
                          0.06290694,
                          0.06130212,
                          0.096969016,
                          -0.057664312,
                          -0.16727506,
                          -0.035220966,
                          0.090760484,
                          0.010039947,
                          0.06513242,
                          0.011055657,
                          -0.004258431,
                          -0.08316792,
                          -0.15650468,
                          -0.076931365,
                          0.11385587,
                          -0.038372636,
                          0.015648656,
                          -0.12029895,
                          -0.06604956,
                          0.009441591,
                          -0.11912808,
                          0.013378132,
                          0.029525978,
                          -0.0056742397,
                          -0.0075976513,
                          0.019999338,
                          -0.05521377,
                          -0.07650746,
                          -0.017710293,
                          -0.033986397,
                          -0.047768556,
                          0.13857274,
                          0.099290825,
                          0.11736938,
                          0.017834296,
                          -0.07140237,
                          -0.052047748,
                          -0.06398965,
                          -0.037033975,
                          -0.061061256,
                          -0.03330076,
                          -0.024472248,
                          -0.059656,
                          0.05359946,
                          -0.043915518,
                          -0.086325996,
                          0.14189173,
                          0.021086395,
                          0.02945159,
                          0.1029604,
                          0.018490415,
                          -0.028736332,
                          -0.025272416,
                          -0.06082937,
                          -0.031339463,
                          -0.0007249595,
                          0.025595888,
                          0.007144545,
                          -0.16938712,
                          -0.1160664,
                          -0.0654145,
                        ]
                discriminator:
                  propertyName: mode
              output_format:
                title: Output Format
                type: object
                required: [container, encoding, sample_rate]
                properties:
                  container:
                    type: string
                    enum: ["raw"]
                  encoding:
                    type: string
                    enum: ["pcm_s16le", "pcm_f32le", "pcm_mulaw", "pcm_alaw"]
                  sample_rate:
                    type: integer
                    enum: [8000, 16000, 22050, 24000, 44100]
              language:
                title: Language
                type: string
                enum: ["en", "es", "fr", "de", "pt", "zh", "ja"]
                example: "en"

  responses:
    Error:
      description: An error response.
      content:
        text/plain:
          schema:
            title: Error Description
            type: string
            example: error in voice

    VoiceEmbeddingResponse:
      description: The voice embedding.
      content:
        application/json:
          schema:
            title: Voice Embedding
            properties:
              embedding:
                "$ref": "#/components/schemas/VoiceEmbedding"
            type: object
            required:
              - embedding

  schemas:
    Timestamp:
      title: Timestamp
      type: string

    Voice:
      type: object
      properties:
        id:
          "$ref": "#/components/schemas/VoiceId"
        user_id:
          type: string
        is_public:
          type: boolean
        name:
          "$ref": "#/components/schemas/VoiceName"
        description:
          "$ref": "#/components/schemas/VoiceDescription"
        created_at:
          "$ref": "#/components/schemas/Timestamp"
        embedding:
          "$ref": "#/components/schemas/VoiceEmbedding"
      required:
        - id
        - user_id
        - is_public
        - name
        - description
        - created_at
        - embedding

    VoiceDescription:
      title: Voice Description
      type: string
      example: "A deep, rich, male voice with an Indian accent."

    VoiceId:
      title: Voice ID
      type: string
      example: *voiceID

    VoiceEmbedding:
      title: Voice Embedding
      items:
        type: number
      type: array
      example: *voiceEmbedding

    VoiceName:
      title: VoiceName
      type: string
      example: "Barbershop Man"

    Clip:
      title: Clip
      type: string
      format: binary

    JSONBaseResponse:
      title: JSON Base Response
      type: object
      properties:
        status_code: &statusCode
          title: Status Code
          type: integer
          description: HTTP status code to allow for error handling. This is for errors encountered while streaming the response.
        done: &done
          title: Done
          type: boolean
          description: Whether the model has finished generating audio.

    JSONChunkResponse:
      title: JSON Chunk Response
      type: object
      allOf:
        - "$ref": "#/components/schemas/JSONBaseResponse"
        - type: object
          properties:
            status_code:
              <<: *statusCode
              enum: [206]
            done:
              <<: *done
              enum: [false]
            data:
              title: Data
              type: string
              format: byte
              description: Binary audio data encoded as base64. The underlying bytes will be in the requested output format.
            step_time:
              title: Step Time
              type: integer
              description: The time in milliseconds that the model took to generate this chunk of audio.

    JSONDoneResponse:
      title: JSON Done Response
      type: object
      allOf:
        - "$ref": "#/components/schemas/JSONBaseResponse"
        - type: object
          properties:
            status_code:
              <<: *statusCode
              enum: [200]
            done:
              <<: *done
              enum: [true]

    JSONErrorResponse:
      title: JSON Error Response
      type: object
      allOf:
        - "$ref": "#/components/schemas/JSONBaseResponse"
        - type: object
          properties:
            status_code:
              <<: *statusCode
              minimum: 400
              maximum: 599
            done:
              <<: *done
              enum: [true]
            error:
              title: Error
              type: string
              description: A human-readable error message.