- Can I use this package in Laravel even though it’s built for Symfony?
- Yes, but with caveats. The package relies on Symfony’s `AIPlatformInterface` and `HttpClientInterface`. For Laravel, you’ll need to create a custom adapter or use the underlying HTTP client directly. The core ElevenLabs API functionality (TTS/STT) works standalone via HTTP calls, so you can bypass Symfony-specific abstractions if needed.
- What Laravel versions does this package support?
- This package isn’t natively Laravel-compatible, but its HTTP-based API works with Laravel 10+ (PHP 8.2+). For full integration, you’d need to adapt Symfony’s `AIPlatformInterface` to Laravel’s service container. Test thoroughly with Laravel’s HTTP client or Guzzle for compatibility.
- How do I authenticate with ElevenLabs in Laravel?
- Use the package’s `ElevenLabsClient` with your API key via constructor injection or Laravel’s service container. Example: `new ElevenLabsClient('your_api_key_here')`. For Laravel, bind the client to the container in `config/app.php` or a service provider, then inject it into your classes.
- Does this support real-time streaming for voice apps?
- Yes, the package supports ElevenLabs’ streaming TTS/STT endpoints. For Laravel, handle the streaming response with PHP’s `stream_get_contents()` or a library like `reactphp/stream`. The Symfony HTTP client’s streaming features can be adapted to Laravel’s Guzzle or native HTTP client.
- What’s the best way to handle rate limits or API errors in Laravel?
- Leverage Laravel’s `HttpClient` (or Guzzle) with retry middleware. The package uses Symfony’s `HttpClient`, so replicate its retry logic (e.g., `retry: 3`) in Laravel. For rate limits, cache responses locally or use Laravel’s `Cache` facade to avoid hitting ElevenLabs’ thresholds.
- Can I queue speech-to-text tasks for background processing?
- Yes, but you’ll need to adapt Symfony’s `Messenger` component to Laravel’s queue system. The package’s `SpeechToText` service can be wrapped in a Laravel job, then dispatched to the queue. Use Laravel’s `dispatch()` method to trigger async STT processing.
- Are there Laravel-specific testing tools or fixtures included?
- No, but the package includes test fixtures (e.g., sample audio files) for local testing. For Laravel, use these fixtures with PHPUnit or Pest to validate TTS/STT responses. Mock the HTTP client in tests to avoid real API calls during CI/CD.
- How do I switch between ElevenLabs and another TTS provider in Laravel?
- The package’s `AbstractProvider` allows provider switching, but Laravel would need a custom facade or service locator. Create a Laravel service that implements `AIPlatformInterface` and routes requests to the active provider (e.g., ElevenLabs or AWS Polly). Use dependency injection to swap implementations.
- What’s the cost impact of high-volume TTS/STT usage in Laravel?
- ElevenLabs charges per character for TTS and per minute for STT. Monitor usage with Laravel’s logging or a package like `spatie/laravel-monitoring`. Implement caching for repeated text (e.g., stored audio files) and batch STT tasks to optimize costs.
- Are there alternatives for Laravel if this package feels too Symfony-heavy?
- Yes, consider direct HTTP clients like Guzzle or Laravel’s `Http` facade to call ElevenLabs’ API endpoints manually. For a more Laravel-native solution, explore packages like `spatie/laravel-ai` (if it supports ElevenLabs) or build a custom wrapper around the ElevenLabs API.