Audio
Text-to-speech (TTS) and speech-to-text (STT) capabilities for voice-enabled applications.
Prism Reference
Atlas audio wraps Prism's audio API. For detailed documentation including all provider options, see Prism Audio.
Text to Speech
Convert text to spoken audio:
php
use Atlasphp\Atlas\Atlas;
$response = Atlas::audio()
->using('openai', 'tts-1')
->withVoice('nova')
->fromText('Hello, welcome to our service!')
->asAudio();
// Save audio file
Storage::put('welcome.mp3', $response->audio);Speech to Text
Transcribe audio to text:
php
$response = Atlas::audio()
->using('openai', 'whisper-1')
->fromFile('/path/to/audio.mp3')
->asText();
echo $response->text; // Transcribed textText-to-Speech Examples
With Voice Selection
php
$response = Atlas::audio()
->using('openai', 'tts-1')
->withVoice('onyx') // Deep, authoritative voice
->fromText('Important announcement.')
->asAudio();OpenAI voices: alloy, echo, fable, onyx, nova, shimmer
HD Quality
php
$response = Atlas::audio()
->using('openai', 'tts-1-hd')
->withVoice('alloy')
->fromText('High-definition audio quality.')
->asAudio();Speech-to-Text Examples
Basic Transcription
php
$response = Atlas::audio()
->using('openai', 'whisper-1')
->fromFile($request->file('audio')->path())
->asText();
return response()->json([
'text' => $response->text,
]);With Language Hint
php
$response = Atlas::audio()
->using('openai', 'whisper-1')
->fromFile('/path/to/audio.mp3')
->withProviderMeta('openai', ['language' => 'en'])
->asText();Complete Examples
Voice Notification Service
php
class NotificationService
{
public function sendVoiceNotification(User $user, string $message): void
{
$response = Atlas::audio()
->using('openai', 'tts-1')
->withVoice('nova')
->fromText($message)
->asAudio();
$filename = 'notifications/' . Str::uuid() . '.mp3';
Storage::put($filename, $response->audio);
$this->voiceService->call($user->phone, Storage::url($filename));
}
}Meeting Transcription
php
class MeetingService
{
public function processRecording(string $audioPath): array
{
// Transcribe
$transcription = Atlas::audio()
->using('openai', 'whisper-1')
->fromFile($audioPath)
->asText();
// Summarize with AI
$summary = Atlas::agent('summarizer')
->chat("Summarize this meeting transcript:\n\n{$transcription->text}");
return [
'transcript' => $transcription->text,
'summary' => $summary->text,
];
}
}Voice Characteristics
| Voice | Description |
|---|---|
alloy | Neutral, balanced |
echo | Clear, confident |
fable | Warm, expressive |
onyx | Deep, authoritative |
nova | Friendly, natural |
shimmer | Clear, energetic |
Pipeline Hooks
Audio operations support pipeline middleware for observability:
| Pipeline | Trigger |
|---|---|
audio.before_audio | Before text-to-speech |
audio.after_audio | After text-to-speech |
audio.before_text | Before speech-to-text |
audio.after_text | After speech-to-text |
php
use Atlasphp\Atlas\Contracts\PipelineContract;
class LogAudioGeneration implements PipelineContract
{
public function handle(mixed $data, Closure $next): mixed
{
$result = $next($data);
Log::info('Audio generated', [
'user_id' => $data['metadata']['user_id'] ?? null,
]);
return $result;
}
}
$registry->register('audio.after_audio', LogAudioGeneration::class);Next Steps
- Prism Audio — Complete audio reference
- Chat — Combine with chat for voice assistants
- Pipelines — Add observability to audio operations