Description
Currently, symfony/ai provides abstractions for request-response completion, token streaming (Capability::OUTPUT_STREAMING), speech-to-text (Whisper), and text-to-speech (Capability::OUTPUT_AUDIO).
However, providers such as OpenAI and Azure OpenAI now offer Realtime APIs for low-latency, bidirectional speech-to-speech voice sessions over WebRTC / WebSockets.
Proposed Solution
Instead of proxying heavy WebRTC audio streams through PHP, Symfony acts as the secure session broker & ephemeral credential minter:
- Add
Capability::REALTIME_SESSION to Symfony\AI\Platform\Capability.
- Add
RealtimeSessionResult ($result->getClientSecret(), $result->getExpiresAt(), $result->getId(), $result->getModel()).
- Add
Realtime model class in Symfony\AI\Platform\Bridge\OpenAi.
- Implement
ModelClient for POST /v1/realtime/sessions and ResultConverter converting responses to RealtimeSessionResult.
- Register realtime models (
gpt-4o-realtime-preview, etc.) in the OpenAI ModelCatalog and Factory.
Example Usage
use Symfony\AI\Platform\Bridge\OpenAi\Realtime;
use Symfony\AI\Platform\Bridge\OpenAi\Factory;
$platform = Factory::createPlatform($_ENV['OPENAI_API_KEY']);
$result = $platform->invoke(
new Realtime('gpt-4o-realtime-preview'),
'You are a customer support agent.',
[
'voice' => 'alloy',
'modalities' => ['text', 'audio'],
'turn_detection' => ['type' => 'server_vad'],
]
);
$session = $result->getResult(); // RealtimeSessionResult
return new JsonResponse([
'client_secret' => $session->getClientSecret(),
'expires_at' => $session->getExpiresAt(),
'session_id' => $session->getId(),
]);
Description
Currently,
symfony/aiprovides abstractions for request-response completion, token streaming (Capability::OUTPUT_STREAMING), speech-to-text (Whisper), and text-to-speech (Capability::OUTPUT_AUDIO).However, providers such as OpenAI and Azure OpenAI now offer Realtime APIs for low-latency, bidirectional speech-to-speech voice sessions over WebRTC / WebSockets.
Proposed Solution
Instead of proxying heavy WebRTC audio streams through PHP, Symfony acts as the secure session broker & ephemeral credential minter:
Capability::REALTIME_SESSIONtoSymfony\AI\Platform\Capability.RealtimeSessionResult($result->getClientSecret(),$result->getExpiresAt(),$result->getId(),$result->getModel()).Realtimemodel class inSymfony\AI\Platform\Bridge\OpenAi.ModelClientforPOST /v1/realtime/sessionsandResultConverterconverting responses toRealtimeSessionResult.gpt-4o-realtime-preview, etc.) in the OpenAIModelCatalogandFactory.Example Usage