IVFSprompt extends BasicPrompt
IVFSprompt stands for "Input, Voice, Format, Settings" and is designed for TTS (Text-to-Speech) pipelines.
IVFSprompt handles the construction and deconstruction of prompt data for TTS operations, allowing configuration of input text, voice selection, output format, and additional settings. The encoder builds a custom VFS block appended to the input, while the decoder extracts these parameters from a JSON-encoded prompt.
Table of Contents
Methods
- __construct() : mixed
- IVFSprompt constructor.
- getFormat() : mixed
- Retrieves the output format for the TTS prompt.
- getInput() : mixed
- Retrieves the input text for the TTS prompt.
- getPrompt() : string
- Gets the prompt text.
- getSettings() : mixed
- Retrieves the additional settings for the TTS prompt.
- getVoice() : mixed
- Retrieves the voice setting for the TTS prompt.
- promptDecode() : static
- Decodes a JSON-encoded prompt string into a BasicPrompt instance.
- promptEncode() : string
- Encodes the prompt data into a JSON string.
- setFormat() : $this
- Sets the output format for the TTS prompt.
- setInput() : $this
- Sets the input text for the TTS prompt.
- setPrompt() : $this
- Sets the prompt text.
- settings() : $this
- Sets additional settings for the TTS prompt.
- setVoice() : $this
- Sets the voice for the TTS prompt.
- decoder() : void
- Decodes a JSON-encoded prompt string and extracts TTS parameters.
- encoder() : string
- Encodes the TTS prompt parameters into a JSON string.
Methods
__construct()
IVFSprompt constructor.
public
__construct() : mixed
Initializes the prompt with default TTS parameters:
- input: "Say this sentence out loud."
- voice: null (no default voice)
- format: "mp3"
- settings: an empty array
getFormat()
Retrieves the output format for the TTS prompt.
public
getFormat() : mixed
Return values
mixed —The output format.
getInput()
Retrieves the input text for the TTS prompt.
public
getInput() : mixed
Return values
mixed —The input text.
getPrompt()
Gets the prompt text.
public
getPrompt() : string
Return values
string —$this Returns the current prompt string.
getSettings()
Retrieves the additional settings for the TTS prompt.
public
getSettings() : mixed
Return values
mixed —The settings array.
getVoice()
Retrieves the voice setting for the TTS prompt.
public
getVoice() : mixed
Return values
mixed —The voice identifier.
promptDecode()
Decodes a JSON-encoded prompt string into a BasicPrompt instance.
public
static promptDecode(string $promptString) : static
This static method creates a new instance of BasicPrompt, decodes the provided JSON string, and sets the prompt data accordingly.
Parameters
- $promptString : string
-
JSON-encoded prompt string.
Return values
static —A new instance of BasicPrompt with the decoded prompt data.
promptEncode()
Encodes the prompt data into a JSON string.
public
promptEncode() : string
This method utilizes the internal encoder to transform the prompt stored in the collection into a JSON representation.
Return values
string —JSON-encoded prompt data.
setFormat()
Sets the output format for the TTS prompt.
public
setFormat(string $string) : $this
Parameters
- $string : string
-
The output format (e.g., "mp3").
Return values
$this —Returns the current instance for method chaining.
setInput()
Sets the input text for the TTS prompt.
public
setInput(string $string) : $this
Parameters
- $string : string
-
The input text.
Return values
$this —Returns the current instance for method chaining.
setPrompt()
Sets the prompt text.
public
setPrompt(string $prompt) : $this
Stores the provided prompt text in the collection under the key "prompt".
Parameters
- $prompt : string
-
The prompt text.
Return values
$this —Returns the current instance for method chaining.
settings()
Sets additional settings for the TTS prompt.
public
settings(array<string|int, mixed> $keyValueArray) : $this
Parameters
- $keyValueArray : array<string|int, mixed>
-
An associative array of settings.
Return values
$this —Returns the current instance for method chaining.
setVoice()
Sets the voice for the TTS prompt.
public
setVoice(string $string) : $this
Parameters
- $string : string
-
The voice identifier.
Return values
$this —Returns the current instance for method chaining.
decoder()
Decodes a JSON-encoded prompt string and extracts TTS parameters.
protected
decoder(string $prompt) : void
Extracts the VFS block from the prompt using a regular expression, splits it to obtain the voice, format, and settings values, and then updates the prompt using the corresponding setter methods.
Parameters
- $prompt : string
-
The JSON-encoded prompt string.
encoder()
Encodes the TTS prompt parameters into a JSON string.
protected
encoder() : string
Constructs a custom formatted string using the following pattern: "{{VFS:voice,format,settings}}", where the settings are concatenated as key|value pairs. This string is appended to the input text, and then the complete prompt is JSON-encoded.
Return values
string —The JSON-encoded representation of the prompt.