@@ -501,8 +501,58 @@ This allows fast and isolated testing of AI-powered features without relying on
501501
502502 This requires `cURL ` and the `ext-curl ` extension to be installed.
503503
504- Adding Voice
505- ~~~~~~~~~~~~
504+ Speech support
505+ ~~~~~~~~~~~~~~
506+
507+ Using speech to send messages / receive answers as audio is a common use case when integrating agents and/or chats.
508+
509+ Speech support can be enable using ``Symfony\AI\Platform\Speech\SpeechProviderListener ``::
510+
511+ use Symfony\AI\Agent\Agent;
512+ use Symfony\AI\Platform\Bridge\ElevenLabs\ElevenLabsSpeechProvider;
513+ use Symfony\AI\Platform\Bridge\ElevenLabs\PlatformFactory;
514+ use Symfony\AI\Platform\Bridge\OpenAi\PlatformFactory as OpenAiPlatformFactory;
515+ use Symfony\AI\Platform\Message\Message;
516+ use Symfony\AI\Platform\Message\MessageBag;
517+ use Symfony\AI\Platform\Speech\SpeechConfiguration;
518+ use Symfony\AI\Platform\Speech\SpeechProviderListener;
519+ use Symfony\Component\EventDispatcher\EventDispatcher;
520+
521+ $eventDispatcher = new EventDispatcher();
522+ $eventDispatcher->addSubscriber(new SpeechProviderListener([
523+ new ElevenLabsSpeechProvider(PlatformFactory::create(
524+ apiKey: $elevenLabsApiKey,
525+ httpClient: http_client(),
526+ speechConfiguration: new SpeechConfiguration(
527+ ttsModel: 'eleven_multilingual_v2',
528+ ttsVoice: 'Dslrhjl3ZpzrctukrQSN', // Brad (https://elevenlabs.io/app/voice-library?voiceId=Dslrhjl3ZpzrctukrQSN)
529+ sttModel: 'eleven_multilingual_v2'
530+ )),
531+ ),
532+ ], []));
533+
534+ $platform = OpenAiPlatformFactory::create($openAiApiKey, httpClient: HttpClient::create(), eventDispatcher: $eventDispatcher);
535+
536+ $agent = new Agent($platform, 'gpt-4o');
537+ $answer = $agent->call(new MessageBag(
538+ Message::ofUser('Tina has one brother and one sister. How many sisters do Tina\'s siblings have?'),
539+ ));
540+
541+ echo $answer->getSpeech('eleven_labs')->asBinary();
542+
543+ When using the bundle, the configuration allows to configure models and voices::
544+
545+ ai:
546+ platform:
547+ eleven_labs:
548+ api_key: '%env(ELEVEN_LABS_API_KEY)%'
549+
550+ speech:
551+ eleven_labs:
552+ tts_model: 'eleven_multilingual_v2'
553+ tts_voice: '%env(ELEVEN_LABS_VOICE_IDENTIFIER)%'
554+ tts_extra_options:
555+ foo: bar
506556
507557Code Examples
508558~~~~~~~~~~~~~
0 commit comments