masterarrow / laravel-elevenlabs-client
Wrapper client for elevenlabs api
Requires
- php: ^8.0
- guzzlehttp/guzzle: ^7.7
- illuminate/support: ^10.13
Requires (Dev)
- pestphp/pest: ^2.6
- vimeo/psalm: ^5.12
README
This is a Laravel package that serves as a wrapper for ElevenLabs Voice Generation API. It provides an easy-to-use interface for generating voices based on provided content.
Installation
You can install the package via Composer. Run the following command:
composer require masterarrow/elevenlabs-api-client
Next, you need to add the service provider in your Laravel application's config/app.php file. Open the file and locate the 'providers' array. Add the following line to the array:
ElevenLabsWrapper\ElevenLabsClient\Providers\ElevenLabsClientServiceProvider::class,
Usage
To get started, make sure to set up your ElevenLabs API key. You can do this by adding the following key to your .env file:
ELEVEN_API_KEY=your-api-key
You can then use the package by accessing the ElevenLabsClient instance. For example, you can add the following route to your web.php or api.php file to test that the library is working:
<?php use Illuminate\Support\Facades\Route; /* |-------------------------------------------------------------------------- | Web Routes |-------------------------------------------------------------------------- | | Here is where you can register web routes for your application. These | routes are loaded by the RouteServiceProvider and all of them will | be assigned to the "web" middleware group. Make something great! | */ Route::get('/test_elevenlabsclient', function() { $elevenLabsClient = app()->make(\ElevenLabsWrapper\ElevenLabsClient\ElevenLabsClient::class); return $elevenLabsClient->voices()->getAll(); });
Voice Class
Namespace
ElevenLabsWrapper\ElevenLabsClient\Voice
Class Description
The Voice
class is a part of the ElevenLabsWrapper\ElevenLabsClient\Voice
namespace. It implements the VoiceInterface
.
getAll()
Retrieve all the available voices.
getVoice(string $voice_id)
Returns metadata about a specific voice.
defaultSettings()
Gets the default settings for voices.
voiceSettings(string $voice_id)
addVoice(string $name, ?string $description, string $files, ?string $labels = "American")
Add a new voice to your collection of voices in VoiceLab.
Parameters:
$name
(string): The name of the voice.$description
(string|null): The description of the voice.$files
(string): The file path of the voice.$labels
(string|null, default: "American"): The labels for the voice.
editVoice(string $voice_id, string $name, ?string $description, ?string $files, ?string $labels = "American")
Edit a voice in your collection of voices in VoiceLab.
Parameters:
$voice_id
(string): The ID of the voice.$name
(string): The new name of the voice.$description
(string|null): The new description of the voice.$files
(string|null): The new file path of the voice.$labels
(string|null, default: "American"): The new labels for the voice.
deleteVoice(string $voice_id)
Delete a specific voice from your collection of voices in VoiceLab.
Parameters:
$voice_id
(string): The ID of the voice.
TextToSpeech class
Namespace
ElevenLabsWrapper\ElevenLabsClient\TextToSpeech
Class Description
The TextToSpeech
class is a part of the ElevenLabsWrapper\ElevenLabsClient\TextToSpeech
namespace. It implements the TextToSpeechInterface
.
generate(string $content, string $voice_id , ?bool $optimize_latency, ?string $model_id, ?array $voice_settings = [])
generate_stream(string $content, string $voice_id , ?bool $optimize_latency, ?string $model_id , ?array $voice_settings = [])
History
Namespace
ElevenLabsWrapper\ElevenLabsClient\History
Class Description
The History
class is a part of the ElevenLabsWrapper\ElevenLabsClient\History
namespace. It implements the HistoryInterface
.
getHistory()
Returns metadata about all your generated audio.
getHistoryItem(string $history_item_id)
Returns information about a history item by its ID.
Parameters
$history_item_id
(string): The ID of the history item.
getHistoryItemAudio(string $history_item_id, string $fileName)
Returns the audio of a history item.
Parameters
$history_item_id
(string): The ID of the history item.$fileName
(string): The desired file name for the audio file.
deleteHistoryItem(string $history_item_id)
Delete a history item by its ID.
Parameters
$history_item_id
(string): The ID of the history item.
downloadHistory(array $history_items, string $filename)
Download one or more history items. If one history item ID is provided, a single audio file will be returned. If multiple history item IDs are provided, the history items will be packed into a .zip file.
Parameters
$history_items
(array): An array of history item IDs.$filename
(string): The desired file name for the downloaded file.
Models
Class
Available Methods
getModels()
Gets a list of available models.
Return Type: array
User
Class
Namespace
ElevenLabsWrapper\ElevenLabsClient\User
Class Description
The User
class is a part of the ElevenLabsWrapper\ElevenLabsClient\User
namespace. It implements the UserInterface
.
Available Methods
getUserInfo()
Gets information about the user.
Return Type: array
Description:
This method retrieves information about the current user. It sends a GET request to the user
endpoint and returns the decoded response data as an array.
getUserSubscription()
Gets extended information about the user's subscription.
Return Type: array
Description:
This method retrieves extended information about the current user's subscription. It sends a GET request to the user/subscription
endpoint and returns the decoded response data as an array.
Feel free to use these methods in your Laravel application to interact with the ElevenLabs Voice Generation API.