5555use Symfony \AI \Platform \Bridge \Cerebras \PlatformFactory as CerebrasPlatformFactory ;
5656use Symfony \AI \Platform \Bridge \DeepSeek \PlatformFactory as DeepSeekPlatformFactory ;
5757use Symfony \AI \Platform \Bridge \DockerModelRunner \PlatformFactory as DockerModelRunnerPlatformFactory ;
58+ use Symfony \AI \Platform \Bridge \ElevenLabs \ElevenLabsSpeechProvider ;
5859use Symfony \AI \Platform \Bridge \ElevenLabs \PlatformFactory as ElevenLabsPlatformFactory ;
5960use Symfony \AI \Platform \Bridge \Gemini \PlatformFactory as GeminiPlatformFactory ;
6061use Symfony \AI \Platform \Bridge \HuggingFace \PlatformFactory as HuggingFacePlatformFactory ;
7677use Symfony \AI \Platform \Platform ;
7778use Symfony \AI \Platform \PlatformInterface ;
7879use Symfony \AI \Platform \ResultConverterInterface ;
80+ use Symfony \AI \Platform \Speech \SpeechConfiguration ;
81+ use Symfony \AI \Platform \Speech \SpeechProviderInterface ;
7982use Symfony \AI \Store \Bridge \Azure \SearchStore as AzureSearchStore ;
8083use Symfony \AI \Store \Bridge \ChromaDb \Store as ChromaDbStore ;
8184use Symfony \AI \Store \Bridge \ClickHouse \Store as ClickHouseStore ;
104107use Symfony \AI \Store \IndexerInterface ;
105108use Symfony \AI \Store \ManagedStoreInterface ;
106109use Symfony \AI \Store \StoreInterface ;
107- use Symfony \AI \Voice \Bridge \ElevenLabs \ElevenLabsSpeechProvider as ElevenLabsVoiceProvider ;
108- use Symfony \AI \Voice \VoiceProviderInterface ;
109110use Symfony \Component \Clock \ClockInterface ;
110111use Symfony \Component \Config \Definition \Configurator \DefinitionConfigurator ;
111112use Symfony \Component \DependencyInjection \Attribute \Target ;
@@ -253,7 +254,12 @@ public function loadExtension(array $config, ContainerConfigurator $container, C
253254 }
254255
255256 foreach ($ config ['voice ' ] as $ voiceProvider => $ provider ) {
256- $ this ->processVoiceProviderConfig ($ voiceProvider , $ provider , $ builder );
257+ $ this ->processSpeechConfig ($ voiceProvider , $ provider , $ builder );
258+ }
259+
260+ $ speechProviders = array_keys ($ builder ->findTaggedServiceIds ('ai.speech_provider ' ));
261+ if ([] === $ speechProviders ) {
262+ $ builder ->removeDefinition ('ai.speech_provider.listener ' );
257263 }
258264
259265 foreach ($ config ['vectorizer ' ] ?? [] as $ vectorizerName => $ vectorizer ) {
@@ -422,11 +428,9 @@ private function processPlatformConfig(string $type, array $platform, ContainerB
422428 }
423429
424430 if ('eleven_labs ' === $ type ) {
425- $ platformId = 'ai.platform.eleven_labs ' ;
426431 $ definition = (new Definition (Platform::class))
427432 ->setFactory (ElevenLabsPlatformFactory::class.'::create ' )
428433 ->setLazy (true )
429- ->addTag ('proxy ' , ['interface ' => PlatformInterface::class])
430434 ->setArguments ([
431435 $ platform ['api_key ' ],
432436 $ platform ['host ' ],
@@ -435,9 +439,10 @@ private function processPlatformConfig(string $type, array $platform, ContainerB
435439 null ,
436440 new Reference ('event_dispatcher ' ),
437441 ])
442+ ->addTag ('proxy ' , ['interface ' => PlatformInterface::class])
438443 ->addTag ('ai.platform ' , ['name ' => 'eleven_labs ' ]);
439444
440- $ container ->setDefinition ($ platformId , $ definition );
445+ $ container ->setDefinition (' ai.platform.eleven_labs ' , $ definition );
441446
442447 return ;
443448 }
@@ -1837,23 +1842,33 @@ private function processChatConfig(string $name, array $configuration, Container
18371842 /**
18381843 * @param array<string, mixed> $providers
18391844 */
1840- private function processVoiceProviderConfig (string $ name , array $ providers , ContainerBuilder $ container ): void
1845+ private function processSpeechConfig (string $ name , array $ providers , ContainerBuilder $ container ): void
18411846 {
18421847 if ('eleven_labs ' === $ name ) {
1843- foreach ($ providers as $ type => $ config ) {
1848+ foreach ($ providers as $ config ) {
1849+ $ configurationDefinition = new Definition (SpeechConfiguration::class);
1850+ $ configurationDefinition
1851+ ->setLazy (true )
1852+ ->setArguments ([
1853+ $ config ['tts_model ' ],
1854+ $ config ['tts_voice ' ],
1855+ $ config ['stt_model ' ],
1856+ ]);
1857+
1858+ $ container ->setDefinition ('ai.speech.eleven_labs.configuration ' , $ configurationDefinition );
1859+
18441860 $ definition = new Definition (ElevenLabsSpeechProvider::class);
18451861 $ definition
18461862 ->setLazy (true )
18471863 ->setArguments ([
18481864 new Reference ('ai.platform.eleven_labs ' ),
1849- $ config [ ' model ' ] ,
1865+ new Reference ( ' ai.speech.eleven_labs.configuration ' ) ,
18501866 ])
1851- ->addTag ('proxy ' , ['interface ' => VoiceProviderInterface::class])
1852- ->addTag ('ai.voice.provider ' );
1867+ ->addTag ('proxy ' , ['interface ' => SpeechProviderInterface::class])
1868+ ->addTag ('kernel.event_subscriber ' )
1869+ ->addTag ('ai.speech_provider ' );
18531870
1854- $ container ->setDefinition ('ai.voice.eleven_labs. ' .$ name , $ definition );
1855- $ container ->registerAliasForArgument ('ai.voice. ' .$ type .'. ' .$ name , VoiceProviderInterface::class, $ name );
1856- $ container ->registerAliasForArgument ('ai.voice. ' .$ type .'. ' .$ name , VoiceProviderInterface::class, $ type .'_ ' .$ name );
1871+ $ container ->setDefinition ('ai.speech.eleven_labs. ' .$ name , $ definition );
18571872 }
18581873 }
18591874 }
0 commit comments