- Can I use this package directly in Laravel without Symfony dependencies?
- No, this package requires Symfony’s HttpClient (or a Laravel-compatible adapter like `symfony/http-client-bridge`). You’ll need to register the `CartesiaProvider` in Laravel’s service container and adapt Symfony’s DI patterns. Laravel’s native `Http` facade can interoperate but lacks Symfony’s retry middleware.
- What Laravel versions does this package support?
- The package itself targets Symfony 6.4+, but Laravel compatibility depends on your Symfony HTTP client adapter. Test with Laravel 9+ (PHP 8.1+) or 10+ (PHP 8.2+). Check the `symfony/http-client-bridge` docs for Laravel-specific constraints.
- How do I authenticate with Cartesia’s API in Laravel?
- Configure your Cartesia API key in Laravel’s `.env` (e.g., `CARTEISA_API_KEY`) and bind it to the `CartesiaProvider` during service registration. The package expects Symfony’s `HttpClient` auth headers—adapt these via Laravel’s `Http` facade or a custom middleware if needed.
- Are there Laravel-specific error handlers for Cartesia API failures?
- No built-in handlers exist. Catch Cartesia-specific exceptions (e.g., `QuotaExceeded`, `InvalidAudioFormat`) using Laravel’s `try-catch` blocks or middleware. Map them to Laravel’s `HttpException` or custom exceptions for consistency with your app’s error handling.
- Can I use this for real-time IVR systems in Laravel?
- Yes, but ensure low-latency by queueing TTS/STT requests via Laravel Queues (e.g., `Cartesia::tts()->generate()`). Monitor Cartesia’s API SLAs and implement retries with exponential backoff using Laravel’s `retry()` helper or Symfony’s `RetryStrategy`.
- How do I handle large audio files (>5MB) for speech-to-text?
- Chunk uploads using Laravel’s `Storage` facade or queue jobs (e.g., `bus:dispatch` with `CartesiaChunkedUploadJob`). Stream responses to avoid memory issues. Test with Cartesia’s API limits—some endpoints may require base64-encoded binary data.
- What’s the best way to test this in Laravel?
- Mock Cartesia’s HTTP responses in Pest/PHPUnit using Laravel’s `Http::fake()` or `Mockery`. Test edge cases like malformed audio, rate limits, and queue failures. Validate event hooks (e.g., `CartesiaRequestSent`) with Laravel’s `Events::assertDispatched()`.
- Will this work with Laravel’s Horizon for queue-based TTS/STT?
- Yes, dispatch TTS/STT jobs to Horizon queues (e.g., `CartesiaTtsJob`). Use Laravel’s `ShouldQueue` trait and configure Cartesia’s client in the job’s `handle()` method. Monitor queue failures via Horizon’s dashboard.
- Are there alternatives for Laravel if this package is unstable?
- For TTS/STT, consider Laravel-specific packages like `spatie/laravel-aws-polly` (AWS Polly) or `mollie/laravel-speech` (Google Cloud Speech). For Symfony AI, use `symfony/ai` with `openai/openai` for LLM-focused tasks. Evaluate Cartesia’s API maturity before committing.
- How do I monitor Cartesia API costs in Laravel?
- Track usage via Laravel’s `Log` or a custom metric (e.g., `Laravel Cashier` for billing). Log API responses with request IDs and implement a `CartesiaUsageObserver` to aggregate costs. Alert on thresholds using Laravel Notifications or `laravel-monitor`.