PHP Classes

How to Use a PHP Text-to-Speech Library to Generate Voice Audio for a Text Using the Package ElevenLabs Laravel: Generate speech from text using the ElevenLabs API

Recommend this page to a friend!
     
  Info   Example   View files Files   Install with Composer Install with Composer   Download Download   Reputation   Support forum   Blog    
Last Updated Ratings Unique User Downloads Download Rankings
2024-08-19 (3 days ago) RSS 2.0 feedNot yet rated by the usersTotal: 7 This week: 7All time: 11,413 This week: 9Up
Version License PHP version Categories
elevenlabs-laravel 1.0Custom (specified...7Text processing, Libraries, Web services, A..., A..., P...
Description 

Author

This package can generate speech from text using the ElevenLabs API.

It provides a Laravel service class configuring a class to call the ElevenLabs text-to-speech API using traits.

The traits can call the ElevenLabs API to:

- Get the available text-to-speech generation models

- Generate an MPEG audio stream that represents a given text and a given model

Picture of Arda Günsüren
  Performance   Level  
Name: Arda Günsüren <contact>
Classes: 3 packages by
Country: Turkey Turkey

Example

<?php

describe
('Methods Unit Test', function () {
   
test('getModels() function', function () {
       
$models = \ArdaGnsrn\ElevenLabs\Facades\ElevenLabs::getModels();
       
expect($models)->toBeArray();
       
expect($models)->not->toBeEmpty();
    });
   
test('textToSpeech() function', function () {
       
$response = \ArdaGnsrn\ElevenLabs\Facades\ElevenLabs::textToSpeech('2EiwWnXFnvU5JabPnv8n', 'H');
       
expect($response)->toBeInstanceOf(\ArdaGnsrn\ElevenLabs\Responses\TextToSpeechResponse::class);

       
$response->saveFile('test.mp3');
       
expect(\Illuminate\Support\Facades\Storage::exists('test.mp3'))->toBeTrue();
    });
});


Details

elevenlabs-js

ElevenLabs.io API for PHP Laravel

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

This is an Open Source PHP Laravel package for elevenlabs.io Text to Speech API. You can find the Official API document here: https://api.elevenlabs.io/docs

Buy me a coffee

Whether you use this project, have learned something from it, or just like it, please consider supporting it by buying me a coffee, so I can dedicate more time on open-source projects like this :)

<a href="https://www.buymeacoffee.com/ardagnsrn" target="_blank"><img src="https://www.buymeacoffee.com/assets/img/custom_images/orange_img.png" alt="Buy Me A Coffee" style="height: auto !important;width: auto !important;" ></a>

Table of Contents

Installation

You can install the package via composer:

composer require ardagnsrn/elevenlabs-laravel

You can publish the config file with:

php artisan vendor:publish --tag="elevenlabs-laravel-config"

This is the contents of the published config file:

return [
    'api_key' => env('ELEVENLABS_API_KEY'),
];

Supported Methods

| Method | Parameters | EndPoint | HTTP Method | |------------------|-----------------------------------------------|----------------------------------------|-------------| | textToSpeech() | voiceId, text, modelId, voiceSettings | /v1/text-to-speech/{voice_id}/stream | POST | | getModels() | N/A | /v1/models | GET |

Parameters

| Parameter | Type | Description | Required | Default | |---------------|--------|-----------------------------------------------------------------------------------------|----------|---------------------------------------------------------------------------------------------------| | voiceId | String | The ID of the voice to use. You can get a list of available voices using getVoices(). | Yes | N/A | | text | String | The text to convert to speech. | Yes | N/A | | modelId | String | The ID of the model to use. You can get a list of available models using getModels(). | No | eleven_multilingual_v2 | | voiceSettings | Array | The settings to use for the voice. | No | ['stability' => 0.95, 'similarity_boost' => 0.75, 'style' => 0.06, 'use_speaker_boost' => true] |

Voice Settings

| Parameter | Type | Description | Default | |-------------------|---------|--------------------------------------|---------| | stability | Float | The stability of the voice. | 0.95 | | similarity_boost | Float | The similarity boost of the voice. | 0.75 | | style | Float | The style of the voice. | 0.06 | | use_speaker_boost | Boolean | Whether to use speaker boost or not. | true |

Usage

textToSpeech() Method

Generate a text to speech audio file. You can either save the file or get the pipe and do whatever you want with it.

$elevenLabs = new ArdaGnsrn\ElevenLabs();
$response = $elevenLabs->textToSpeech('YOUR_VOICE_ID', 'Hello World!', 'eleven_multilingual_v2', [
    'stability' => 0.95, 
    'similarity_boost' => 0.75, 
    'style' => 0.06, 
    'use_speaker_boost' => true
]);

// If you want, you can save to storage like this:
$response->saveFile('audio.mp3');

// Or you can get the response and do whatever you want with it:
$response->getResponse();

getModels() Method

Get a list of available models.

$elevenLabs = new ArdaGnsrn\ElevenLabs();
$models = $elevenLabs->getModels();

Testing

composer test

Other Languages

Also, you can find the other languages of this package here: - ElevenLabs API For NodeJS (elevenlabs-js) - ElevenLabs API For PHP Laravel (elevenlabs-laravel)

Changelog

Please see CHANGELOG for more information on what has changed recently.

Credits

License

The MIT License (MIT). Please see License File for more information.


  Files folder image Files (30)  
File Role Description
Files folder image.github (2 files, 2 directories)
Files folder imageconfig (1 file)
Files folder imagesrc (2 files, 4 directories)
Files folder imagetests (4 files)
Files folder imageworkbench (1 directory)
Accessible without login Plain text file .editorconfig Data Auxiliary data
Accessible without login Image file banner.png Icon Icon image
Accessible without login Plain text file CHANGELOG.md Data Auxiliary data
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file LICENSE.md Lic. License text
Accessible without login Plain text file phpstan.neon.dist Data Auxiliary data
Accessible without login Plain text file phpunit.xml.dist Data Auxiliary data
Accessible without login Plain text file README.md Doc. Documentation

  Files folder image Files (30)  /  .github  
File Role Description
Files folder imageISSUE_TEMPLATE (2 files)
Files folder imageworkflows (5 files)
  Accessible without login Plain text file dependabot.yml Data Auxiliary data
  Accessible without login Plain text file FUNDING.yml Data Auxiliary data

  Files folder image Files (30)  /  .github  /  ISSUE_TEMPLATE  
File Role Description
  Accessible without login Plain text file bug.yml Data Auxiliary data
  Accessible without login Plain text file config.yml Data Auxiliary data

  Files folder image Files (30)  /  .github  /  workflows  
File Role Description
  Accessible without login Plain text file dependabot-auto-merge.yml Data Auxiliary data
  Accessible without login Plain text file fix-php-code-style-issues.yml Data Auxiliary data
  Accessible without login Plain text file phpstan.yml Data Auxiliary data
  Accessible without login Plain text file run-tests.yml Data Auxiliary data
  Accessible without login Plain text file update-changelog.yml Data Auxiliary data

  Files folder image Files (30)  /  config  
File Role Description
  Accessible without login Plain text file elevenlabs.php Aux. Configuration script

  Files folder image Files (30)  /  src  
File Role Description
Files folder imageFacades (1 file)
Files folder imageResponses (1 file)
Files folder imageTraits (2 files)
Files folder imageUtils (1 file)
  Plain text file ElevenLabs.php Class Class source
  Plain text file ElevenLabsServiceProvider.php Class Class source

  Files folder image Files (30)  /  src  /  Facades  
File Role Description
  Plain text file ElevenLabs.php Class Class source

  Files folder image Files (30)  /  src  /  Responses  
File Role Description
  Plain text file TextToSpeechResponse.php Class Class source

  Files folder image Files (30)  /  src  /  Traits  
File Role Description
  Plain text file ModelsTrait.php Class Class source
  Plain text file TextToSpeechTrait.php Class Class source

  Files folder image Files (30)  /  src  /  Utils  
File Role Description
  Plain text file API.php Class Class source

  Files folder image Files (30)  /  tests  
File Role Description
  Accessible without login Plain text file ArchTest.php Example Example script
  Accessible without login Plain text file ExampleTest.php Example Example script
  Accessible without login Plain text file Pest.php Test Test script
  Accessible without login Plain text file TestCase.php Test Test class

  Files folder image Files (30)  /  workbench  
File Role Description
Files folder imageapp (1 directory)

  Files folder image Files (30)  /  workbench  /  app  
File Role Description
Files folder imageProviders (1 file)

  Files folder image Files (30)  /  workbench  /  app  /  Providers  
File Role Description
  Plain text file WorkbenchServiceProvider.php Class Class source

The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page.
Install with Composer Install with Composer
 Version Control Unique User Downloads Download Rankings  
 100%
Total:7
This week:7
All time:11,413
This week:9Up