Vizra ADK is in maintenance mode. It continues to work and receives compatibility fixes, but no new features are planned. For evaluating AI agents — now built on the official Laravel AI SDK — check out Vizra Evals, its successor for the evaluation use-case. Coming from ADK? See the migration guide.
The AudioAgent provides text-to-speech (TTS) capabilities using AI models through Prism PHP. Convert any text into natural-sounding speech with multiple voice options and audio formats.
Quick Start
Generate speech from text with just a few lines of code:
use Vizra\VizraADK\Agents\AudioAgent;// Simple TTS generation$audio = AudioAgent::run('Welcome to our application')->go();// Save the audio$audio->storeAs('welcome.mp3');// Get the URL$url = $audio->url();
Voice Selection
Choose from six distinct AI voices, each with their own character:
// Using the voice() method$audio = AudioAgent::run('Hello world') ->voice('nova') ->go();// Using voice preset methods$audio = AudioAgent::run('Hello world') ->shimmer() ->go();
Available Voices
Voice
Description
alloy
Balanced, neutral voice (default)
echo
Warm, conversational tone
fable
Expressive, storytelling style
onyx
Deep, authoritative voice
nova
Friendly, energetic delivery
shimmer
Clear, professional sound
Each voice has a shortcut method: alloy(), echo(), fable(), onyx(), nova(), shimmer().
Audio Formats
Select your preferred output format based on your use case:
$audio = AudioAgent::run('Your order has been confirmed') ->format('wav') ->go();
Supported Formats
Format
Use Case
mp3
Web playback, general use (default)
wav
High quality, editing workflows
opus
Streaming, low latency
aac
iOS/Safari compatibility
flac
Lossless archival
Speech Speed
Adjust the speaking rate between 0.25x and 4.0x:
// Slower for accessibility$audio = AudioAgent::run('Important instructions') ->speed(0.8) ->go();// Faster for summaries$audio = AudioAgent::run('Quick recap of today') ->speed(1.5) ->go();
Model Selection
Override the default model for different quality/speed tradeoffs:
// Use HD model for higher quality$audio = AudioAgent::run('Premium narration content') ->using('openai', 'tts-1-hd') ->go();// Use mini model for faster generation$audio = AudioAgent::run('Quick notification') ->using('openai', 'gpt-4o-mini-tts') ->go();
Available Models
Model
Description
tts-1
Standard quality, faster generation (default)
tts-1-hd
Higher quality, slower generation
gpt-4o-mini-tts
Latest model with enhanced capabilities
Storage
Auto-store with Custom Filename
$audio = AudioAgent::run('Welcome message') ->voice('nova') ->storeAs('welcome.mp3') ->go();echo $audio->url(); // Returns the stored file URLecho $audio->path(); // Returns the storage path
$audio = AudioAgent::run('Hello world')->go();// Store with custom filename$audio->storeAs('greetings/hello.mp3');// Or auto-generate filename$audio->store();
Working with AudioResponse
The AudioResponse object provides methods to access and manipulate the generated audio:
$audio = AudioAgent::run('Sample text') ->nova() ->format('mp3') ->go();// Access audio data$audio->data(); // Raw binary audio data$audio->base64(); // Base64-encoded audio$audio->toDataUri(); // Data URI for embedding (data:audio/mpeg;base64,...)// Metadata$audio->text(); // Original input text$audio->voice(); // Voice used (e.g., 'nova')$audio->format(); // Format (e.g., 'mp3')$audio->mimeType(); // MIME type (e.g., 'audio/mpeg')$audio->metadata(); // Full metadata array// Storage status$audio->isStored(); // Check if audio was stored$audio->url(); // Get URL (stored or data URI)$audio->path(); // Get storage path$audio->disk(); // Get storage disk used
Embedding in HTML
$audio = AudioAgent::run('Play this message')->go();// Using data URI (no storage needed)$html = '<audio controls src="' . $audio->toDataUri() . '"></audio>';// Using stored URL$audio->store();$html = '<audio controls src="' . $audio->url() . '"></audio>';
Async/Queued Generation
For long-running generations or batch processing, use Laravel queues:
// Basic async generationAudioAgent::run('Long article content here...') ->onQueue('media') ->go();// With callback after completionAudioAgent::run('Order confirmation for order #12345') ->shimmer() ->format('mp3') ->onQueue('media') ->then(function ($audio) { $audio->storeAs('confirmations/order-12345.mp3'); // Send notification, update database, etc. Notification::send($user, new AudioReadyNotification($audio->url())); }) ->go();
Queue Options
AudioAgent::run('Background audio task') ->onQueue('media') // Specify queue name ->delay(60) // Delay in seconds ->tries(5) // Retry attempts ->timeout(180) // Timeout in seconds ->then(fn($audio) => $audio->store()) ->go();
Async Return Value
When using async mode, go() returns job information instead of the audio:
Allow your LLM agents to generate audio by delegating to the AudioAgent:
use Vizra\VizraADK\Agents\BaseLlmAgent;use Vizra\VizraADK\Tools\DelegateToMediaAgentTool;class AssistantAgent extends BaseLlmAgent{ protected string $name = 'assistant'; protected string $instructions = <<<'PROMPT' You are a helpful assistant. When the user asks you to read something aloud or create audio, use the generate_audio tool to convert text to speech. PROMPT; protected array $tools = [ DelegateToMediaAgentTool::class, ]; protected array $mediaAgents = [ \Vizra\VizraADK\Agents\AudioAgent::class, ];}
Or create the tool directly:
use Vizra\VizraADK\Tools\DelegateToMediaAgentTool;class NarratorAgent extends BaseLlmAgent{ protected function tools(): array { return [ DelegateToMediaAgentTool::forAudio(), ]; }}
When the LLM calls the generate_audio tool, it can specify:
text (required): The text to convert to speech
voice (optional): Voice selection
format (optional): Output format
Configuration
Environment Variables
# Provider and modelVIZRA_ADK_AUDIO_PROVIDER=openaiVIZRA_ADK_AUDIO_MODEL=tts-1# DefaultsVIZRA_ADK_AUDIO_VOICE=alloyVIZRA_ADK_AUDIO_FORMAT=mp3VIZRA_ADK_AUDIO_SPEED=1.0