@@ -532,6 +532,64 @@ This allows fast and isolated testing of AI-powered features without relying on
532532
533533 This requires `cURL ` and the `ext-curl ` extension to be installed.
534534
535+ Speech support
536+ ~~~~~~~~~~~~~~
537+
538+ Using speech to send messages / receive answers as audio is a common use case when integrating agents and/or chats.
539+
540+ Speech support can be enable using ``Symfony\AI\Platform\Speech\SpeechProviderListener ``::
541+
542+ use Symfony\AI\Agent\Agent;
543+ use Symfony\AI\Platform\Bridge\ElevenLabs\ElevenLabsSpeechProvider;
544+ use Symfony\AI\Platform\Bridge\ElevenLabs\PlatformFactory;
545+ use Symfony\AI\Platform\Bridge\OpenAi\PlatformFactory as OpenAiPlatformFactory;
546+ use Symfony\AI\Platform\Message\Message;
547+ use Symfony\AI\Platform\Message\MessageBag;
548+ use Symfony\AI\Platform\Speech\SpeechConfiguration;
549+ use Symfony\AI\Platform\Speech\SpeechProviderListener;
550+ use Symfony\Component\EventDispatcher\EventDispatcher;
551+
552+ $eventDispatcher = new EventDispatcher();
553+ $eventDispatcher->addSubscriber(new SpeechProviderListener([
554+ new ElevenLabsSpeechProvider(PlatformFactory::create(
555+ apiKey: $elevenLabsApiKey,
556+ httpClient: http_client(),
557+ speechConfiguration: new SpeechConfiguration(
558+ ttsModel: 'eleven_multilingual_v2',
559+ ttsVoice: 'Dslrhjl3ZpzrctukrQSN', // Brad (https://elevenlabs.io/app/voice-library?voiceId=Dslrhjl3ZpzrctukrQSN)
560+ sttModel: 'eleven_multilingual_v2'
561+ )),
562+ ),
563+ ], []));
564+
565+ $platform = OpenAiPlatformFactory::create($openAiApiKey, httpClient: HttpClient::create(), eventDispatcher: $eventDispatcher);
566+
567+ $agent = new Agent($platform, 'gpt-4o');
568+ $answer = $agent->call(new MessageBag(
569+ Message::ofUser('Tina has one brother and one sister. How many sisters do Tina\'s siblings have?'),
570+ ));
571+
572+ echo $answer->getSpeech('elevenlabs')->asBinary();
573+
574+ When using the bundle, the configuration allows to configure models and voices::
575+
576+ ai:
577+ platform:
578+ elevenlabs:
579+ api_key: '%env(ELEVEN_LABS_API_KEY)%'
580+
581+ speech:
582+ elevenlabs:
583+ platform: 'ai.platform.elevenlabs'
584+ tts_model: 'eleven_multilingual_v2'
585+ tts_voice: '%env(ELEVEN_LABS_VOICE_IDENTIFIER)%'
586+ tts_extra_options:
587+ foo: bar
588+
589+ .. note ::
590+
591+ Please be aware that enabling speech support requires to define corresponding platforms.
592+
535593Code Examples
536594~~~~~~~~~~~~~
537595
0 commit comments