AudioTTS implements Pipeline
Implements an OpenAI TTS pipeline for audio generation.
This pipeline uses an underlying driver (default: GuzzleDriver) to communicate with the OpenAI API for text-to-speech generation. It sets the model and API endpoint based on configuration, applies required HTTP headers including the access token, and expects an IVFSprompt instance to configure the request. The resulting audio output is stored as a file (with a UUID-based filename).
You can find available voices at: https://platform.openai.com/docs/guides/text-to-speech They include: alloy, ash, coral, echo, fable, onyx, nova, sage, shimmer
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 OpenAI access token retrieved from configuration.
- $driver : GuzzleDriver
- The driver instance used for HTTP requests.
- $fileType : string
- The output file type (e.g., "mp3").
- $model : mixed
- The model identifier used for the API request.
- $prompt : mixed
- The prompt input, extracted from an IVFSprompt instance.
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 API response.
- setModel() : self
- Sets the model for the pipeline.
- setPrompt() : self
- Sets the prompt for the pipeline.
- store() : mixed
- Executes the API request, stores the audio output as a file, and returns file metadata.
- stream() : Generator
- Executes a streaming API request.
Properties
$accessToken
The OpenAI access token retrieved from configuration.
protected
mixed
$accessToken
$driver
The driver instance used for HTTP requests.
protected
GuzzleDriver
$driver
$fileType
The output file type (e.g., "mp3").
protected
string
$fileType
$model
The model identifier used for the API request.
protected
mixed
$model
$prompt
The prompt input, extracted from an IVFSprompt instance.
protected
mixed
$prompt
Methods
__construct()
AudioTTS constructor.
public
__construct([Driver $driver = new GuzzleDriver() ]) : mixed
Retrieves configuration values for the API endpoint, model, and access token, sets up the underlying driver, and configures necessary HTTP headers. Throws an exception if any required configuration value is missing.
Parameters
- $driver : Driver = new GuzzleDriver()
-
An instance implementing the Driver contract.
Tags
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
stringgetDriver()
Retrieves the current driver.
public
getDriver() : Driver
Return values
Driver —The driver instance.
getModel()
Retrieves the current model identifier.
public
getModel() : mixed
Return values
mixed —The model identifier.
getPrompt()
Retrieves the current prompt input.
public
getPrompt() : mixed
Return values
mixed —The prompt input.
output()
Executes the API request and returns the stored output.
public
output([bool $json = true ]) : mixed
This method is an alias for the store() method.
Parameters
- $json : bool = true
-
Optional. If true, returns JSON-encoded file metadata.
Return values
mixed —The file metadata or its JSON-encoded representation.
promptClass()
Retrieves the class name of the default associated prompt.
public
promptClass() : string
Return values
stringraw()
Retrieves the raw API response.
public
raw() : mixed
Return values
mixed —The raw audio data.
setModel()
Sets the model for the pipeline.
public
setModel(mixed $model) : self
Updates both the pipeline property and the driver's request payload.
Parameters
- $model : mixed
-
The model identifier.
Return values
selfsetPrompt()
Sets the prompt for the pipeline.
public
setPrompt(IVFSprompt $prompt) : self
Expects an IVFSprompt instance. Extracts input, voice, and format from the prompt, configures the driver's prompt, and updates the request with the appropriate voice and response_format parameters. Also stores the file type based on the prompt format.
Parameters
- $prompt : IVFSprompt
-
An IVFSprompt instance.
Tags
Return values
selfstore()
Executes the API request, stores the audio output as a file, and returns file metadata.
public
store([bool $json = false ]) : mixed
Generates a UUID-based filename with the defined file type, saves the audio data using the driver's fileMake method, and returns metadata about the stored file.
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 streaming mode.