@ai-sdk/cartesia 0.0.1 → 3.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.
- package/CHANGELOG.md +23 -0
- package/LICENSE +13 -0
- package/README.md +47 -0
- package/dist/index.d.ts +185 -0
- package/dist/index.js +724 -0
- package/dist/index.js.map +1 -0
- package/docs/95-cartesia.mdx +262 -0
- package/package.json +69 -7
- package/src/cartesia-api-types.ts +17 -0
- package/src/cartesia-config.ts +9 -0
- package/src/cartesia-error.ts +17 -0
- package/src/cartesia-provider.ts +190 -0
- package/src/cartesia-realtime-model-options.ts +3 -0
- package/src/cartesia-realtime-model.ts +326 -0
- package/src/cartesia-speech-api-types.ts +64 -0
- package/src/cartesia-speech-model-options.ts +40 -0
- package/src/cartesia-speech-model.ts +285 -0
- package/src/cartesia-speech-options.ts +9 -0
- package/src/cartesia-transcription-model-options.ts +13 -0
- package/src/cartesia-transcription-model.ts +157 -0
- package/src/cartesia-transcription-options.ts +1 -0
- package/src/index.ts +20 -0
- package/src/transcript-test.mp3 +0 -0
- package/src/version.ts +6 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# @ai-sdk/cartesia
|
|
2
|
+
|
|
3
|
+
## 3.0.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies [4be62c1]
|
|
8
|
+
- Updated dependencies [7805e4a]
|
|
9
|
+
- Updated dependencies [cd12954]
|
|
10
|
+
- @ai-sdk/provider-utils@5.0.9
|
|
11
|
+
|
|
12
|
+
## 3.0.1
|
|
13
|
+
|
|
14
|
+
### Patch Changes
|
|
15
|
+
|
|
16
|
+
- Updated dependencies [e193290]
|
|
17
|
+
- @ai-sdk/provider-utils@5.0.8
|
|
18
|
+
|
|
19
|
+
## 3.0.0
|
|
20
|
+
|
|
21
|
+
### Major Changes
|
|
22
|
+
|
|
23
|
+
- 8f89c25: Add the Cartesia provider with Sonic 3.5 speech generation, Ink-Whisper batch transcription, and Ink 2 realtime transcription support.
|
package/LICENSE
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
Copyright 2023 Vercel, Inc.
|
|
2
|
+
|
|
3
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
you may not use this file except in compliance with the License.
|
|
5
|
+
You may obtain a copy of the License at
|
|
6
|
+
|
|
7
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
|
|
9
|
+
Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
See the License for the specific language governing permissions and
|
|
13
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
# AI SDK - Cartesia Provider
|
|
2
|
+
|
|
3
|
+
The **[Cartesia provider](https://ai-sdk.dev/providers/ai-sdk-providers/cartesia)** for the [AI SDK](https://ai-sdk.dev/docs)
|
|
4
|
+
contains Sonic 3.5 speech generation, Ink-Whisper batch transcription, and Ink 2 realtime transcription support.
|
|
5
|
+
|
|
6
|
+
> **Deploying to Vercel?** With Vercel's AI Gateway you can access Cartesia (and hundreds of models from other providers) — no additional packages, API keys, or extra cost. [Get started with AI Gateway](https://vercel.com/ai-gateway).
|
|
7
|
+
|
|
8
|
+
## Setup
|
|
9
|
+
|
|
10
|
+
The Cartesia provider is available in the `@ai-sdk/cartesia` module. You can install it with
|
|
11
|
+
|
|
12
|
+
```bash
|
|
13
|
+
npm i @ai-sdk/cartesia
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
## Skill for Coding Agents
|
|
17
|
+
|
|
18
|
+
If you use coding agents such as Claude Code or Cursor, we highly recommend adding the AI SDK skill to your repository:
|
|
19
|
+
|
|
20
|
+
```shell
|
|
21
|
+
npx skills add vercel/ai
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
## Provider Instance
|
|
25
|
+
|
|
26
|
+
You can import the default provider instance `cartesia` from `@ai-sdk/cartesia`:
|
|
27
|
+
|
|
28
|
+
```ts
|
|
29
|
+
import { cartesia } from '@ai-sdk/cartesia';
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## Example
|
|
33
|
+
|
|
34
|
+
```ts
|
|
35
|
+
import { cartesia } from '@ai-sdk/cartesia';
|
|
36
|
+
import { generateSpeech } from 'ai';
|
|
37
|
+
|
|
38
|
+
const { audio } = await generateSpeech({
|
|
39
|
+
model: cartesia.speech('sonic-3.5'),
|
|
40
|
+
text: 'Hello from the Vercel AI SDK!',
|
|
41
|
+
voice: 'a0e99841-438c-4a64-b679-ae501e7d6091',
|
|
42
|
+
});
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
## Documentation
|
|
46
|
+
|
|
47
|
+
Please check out the **[Cartesia provider documentation](https://ai-sdk.dev/providers/ai-sdk-providers/cartesia)** for more information.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
import * as _ai_sdk_provider from '@ai-sdk/provider';
|
|
2
|
+
import { SpeechModelV4, ProviderV4, TranscriptionModelV4, Experimental_RealtimeFactoryV4, Experimental_RealtimeModelV4, Experimental_RealtimeModelV4ClientSecretOptions, Experimental_RealtimeModelV4ClientSecretResult, Experimental_RealtimeModelV4ServerEvent, Experimental_RealtimeModelV4ClientEvent, Experimental_RealtimeModelV4SessionConfig } from '@ai-sdk/provider';
|
|
3
|
+
import { FetchFunction, WORKFLOW_SERIALIZE, WORKFLOW_DESERIALIZE } from '@ai-sdk/provider-utils';
|
|
4
|
+
import { z } from 'zod/v4';
|
|
5
|
+
|
|
6
|
+
type CartesiaTranscriptionModelId = 'ink-whisper' | (string & {});
|
|
7
|
+
|
|
8
|
+
type CartesiaConfig = {
|
|
9
|
+
provider: string;
|
|
10
|
+
url: (options: {
|
|
11
|
+
modelId: string;
|
|
12
|
+
path: string;
|
|
13
|
+
}) => string;
|
|
14
|
+
headers?: () => Record<string, string | undefined>;
|
|
15
|
+
fetch?: FetchFunction;
|
|
16
|
+
generateId?: () => string;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
type CartesiaSpeechModelId = 'sonic-3.5' | 'sonic-3' | 'sonic-2' | 'sonic-turbo' | 'sonic-latest' | (string & {});
|
|
20
|
+
type CartesiaSpeechVoiceId = string;
|
|
21
|
+
|
|
22
|
+
interface CartesiaSpeechModelConfig extends CartesiaConfig {
|
|
23
|
+
_internal?: {
|
|
24
|
+
currentDate?: () => Date;
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
declare class CartesiaSpeechModel implements SpeechModelV4 {
|
|
28
|
+
readonly modelId: CartesiaSpeechModelId;
|
|
29
|
+
private readonly config;
|
|
30
|
+
readonly specificationVersion = "v4";
|
|
31
|
+
get provider(): string;
|
|
32
|
+
static [WORKFLOW_SERIALIZE](model: CartesiaSpeechModel): {
|
|
33
|
+
modelId: string;
|
|
34
|
+
config: _ai_sdk_provider.JSONObject;
|
|
35
|
+
};
|
|
36
|
+
static [WORKFLOW_DESERIALIZE](options: {
|
|
37
|
+
modelId: CartesiaSpeechModelId;
|
|
38
|
+
config: CartesiaSpeechModelConfig;
|
|
39
|
+
}): CartesiaSpeechModel;
|
|
40
|
+
constructor(modelId: CartesiaSpeechModelId, config: CartesiaSpeechModelConfig);
|
|
41
|
+
private getArgs;
|
|
42
|
+
doGenerate(options: Parameters<SpeechModelV4['doGenerate']>[0]): Promise<Awaited<ReturnType<SpeechModelV4['doGenerate']>>>;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
interface CartesiaProvider extends ProviderV4 {
|
|
46
|
+
(modelId: CartesiaSpeechModelId, settings?: {}): {
|
|
47
|
+
speech: CartesiaSpeechModel;
|
|
48
|
+
};
|
|
49
|
+
/**
|
|
50
|
+
* Creates a model for transcription.
|
|
51
|
+
*/
|
|
52
|
+
transcription(modelId: CartesiaTranscriptionModelId): TranscriptionModelV4;
|
|
53
|
+
/**
|
|
54
|
+
* Creates a model for speech generation.
|
|
55
|
+
*/
|
|
56
|
+
speech(modelId: CartesiaSpeechModelId): SpeechModelV4;
|
|
57
|
+
/**
|
|
58
|
+
* Creates a realtime Ink speech-to-text model.
|
|
59
|
+
*/
|
|
60
|
+
experimental_realtime: Experimental_RealtimeFactoryV4;
|
|
61
|
+
/**
|
|
62
|
+
* @deprecated Use `embeddingModel` instead.
|
|
63
|
+
*/
|
|
64
|
+
textEmbeddingModel(modelId: string): never;
|
|
65
|
+
}
|
|
66
|
+
interface CartesiaProviderSettings {
|
|
67
|
+
/**
|
|
68
|
+
* API key for authenticating requests.
|
|
69
|
+
*/
|
|
70
|
+
apiKey?: string;
|
|
71
|
+
/**
|
|
72
|
+
* The Cartesia API version to use (sent via the `Cartesia-Version` header).
|
|
73
|
+
*/
|
|
74
|
+
version?: string;
|
|
75
|
+
/**
|
|
76
|
+
* Custom headers to include in the requests.
|
|
77
|
+
*/
|
|
78
|
+
headers?: Record<string, string>;
|
|
79
|
+
/**
|
|
80
|
+
* Custom fetch implementation. You can use it as a middleware to intercept requests,
|
|
81
|
+
* or to provide a custom fetch implementation for e.g. testing.
|
|
82
|
+
*/
|
|
83
|
+
fetch?: FetchFunction;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Create a Cartesia provider instance.
|
|
87
|
+
*/
|
|
88
|
+
declare function createCartesia(options?: CartesiaProviderSettings): CartesiaProvider;
|
|
89
|
+
/**
|
|
90
|
+
* Default Cartesia provider instance.
|
|
91
|
+
*/
|
|
92
|
+
declare const cartesia: CartesiaProvider;
|
|
93
|
+
|
|
94
|
+
interface CartesiaTranscriptionModelConfig extends CartesiaConfig {
|
|
95
|
+
_internal?: {
|
|
96
|
+
currentDate?: () => Date;
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
declare class CartesiaTranscriptionModel implements TranscriptionModelV4 {
|
|
100
|
+
readonly modelId: CartesiaTranscriptionModelId;
|
|
101
|
+
private readonly config;
|
|
102
|
+
readonly specificationVersion = "v4";
|
|
103
|
+
get provider(): string;
|
|
104
|
+
static [WORKFLOW_SERIALIZE](model: CartesiaTranscriptionModel): {
|
|
105
|
+
modelId: string;
|
|
106
|
+
config: _ai_sdk_provider.JSONObject;
|
|
107
|
+
};
|
|
108
|
+
static [WORKFLOW_DESERIALIZE](options: {
|
|
109
|
+
modelId: CartesiaTranscriptionModelId;
|
|
110
|
+
config: CartesiaTranscriptionModelConfig;
|
|
111
|
+
}): CartesiaTranscriptionModel;
|
|
112
|
+
constructor(modelId: CartesiaTranscriptionModelId, config: CartesiaTranscriptionModelConfig);
|
|
113
|
+
private getArgs;
|
|
114
|
+
doGenerate(options: Parameters<TranscriptionModelV4['doGenerate']>[0]): Promise<Awaited<ReturnType<TranscriptionModelV4['doGenerate']>>>;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
type CartesiaRealtimeModelId = 'ink-2' | (string & {});
|
|
118
|
+
type CartesiaRealtimeModelOptions = Record<string, never>;
|
|
119
|
+
|
|
120
|
+
type CartesiaRealtimeModelConfig = {
|
|
121
|
+
provider: string;
|
|
122
|
+
baseURL: string;
|
|
123
|
+
version: string;
|
|
124
|
+
headers: () => Record<string, string | undefined>;
|
|
125
|
+
fetch?: FetchFunction;
|
|
126
|
+
_internal?: {
|
|
127
|
+
currentDate?: () => Date;
|
|
128
|
+
};
|
|
129
|
+
};
|
|
130
|
+
/**
|
|
131
|
+
* Realtime Ink model using Cartesia's STT WebSocket APIs.
|
|
132
|
+
*/
|
|
133
|
+
declare class CartesiaRealtimeModel implements Experimental_RealtimeModelV4 {
|
|
134
|
+
readonly specificationVersion: "v4";
|
|
135
|
+
readonly provider: string;
|
|
136
|
+
readonly modelId: CartesiaRealtimeModelId;
|
|
137
|
+
private readonly config;
|
|
138
|
+
private manualTranscript;
|
|
139
|
+
private sessionCreated;
|
|
140
|
+
private useTurnDetection;
|
|
141
|
+
constructor(modelId: CartesiaRealtimeModelId, config: CartesiaRealtimeModelConfig);
|
|
142
|
+
doCreateClientSecret(options: Experimental_RealtimeModelV4ClientSecretOptions): Promise<Experimental_RealtimeModelV4ClientSecretResult>;
|
|
143
|
+
getWebSocketConfig(options: {
|
|
144
|
+
token: string;
|
|
145
|
+
url: string;
|
|
146
|
+
}): {
|
|
147
|
+
url: string;
|
|
148
|
+
};
|
|
149
|
+
parseServerEvent(raw: unknown): Experimental_RealtimeModelV4ServerEvent | Experimental_RealtimeModelV4ServerEvent[];
|
|
150
|
+
serializeClientEvent(event: Experimental_RealtimeModelV4ClientEvent): unknown;
|
|
151
|
+
buildSessionConfig(_config: Experimental_RealtimeModelV4SessionConfig): null;
|
|
152
|
+
private finishManualTranscript;
|
|
153
|
+
private withSessionCreated;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
declare const cartesiaSpeechModelOptionsSchema: z.ZodObject<{
|
|
157
|
+
container: z.ZodOptional<z.ZodNullable<z.ZodEnum<{
|
|
158
|
+
raw: "raw";
|
|
159
|
+
wav: "wav";
|
|
160
|
+
mp3: "mp3";
|
|
161
|
+
}>>>;
|
|
162
|
+
encoding: z.ZodOptional<z.ZodNullable<z.ZodEnum<{
|
|
163
|
+
pcm_f32le: "pcm_f32le";
|
|
164
|
+
pcm_s16le: "pcm_s16le";
|
|
165
|
+
pcm_mulaw: "pcm_mulaw";
|
|
166
|
+
pcm_alaw: "pcm_alaw";
|
|
167
|
+
}>>>;
|
|
168
|
+
sampleRate: z.ZodOptional<z.ZodNullable<z.ZodUnion<readonly [z.ZodLiteral<8000>, z.ZodLiteral<16000>, z.ZodLiteral<22050>, z.ZodLiteral<24000>, z.ZodLiteral<44100>, z.ZodLiteral<48000>]>>>;
|
|
169
|
+
bitRate: z.ZodOptional<z.ZodNullable<z.ZodUnion<readonly [z.ZodLiteral<32000>, z.ZodLiteral<64000>, z.ZodLiteral<96000>, z.ZodLiteral<128000>, z.ZodLiteral<192000>]>>>;
|
|
170
|
+
speed: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
|
|
171
|
+
language: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
172
|
+
}, z.core.$strip>;
|
|
173
|
+
type CartesiaSpeechModelOptions = z.infer<typeof cartesiaSpeechModelOptionsSchema>;
|
|
174
|
+
|
|
175
|
+
declare const cartesiaTranscriptionModelOptionsSchema: z.ZodObject<{
|
|
176
|
+
language: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
177
|
+
timestampGranularities: z.ZodOptional<z.ZodNullable<z.ZodArray<z.ZodEnum<{
|
|
178
|
+
word: "word";
|
|
179
|
+
}>>>>;
|
|
180
|
+
}, z.core.$strip>;
|
|
181
|
+
type CartesiaTranscriptionModelOptions = z.infer<typeof cartesiaTranscriptionModelOptionsSchema>;
|
|
182
|
+
|
|
183
|
+
declare const VERSION: string;
|
|
184
|
+
|
|
185
|
+
export { type CartesiaProvider, type CartesiaProviderSettings, CartesiaRealtimeModel, type CartesiaRealtimeModelId, type CartesiaRealtimeModelOptions, CartesiaSpeechModel, type CartesiaSpeechModelId, type CartesiaSpeechModelOptions, type CartesiaSpeechVoiceId, CartesiaTranscriptionModel, type CartesiaTranscriptionModelId, type CartesiaTranscriptionModelOptions, VERSION, cartesia, createCartesia };
|