Skip to content

Commit e78d27e

Browse files
committed
feat(platform): Cartesia support
1 parent fc32bc6 commit e78d27e

File tree

21 files changed

+752
-0
lines changed

21 files changed

+752
-0
lines changed

docs/components/platform.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,9 @@ Supported Models & Platforms
102102
* `LM Studio Catalog`_ and `HuggingFace`_ Models with `LM Studio`_ as Platform.
103103
* All models provided by `HuggingFace`_ can be listed with a command in the examples folder,
104104
and also filtered, e.g. ``php examples/huggingface/_model-listing.php --provider=hf-inference --task=object-detection``
105+
* **Voice Models**
106+
* `Cartesia TTS` with `Cartesia`_ as Platform
107+
* `Cartesia STT` with `Cartesia`_ as Platform
105108

106109
Options
107110
-------
@@ -463,6 +466,7 @@ Code Examples
463466
.. _`Anthropic's Claude`: https://www.anthropic.com/claude
464467
.. _`Anthropic`: https://www.anthropic.com/
465468
.. _`AWS Bedrock`: https://aws.amazon.com/bedrock/
469+
.. _`Cartesia`: https://cartesia.ai/sonic
466470
.. _`Meta's Llama`: https://www.llama.com/
467471
.. _`Ollama`: https://ollama.com/
468472
.. _`Replicate`: https://replicate.com/

examples/.env

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@ OPENROUTER_KEY=
5252
ELEVEN_LABS_URL=https://api.elevenlabs.io/v1
5353
ELEVEN_LABS_API_KEY=
5454

55+
# For using Cartesia
56+
CARTESIA_API_KEY=
57+
CARTESIA_API_VERSION=2025-04-16
58+
5559
# For using SerpApi (tool)
5660
SERP_API_KEY=
5761

examples/cartesia/README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Cartesia Examples
2+
3+
One use case of Cartesia is to convert text to speech, which creates audio files from text input.
4+
5+
To run the examples, you can use additional tools like (mpg123)[https://www.mpg123.de/]:
6+
7+
```bash
8+
php cartesia/text-to-speech.php | mpg123 -
9+
```
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
use Symfony\AI\Platform\Bridge\Cartesia\PlatformFactory;
13+
use Symfony\AI\Platform\Message\Content\Audio;
14+
15+
require_once dirname(__DIR__).'/bootstrap.php';
16+
17+
$platform = PlatformFactory::create(
18+
apiKey: env('CARTESIA_API_KEY'),
19+
version: env('CARTESIA_API_VERSION'),
20+
httpClient: http_client(),
21+
);
22+
23+
$result = $platform->invoke('ink-whisper', Audio::fromFile(dirname(__DIR__, 2).'/fixtures/audio.mp3'));
24+
25+
echo $result->asText().\PHP_EOL;
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
use Symfony\AI\Platform\Bridge\Cartesia\PlatformFactory;
13+
use Symfony\AI\Platform\Message\Content\Text;
14+
15+
require_once dirname(__DIR__).'/bootstrap.php';
16+
17+
$platform = PlatformFactory::create(
18+
apiKey: env('CARTESIA_API_KEY'),
19+
version: env('CARTESIA_API_VERSION'),
20+
httpClient: http_client(),
21+
);
22+
23+
$result = $platform->invoke('sonic-3', new Text('Hello world'), [
24+
'voice' => '6ccbfb76-1fc6-48f7-b71d-91ac6298247b', // Tessa (https://play.cartesia.ai/voices/6ccbfb76-1fc6-48f7-b71d-91ac6298247b)
25+
'output_format' => [
26+
'container' => 'mp3',
27+
'sample_rate' => 48000,
28+
'bit_rate' => 192000,
29+
],
30+
]);
31+
32+
echo $result->asBinary().\PHP_EOL;

src/ai-bundle/config/options.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,17 @@
5454
->end()
5555
->end()
5656
->end()
57+
->arrayNode('cartesia')
58+
->children()
59+
->stringNode('host')->end()
60+
->stringNode('api_key')->isRequired()->end()
61+
->stringNode('version')->isRequired()->end()
62+
->stringNode('http_client')
63+
->defaultValue('http_client')
64+
->info('Service ID of the HTTP client to use')
65+
->end()
66+
->end()
67+
->end()
5768
->arrayNode('eleven_labs')
5869
->children()
5970
->stringNode('host')->end()

src/ai-bundle/config/services.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
use Symfony\AI\Platform\Bridge\Anthropic\Contract\AnthropicContract;
2828
use Symfony\AI\Platform\Bridge\Anthropic\ModelCatalog as AnthropicModelCatalog;
2929
use Symfony\AI\Platform\Bridge\Anthropic\TokenOutputProcessor as AnthropicTokenOutputProcessor;
30+
use Symfony\AI\Platform\Bridge\Cartesia\ModelCatalog as CartesiaModelCatalog;
3031
use Symfony\AI\Platform\Bridge\Cerebras\ModelCatalog as CerebrasModelCatalog;
3132
use Symfony\AI\Platform\Bridge\DeepSeek\ModelCatalog as DeepSeekModelCatalog;
3233
use Symfony\AI\Platform\Bridge\DockerModelRunner\ModelCatalog as DockerModelRunnerModelCatalog;
@@ -84,6 +85,7 @@
8485
// model catalog
8586
->set('ai.platform.model_catalog.aimlapi', AiMlApiModelCatalog::class)
8687
->set('ai.platform.model_catalog.anthropic', AnthropicModelCatalog::class)
88+
->set('ai.platform.model_catalog.cartesia', CartesiaModelCatalog::class)
8789
->set('ai.platform.model_catalog.cerebras', CerebrasModelCatalog::class)
8890
->set('ai.platform.model_catalog.deepseek', DeepSeekModelCatalog::class)
8991
->set('ai.platform.model_catalog.dockermodelrunner', DockerModelRunnerModelCatalog::class)

src/ai-bundle/src/AiBundle.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
use Symfony\AI\Chat\MessageStoreInterface;
4141
use Symfony\AI\Platform\Bridge\Anthropic\PlatformFactory as AnthropicPlatformFactory;
4242
use Symfony\AI\Platform\Bridge\Azure\OpenAi\PlatformFactory as AzureOpenAiPlatformFactory;
43+
use Symfony\AI\Platform\Bridge\Cartesia\PlatformFactory as CartesiaPlatformFactory;
4344
use Symfony\AI\Platform\Bridge\Cerebras\PlatformFactory as CerebrasPlatformFactory;
4445
use Symfony\AI\Platform\Bridge\DeepSeek\PlatformFactory as DeepSeekPlatformFactory;
4546
use Symfony\AI\Platform\Bridge\DockerModelRunner\PlatformFactory as DockerModelRunnerPlatformFactory;
@@ -291,6 +292,26 @@ private function processPlatformConfig(string $type, array $platform, ContainerB
291292
return;
292293
}
293294

295+
if ('cartesia' === $type) {
296+
$definition = (new Definition(Platform::class))
297+
->setFactory(CartesiaPlatformFactory::class.'::create')
298+
->setLazy(true)
299+
->addTag('proxy', ['interface' => PlatformInterface::class])
300+
->setArguments([
301+
$platform['api_key'],
302+
$platform['version'],
303+
$platform['host'],
304+
new Reference($platform['http_client'], ContainerInterface::NULL_ON_INVALID_REFERENCE),
305+
new Reference('ai.platform.model_catalog.cartesia'),
306+
new Reference('event_dispatcher'),
307+
])
308+
->addTag('ai.platform', ['name' => 'cartesia']);
309+
310+
$container->setDefinition('ai.platform.cartesia', $definition);
311+
312+
return;
313+
}
314+
294315
if ('eleven_labs' === $type) {
295316
$platformId = 'ai.platform.eleven_labs';
296317
$definition = (new Definition(Platform::class))

src/ai-bundle/tests/DependencyInjection/AiBundleTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2763,6 +2763,11 @@ private function getFullConfig(): array
27632763
'api_version' => '2024-02-15-preview',
27642764
],
27652765
],
2766+
'cartesia' => [
2767+
'host' => 'https://api.cartesia.ai',
2768+
'api_key' => 'cartesia_key_full',
2769+
'version' => '2025-04-16',
2770+
],
27662771
'eleven_labs' => [
27672772
'host' => 'https://api.elevenlabs.io/v1',
27682773
'api_key' => 'eleven_labs_key_full',

src/platform/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ CHANGELOG
2727
- AI/ML API (language models and embeddings)
2828
- Docker Model Runner (local model hosting)
2929
- Scaleway (language models like OpenAI OSS, Llama 4, Qwen 3, and more)
30+
- Cartesia (voice model that supports both text-to-speech and speech-to-text)
3031
* Add comprehensive message system with role-based messaging:
3132
- `UserMessage` for user inputs with multi-modal content
3233
- `SystemMessage` for system instructions

0 commit comments

Comments
 (0)