symfony/ai-cartesia-platform
Symfony AI bridge for the Cartesia Platform. Integrates Cartesia APIs for text-to-speech (bytes) and speech-to-text transcription, enabling easy API requests and usage within Symfony applications via the Symfony AI ecosystem.
Provider abstraction (v0.8.0+) aligns with Laravel’s service-oriented architecture, enabling clean separation of concerns. The PSR-15/PSR-18 compliance ensures compatibility with Laravel’s HTTP stack (e.g., illuminate/http-client or Guzzle), reducing vendor lock-in.CartesiaProvider as a Laravel service with a custom facade or helper.Cartesia::tts()->generate() for intuitive usage.CartesiaRequestSent, CartesiaResponseReceived) for logging/analytics.OpenAIProvider) is preferred.Provider abstraction’s maturity is unproven (limited changelog details). Custom logic (e.g., audio preprocessing, model fine-tuning) may require forking the package or extending it via Laravel’s service providers.HttpClient (or a Laravel-compatible adapter like symfony/http-client-bridge). Laravel’s native Http facade can interoperate but lacks Symfony’s retry middleware and event system.Provider abstraction enables swapping Cartesia, migrating to another service (e.g., AWS Polly) would require rewriting provider logic, not just configuration changes.HttpClient events (e.g., response, exception) be mapped to Laravel’s middleware or events for consistency?QuotaExceeded, InvalidAudioFormat) must be caught, and how will they map to Laravel’s exception handling?RetryStrategy or Laravel’s retry() helper? How will exponential backoff be configured?CartesiaProvider as a Laravel service with a custom facade or helper class to abstract Symfony dependencies.
// app/Providers/CartesiaServiceProvider.php
public function register()
{
$this->app->singleton(CartesiaTTS::class, function ($app) {
return new CartesiaTTS(new \Symfony\AI\Cartesia\Client());
});
}
Cartesia facade for intuitive usage:
// app/Facades/Cartesia.php
public function tts(string $text, string $voice): string
{
return $this->app->make(CartesiaTTS::class)->generate($text, $voice);
}
Http facade with Symfony’s HttpClient adapter for retries/middleware:
use Symfony\Component\HttpClient\HttpClient;
$client = HttpClient::create([
'base_uri' => 'https://api.cartesia.ai',
'auth_bearer' => config('services.cartesia.key'),
]);
Http facade or Guzzle for cross-stack compatibility..env:
CARTEsia_API_KEY=your_key_here
CARTEsia_TIMEOUT=30
Phase 1: API Validation (1–2 Days)
Http facade to confirm latency, cost, and response formats.$response = Http::withHeaders([
'Authorization' => 'Bearer ' . config('services.cartesia.key'),
])->post('https://api.cartesia.ai/tts/bytes', [
'text' => 'Hello',
'voice' => 'en-US',
]);
Phase 2: Symfony Provider Wrapper (2–3 Days)
CartesiaProvider:
// app/Services/CartesiaService.php
class CartesiaService {
public function __construct(private Client $client) {}
public function generateTTS(string $text, string $voice): string
{
return $this->client->tts()->bytes($text, $voice)->getContent();
}
}
$this->app->singleton(CartesiaService::class, function ($app) {
return new CartesiaService(new \Symfony\AI\Cartesia\Client());
});
Phase 3: Facade & Middleware (2 Days)
// app/Facades/Cartesia.php
public function tts(string $text, string $voice): string
{
return $this->app->make(CartesiaService::class)->generateTTS($text, $voice);
}
// app/Http/Middleware/CartesiaMiddleware.php
public function handle($request, Closure $next)
{
$response = $next($request);
if ($response->failed()) {
Log::error('Cartesia API failed', ['status' => $response->status()]);
}
return $response;
}
Phase 4: Queue & Caching (1–2 Days)
// app/Jobs/GenerateTTS.php
public function handle()
{
$audio = Cartesia::tts($this->text, $this->voice);
Storage::put($this->path, $audio);
}
$
How can I help you explore Laravel packages today?