Documentation

AudioTTS implements Pipeline

Implements an ElevenLabs TTS pipeline for audio generation.

This pipeline uses an underlying driver (default: GuzzleDriver) to make HTTP requests to the ElevenLabs API, setting the model, prompt, and voice parameters based on configuration and input IVFSprompt instances. It handles header configuration, API endpoint setup, and request modification to include voice settings. The output is stored as an audio file (default format: mp3) with a UUID as its filename.

Table of Contents

Interfaces

Pipeline
Defines the required methods for Ai Model Pipelines, which are required for compatibility with LaravelNeuro Agent Networking features.

Properties

$accessToken  : mixed
The ElevenLabs access token from configuration.
$driver  : GuzzleDriver
The AI model driver used for HTTP communication.
$fileType  : string
The output file type (default: "mp3").
$model  : mixed
The model identifier used for the request.
$prompt  : mixed
The prompt text extracted from the provided IVFSprompt instance.
$voice  : mixed
The default voice to use, as configured in the package configuration.

Methods

__construct()  : mixed
AudioTTS constructor.
driver()  : Driver
Accesses the injected Driver instance.
driverClass()  : string
Retrieves the class name of the default associated driver.
getDriver()  : Driver
Retrieves the current driver.
getModel()  : mixed
Retrieves the current model identifier.
getPrompt()  : mixed
Retrieves the current prompt input.
output()  : mixed
Executes the API request and returns the stored output.
promptClass()  : string
Retrieves the class name of the default associated prompt.
raw()  : mixed
Retrieves the raw response from the driver.
setModel()  : self
Sets the model for the pipeline.
setPrompt()  : self
Sets the prompt for the pipeline.
store()  : mixed
Stores the audio output as a file.
stream()  : Generator
Executes a streaming API request.

Properties

$accessToken

The ElevenLabs access token from configuration.

protected mixed $accessToken

$driver

The AI model driver used for HTTP communication.

protected GuzzleDriver $driver

Expected to implement the Driver contract.

$fileType

The output file type (default: "mp3").

protected string $fileType = "mp3"

$model

The model identifier used for the request.

protected mixed $model

$prompt

The prompt text extracted from the provided IVFSprompt instance.

protected mixed $prompt

$voice

The default voice to use, as configured in the package configuration.

protected mixed $voice

Methods

__construct()

AudioTTS constructor.

public __construct([Driver $driver = new GuzzleDriver() ]) : mixed

Injects a Driver instance (defaulting to GuzzleDriver) and sets up the pipeline using configuration values. It retrieves the voice, model, API endpoint, and access token from the config, and sets the appropriate headers required by the ElevenLabs API. If any required configuration is missing, an exception is thrown.

Parameters
$driver : Driver = new GuzzleDriver()

An instance of a class implementing the Driver contract.

Tags
throws
InvalidArgumentException

if required configuration values are missing.

driver()

Accesses the injected Driver instance.

public driver() : Driver
Return values
Driver

the Driver instance stored in this instance of the class.

driverClass()

Retrieves the class name of the default associated driver.

public driverClass() : string
Return values
string

getDriver()

Retrieves the current driver.

public getDriver() : Driver
Return values
Driver

The current driver instance.

getModel()

Retrieves the current model identifier.

public getModel() : mixed
Return values
mixed

The current model identifier.

getPrompt()

Retrieves the current prompt input.

public getPrompt() : mixed
Return values
mixed

The current prompt.

output()

Executes the API request and returns the stored output.

public output([bool $json = true ]) : mixed

Internally calls the store() method to process and save the audio output.

Parameters
$json : bool = true

(Optional) If true, returns a JSON-encoded string of file metadata.

Return values
mixed

The file metadata or JSON-encoded string, depending on the $json parameter.

promptClass()

Retrieves the class name of the default associated prompt.

public promptClass() : string
Return values
string

raw()

Retrieves the raw response from the driver.

public raw() : mixed
Return values
mixed

The raw response body.

setModel()

Sets the model for the pipeline.

public setModel(mixed $model) : self

Assigns the given model to the pipeline and updates the underlying driver's request payload.

Parameters
$model : mixed

The model identifier to be used.

Return values
self

setPrompt()

Sets the prompt for the pipeline.

public setPrompt(IVFSprompt $prompt) : self

Expects an IVFSprompt instance. The method sets default voice settings if none are provided, extracts the input from the prompt, updates the driver's prompt (using a key "text"), and modifies the API endpoint by replacing the {voice} placeholder with the prompt's voice value or the default voice. It also converts the prompt's settings to a standard object and updates the driver's request with voice settings.

Parameters
$prompt : IVFSprompt

An instance of IVFSprompt.

Tags
throws
InvalidArgumentException

If the provided prompt is not an IVFSprompt.

Return values
self

store()

Stores the audio output as a file.

public store([bool $json = false ]) : mixed

Generates a UUID-based filename with the defined file type (default "mp3"), uses the driver's fileMake method to save the audio data, and returns the file metadata.

Parameters
$json : bool = false

(Optional) If true, returns JSON-encoded file metadata.

Return values
mixed

The file metadata array or its JSON-encoded representation.

stream()

Executes a streaming API request.

public stream() : Generator

This pipeline does not support stream mode. Calling this method will always throw an exception.

Tags
throws
Exception

Always throws an exception indicating that stream mode is not supported.

Return values
Generator

        
On this page

Search results