PHPackages                             samandar/laravel-elevenlabs - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. samandar/laravel-elevenlabs

ActiveLibrary[API Development](/categories/api)

samandar/laravel-elevenlabs
===========================

Laravel package for ElevenLabs Text-to-Speech API integration with full API support

v1.2.0(9mo ago)00MITPHPPHP ^8.1CI failing

Since Aug 8Pushed 9mo agoCompare

[ Source](https://github.com/abdu11aev-samandar/laravel-elevenlabs)[ Packagist](https://packagist.org/packages/samandar/laravel-elevenlabs)[ RSS](/packages/samandar-laravel-elevenlabs/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (1)Dependencies (5)Versions (5)Used By (0)

ElevenLabs Laravel Package
==========================

[](#elevenlabs-laravel-package)

 [ ![Tests](https://camo.githubusercontent.com/3e2062f5fedc2e0fa1fef35860d02030f13da989102e1cdfb0eabb6274943d1b/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f6162647531316165762d73616d616e6461722f6c61726176656c2d656c6576656e6c6162732f74657374732e796d6c3f6272616e63683d6d61696e267374796c653d666c61742d737175617265266c6f676f3d676974687562) ](https://github.com/abdu11aev-samandar/laravel-elevenlabs/actions) [ ![Latest Version](https://camo.githubusercontent.com/8ebcec9e0db1bce2103d791411f614c7eb925f98f18f645324a75b6f8b15d2d4/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f73616d616e6461722f6c61726176656c2d656c6576656e6c6162732e7376673f7374796c653d666c61742d737175617265266c6f676f3d7061636b6167697374) ](https://packagist.org/packages/samandar/laravel-elevenlabs) [ ![Total Downloads](https://camo.githubusercontent.com/52c0b3dc7be78eca0f6b0697c5b127ddd1ef06cf0763e9751946e3454df14895/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f73616d616e6461722f6c61726176656c2d656c6576656e6c6162732e7376673f7374796c653d666c61742d737175617265266c6f676f3d7061636b6167697374) ](https://packagist.org/packages/samandar/laravel-elevenlabs) [ ![License](https://camo.githubusercontent.com/61819ceaaf43ebc373c74544d5dfd1921ae4b0187ad9ee8d6909b296dba4f737/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f6162647531316165762d73616d616e6461722f6c61726176656c2d656c6576656e6c6162733f7374796c653d666c61742d737175617265) ](https://github.com/abdu11aev-samandar/laravel-elevenlabs/blob/main/LICENSE) [ ![PHP Version](https://camo.githubusercontent.com/43a52de372d08e615769aeeed8ba305d51236062c2f310351a08c9805d833f33/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048502d382e312532422d3737374242343f7374796c653d666c61742d737175617265266c6f676f3d706870) ](https://php.net) [ ![Laravel Version](https://camo.githubusercontent.com/2cbf5de858cbfae5b9f2f05b8fa97d5d0ddc7dad6156b70f2ce9c20f4edd49d9/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c61726176656c2d392e7825323025374325323031302e7825323025374325323031312e782d4646324432303f7374796c653d666c61742d737175617265266c6f676f3d6c61726176656c) ](https://laravel.com)

 **A comprehensive Laravel package for integrating with ElevenLabs Text-to-Speech API**
 Featuring modular architecture, backward compatibility, and professional-grade functionality.

---

📊 Package Statistics
--------------------

[](#-package-statistics)

- **🏗️ Architecture**: Modular service-based design
- **🧪 Tests**: 46 tests with 80 assertions (100% passing)
- **📦 Services**: 6 specialized service classes
- **🔧 Methods**: 50+ API methods available
- **🚀 Features**: TTS, STT, Voice Cloning, Dubbing, AI Chat, and more
- **📚 Documentation**: Comprehensive guides and examples
- **🔄 Compatibility**: Full backward compatibility maintained

Features
--------

[](#features)

### 🎯 Core Features

[](#-core-features)

- **Text-to-Speech** conversion with multiple models
- **Speech-to-Text** transcription capabilities
- **Speech-to-Speech** voice conversion
- **Streaming TTS** for real-time audio generation
- 🌍 Support for multiple languages and voices
- ⚙️ Configurable voice settings with fine-tuning

### 🎭 Voice Management

[](#-voice-management)

- Voice cloning and custom voice creation
- Voice library access and similarity search
- Voice settings editing and deletion
- Shared voices from community library
- Voice similarity detection

### 🚀 Advanced Features

[](#-advanced-features)

- **Dubbing** for video/audio translation
- **History Management** for generation tracking
- **Pronunciation Dictionaries** for custom pronunciations
- **Forced Alignment** for precise audio-text synchronization

### 🎬 Studio &amp; Projects

[](#-studio--projects)

- **Studio Projects** creation and management
- **Podcast Project** generation
- Project conversion and media processing
- File upload and project organization

### 🤖 Conversational AI

[](#-conversational-ai)

- **Knowledge Base** creation from URLs
- **Conversational AI Settings** management
- **Workspace Secrets** handling
- Resource sharing and collaboration tools

### 📊 Analytics &amp; Management

[](#-analytics--management)

- **Usage Statistics** and character tracking
- Generation history and analytics
- User subscription information
- Comprehensive error handling and logging

### 🔧 Laravel Integration

[](#-laravel-integration)

- Simple and intuitive API
- Laravel service container integration
- Facade support for easy usage
- Automatic file saving capabilities
- Comprehensive test coverage

Installation
------------

[](#installation)

You can install the package via composer:

```
composer require samandar/laravel-elevenlabs
```

Configuration
-------------

[](#configuration)

1. **Publish the configuration file:**

```
php artisan vendor:publish --tag=elevenlabs-config
```

2. **Add your ElevenLabs API key to your `.env` file:**

```
ELEVENLABS_API_KEY=your_api_key_here
ELEVENLABS_DEFAULT_VOICE_ID=21m00Tcm4TlvDq8ikWAM
ELEVENLABS_DEFAULT_MODEL=eleven_multilingual_v2
```

3. **Optionally configure other settings:**

```
ELEVENLABS_AUDIO_PATH=elevenlabs/audio
ELEVENLABS_TIMEOUT=30
ELEVENLABS_LOG_REQUESTS=false
```

Usage
-----

[](#usage)

The package provides two approaches for accessing ElevenLabs functionality:

1. **New Modular Approach** (Recommended) - Organized by feature groups
2. **Legacy Approach** - Backward compatible with previous versions

### 🚀 New Modular Approach

[](#-new-modular-approach)

#### Audio Service (TTS, STT, STS, etc.)

[](#audio-service-tts-stt-sts-etc)

```
use Samandar\LaravelElevenLabs\Facades\ElevenLabs;

// Text-to-Speech
$result = ElevenLabs::audio()->textToSpeech('Hello, world!');

// Speech-to-Text
$uploadedFile = request()->file('audio');
$result = ElevenLabs::audio()->speechToText($uploadedFile);

// Speech-to-Speech conversion
$result = ElevenLabs::audio()->speechToSpeech(
    'voice_id_here',
    $uploadedFile
);

// Streaming TTS
$stream = ElevenLabs::audio()->streamTextToSpeech('Hello streaming!');
foreach ($stream as $chunk) {
    // Process audio chunk
    echo $chunk;
}

// Save audio to file
$saved = ElevenLabs::audio()->saveAudioToFile(
    $audioContent,
    storage_path('app/speech.mp3')
);

// Text-to-Speech with file saving
$result = ElevenLabs::audio()->textToSpeechAndSave(
    'Hello, this will be saved!',
    storage_path('app/test-speech.mp3')
);

// 🆕 NEW: Audio Isolation (experimental)
// Note: This method is experimental and may change as ElevenLabs finalizes the endpoint.
$isolatedAudio = ElevenLabs::audio()->audioIsolation($uploadedFile);

// 🆕 NEW: Sound Generation - Create sound effects from text
$soundEffect = ElevenLabs::audio()->soundGeneration(
    'Thunder and rain sounds',  // Text description
    10,                         // Duration in seconds (optional)
    'strong'                    // Prompt influence or guidance (optional)
);
```

#### Voice Service (Voice Management)

[](#voice-service-voice-management)

```
// Get available voices
$voices = ElevenLabs::voice()->getVoices();

// Get specific voice details
$voice = ElevenLabs::voice()->getVoice('voice_id_here');

// Add custom voice
$result = ElevenLabs::voice()->addVoice(
    'My Custom Voice',
    $audioFiles, // Array of UploadedFile objects
    'Description of the voice'
);

// Edit voice settings
$result = ElevenLabs::voice()->editVoiceSettings('voice_id', [
    'stability' => 0.7,
    'similarity_boost' => 0.8
]);

// Delete voice
$result = ElevenLabs::voice()->deleteVoice('voice_id');

// Get shared voices from community
$sharedVoices = ElevenLabs::voice()->getSharedVoices();

// Pronunciation dictionaries
$dictionaries = ElevenLabs::voice()->getPronunciationDictionaries();
$result = ElevenLabs::voice()->addPronunciationDictionary(
    'My Dictionary',
    [['string' => 'word', 'phoneme' => 'pronunciation']]
);

// 🆕 NEW: Create voice previews
$result = ElevenLabs::voice()->createVoicePreviews(
    'Hello, this is a voice preview test',
    'voice_id_here'
);
);
```

#### AI Service (Conversational AI &amp; Knowledge Base)

[](#ai-service-conversational-ai--knowledge-base)

```
// Conversational AI settings
$settings = ElevenLabs::ai()->getConversationalAISettings();
$result = ElevenLabs::ai()->updateConversationalAISettings($newSettings);

// Knowledge base management
$result = ElevenLabs::ai()->createKnowledgeBaseFromURL('https://docs.example.com');
$knowledgeBases = ElevenLabs::ai()->getKnowledgeBases();
$result = ElevenLabs::ai()->deleteKnowledgeBase('kb_id');

// Knowledge base documents (file upload)
$multipart = [
    [
        'name' => 'file',
        'contents' => fopen(storage_path('app/docs.pdf'), 'r'),
        'filename' => 'docs.pdf'
    ]
];
$doc = ElevenLabs::ai()->createKnowledgeBaseDocumentFromFile($multipart);
$docContent = ElevenLabs::ai()->getKnowledgeBaseDocumentContent('document_id');

// RAG Index overview
$rag = ElevenLabs::ai()->getRagIndexOverview();

// Workspace secrets
$secrets = ElevenLabs::ai()->getWorkspaceSecrets();

// 🆕 NEW: Signed URL and Widget
$signed = ElevenLabs::ai()->getSignedUrl('agent_id_here');
$widget = ElevenLabs::ai()->getAgentWidgetConfig('agent_id_here');

// 🆕 NEW: Tools and MCP Servers
$tools = ElevenLabs::ai()->listTools();
$tool = ElevenLabs::ai()->getTool('tool_id');
$createdTool = ElevenLabs::ai()->createTool(['name' => 'Search Tool']);
$dependentAgents = ElevenLabs::ai()->getDependentAgents('tool_id');

$mcpServers = ElevenLabs::ai()->listMcpServers();
$createdMcp = ElevenLabs::ai()->createMcpServer(['name' => 'Internal MCP']);
$approval = ElevenLabs::ai()->createMcpApprovalPolicy(['policy' => 'allow_all']);

// Dashboard settings
$dashboard = ElevenLabs::ai()->getDashboardSettings();

// 🆕 NEW: AI Agents Management
// List all conversational AI agents with pagination
$agents = ElevenLabs::ai()->getAgents('cursor_here', 10);

// Create a new AI agent
$agentData = [
    'name' => 'Customer Support Agent',
    'prompt' => 'You are a helpful customer support assistant.',
    'voice_id' => '21m00Tcm4TlvDq8ikWAM',
    'language' => 'en'
];
$newAgent = ElevenLabs::ai()->createAgent($agentData);

// 🆕 NEW: Conversations Management
// List conversations with pagination and filters
$conversations = ElevenLabs::ai()->getConversations(
    'cursor_here',
    10 // page size
);

// Get specific conversation details
$conversation = ElevenLabs::ai()->getConversation('conversation_id');

// Get conversation audio file
$audio = ElevenLabs::ai()->getConversationAudio('conversation_id');

// 🆕 NEW: Batch Calling
// Submit a batch calling job
$callsData = [
    [
        'phone_number' => '+1234567890',
        'message' => 'Hello, this is a test call.'
    ],
    [
        'phone_number' => '+0987654321',
        'message' => 'Another test message.'
    ]
];
$batchJob = ElevenLabs::ai()->submitBatchCalling($callsData);

// Get batch calling status
$status = ElevenLabs::ai()->getBatchCalling('batch_id');
```

#### Studio Service (Projects &amp; Dubbing)

[](#studio-service-projects--dubbing)

```
// Studio projects
$projects = ElevenLabs::studio()->getStudioProjects();
$project = ElevenLabs::studio()->getStudioProject('project_id');

// Chapters and snapshots
$chapter = ElevenLabs::studio()->getChapter('project_id', 'chapter_id');
$chapterSnaps = ElevenLabs::studio()->listChapterSnapshots('project_id', 'chapter_id');
$chapterSnapshot = ElevenLabs::studio()->getChapterSnapshot('project_id', 'chapter_id', 'snapshot_id');
$projectSnapshot = ElevenLabs::studio()->getProjectSnapshot('project_id', 'project_snapshot_id');

// Create project from file
$result = ElevenLabs::studio()->createStudioProject(
    $uploadedFile,
    'My Project Name'
);

// Convert project
$result = ElevenLabs::studio()->convertStudioProject('project_id');

// Delete project
$result = ElevenLabs::studio()->deleteStudioProject('project_id');

// Dubbing operations
$result = ElevenLabs::studio()->createDubbing(
    $sourceFile,
    'spanish', // target language
    'english', // source language (optional)
    2 // number of speakers (optional)
);

$dubbing = ElevenLabs::studio()->getDubbing('dubbing_id');
$audio = ElevenLabs::studio()->getDubbedAudio('dubbing_id', 'es');

// Podcast projects
$result = ElevenLabs::studio()->createPodcastProject($podcastData);

// Dubbing transcript (SRT/WEBVTT)
$transcript = ElevenLabs::studio()->getDubbingTranscript('dubbing_id', 'srt');
```

#### Analytics Service (Usage &amp; History)

[](#analytics-service-usage--history)

```
// User information and usage
$userInfo = ElevenLabs::analytics()->getUserInfo();
$usage = ElevenLabs::analytics()->getCharacterUsage();
$models = ElevenLabs::analytics()->getModels();

// Generation history
$history = ElevenLabs::analytics()->getHistory();
$historyItem = ElevenLabs::analytics()->getHistoryItem('history_id');
$result = ElevenLabs::analytics()->deleteHistoryItem('history_id');

// Download multiple history items
$result = ElevenLabs::analytics()->downloadHistory(['id1', 'id2']);

// 🆕 NEW: Get user subscription info
$subscription = ElevenLabs::analytics()->getUserSubscription();
```

#### Workspace Service (Collaboration)

[](#workspace-service-collaboration)

```
// Share workspace resources
$result = ElevenLabs::workspace()->shareWorkspaceResource(
    'resource_id',
    $shareData
);

// Get resources and a specific resource
$resources = ElevenLabs::workspace()->getWorkspaceResources();
$resource = ElevenLabs::workspace()->getWorkspaceResource('resource_id');

// Search groups
$groups = ElevenLabs::workspace()->searchWorkspaceGroups(['q' => 'team']);

// Members
$members = ElevenLabs::workspace()->getWorkspaceMembers();
$invitation = ElevenLabs::workspace()->inviteWorkspaceMember('user@example.com', ['read']);
$removed = ElevenLabs::workspace()->removeWorkspaceMember('member_id');

// Workspace-level secrets (optional)
$workspaceSecrets = ElevenLabs::workspace()->getWorkspaceSecrets();
```

### 🔄 Legacy Approach (Backward Compatible)

[](#-legacy-approach-backward-compatible)

All existing code continues to work unchanged:

```
use Samandar\LaravelElevenLabs\Facades\ElevenLabs;

// Basic text-to-speech conversion
$result = ElevenLabs::textToSpeech('Hello, world!');

if ($result['success']) {
    // Save audio to file
    $saved = ElevenLabs::saveAudioToFile(
        $result['audio'],
        storage_path('app/speech.mp3')
    );
}

// Convert text to speech and save in one step
$result = ElevenLabs::textToSpeechAndSave(
    'Hello, this is a test message!',
    storage_path('app/test-speech.mp3')
);

// Get available voices
$voices = ElevenLabs::getVoices();
if ($voices['success']) {
    foreach ($voices['voices'] as $voice) {
        echo $voice['name'] . ' - ' . $voice['voice_id'] . "\n";
    }
}

// Use custom voice settings
$result = ElevenLabs::textToSpeech(
    'Custom voice settings example',
    '21m00Tcm4TlvDq8ikWAM', // Voice ID
    [
        'stability' => 0.7,
        'similarity_boost' => 0.8,
        'style' => 0.6,
        'use_speaker_boost' => true
    ]
);
```

### Using Dependency Injection

[](#using-dependency-injection)

```
use Samandar\LaravelElevenLabs\Services\ElevenLabsService;

class SpeechController extends Controller
{
    public function generateSpeech(ElevenLabsService $elevenLabs)
    {
        $result = $elevenLabs->textToSpeech('Hello from controller!');

        if ($result['success']) {
            return response($result['audio'], 200)
                ->header('Content-Type', $result['content_type']);
        }

        return response()->json(['error' => $result['error']], 500);
    }
}
```

### Controller Example

[](#controller-example)

```
