Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/phpaisdk/fal/llms.txt

Use this file to discover all available pages before exploring further.

FalSpeechModel makes two HTTP calls on your behalf: first, a POST to {baseUrl}/{modelId} (defaulting to https://fal.run/{modelId}) to request speech synthesis and receive an audio URL from fal.ai; then, a GET to that URL to download the raw audio bytes. Both steps are handled automatically inside run() — your code receives a fully populated SpeechResponse with the audio data already fetched and ready to use.

Basic Usage

use AiSdk\Generate;
use AiSdk\Fal;

$result = Generate::speech()
    ->model(Fal::model('fal-ai/minimax/speech-02-hd'))
    ->input('Hello, world!')
    ->run();

// $result->audio->data contains the raw audio bytes
file_put_contents('output.mp3', $result->audio->data);

Request Parameters

The following fields are sent as JSON to the fal.ai endpoint:
FieldTypeSourceDescription
textstring$request->inputThe text to synthesize into speech.
voicestring$request->voiceThe voice identifier to use for synthesis.
Additional fields from $request->providerOptionsFor('fal') are merged into the body, allowing you to pass any model-specific parameters supported by the fal.ai endpoint.

Response

generate() returns a SpeechResponse with an audio property of type AudioData:
  • data (string) — the raw audio bytes, downloaded directly from the URL returned by fal.ai.
  • mimeType (string) — taken from audio.content_type in the fal.ai response; defaults to audio/mpeg when the API omits it.
A RuntimeException is thrown if fal.ai does not return a valid audio URL in the synthesis response. This can occur if the model rejects the input text or if the request payload is malformed.

Saving Audio

The audio->data property contains the raw bytes of the audio file and can be written directly to disk or streamed to the client:
$result = Generate::speech()
    ->model(Fal::model('fal-ai/minimax/speech-02-hd'))
    ->input('The quick brown fox jumps over the lazy dog.')
    ->run();

// Write raw bytes to a file
file_put_contents('output.mp3', $result->audio->data);

// Or inspect the MIME type before saving
echo $result->audio->mimeType; // audio/mpeg

Provider Options

Pass model-specific parameters using providerOptions():
$result = Generate::speech()
    ->model(Fal::model('fal-ai/minimax/speech-02-hd'))
    ->input('Hello, world!')
    ->providerOptions('fal', ['speed' => 1.2])
    ->run();

Build docs developers (and LLMs) love