|
| 1 | +<?php |
| 2 | + |
| 3 | +/* |
| 4 | + * This file is part of the Symfony package. |
| 5 | + * |
| 6 | + * (c) Fabien Potencier <fabien@symfony.com> |
| 7 | + * |
| 8 | + * For the full copyright and license information, please view the LICENSE |
| 9 | + * file that was distributed with this source code. |
| 10 | + */ |
| 11 | + |
| 12 | +use Symfony\AI\Agent\Agent; |
| 13 | +use Symfony\AI\Platform\Bridge\ElevenLabs\ElevenLabsSpeechListener; |
| 14 | +use Symfony\AI\Platform\Bridge\ElevenLabs\ElevenLabsSpeechProvider; |
| 15 | +use Symfony\AI\Platform\Bridge\ElevenLabs\PlatformFactory; |
| 16 | +use Symfony\AI\Platform\Bridge\OpenAi\PlatformFactory as OpenAiPlatformFactory; |
| 17 | +use Symfony\AI\Platform\Message\Content\Audio; |
| 18 | +use Symfony\AI\Platform\Message\Message; |
| 19 | +use Symfony\AI\Platform\Message\MessageBag; |
| 20 | +use Symfony\AI\Platform\Speech\SpeechConfiguration; |
| 21 | +use Symfony\AI\Platform\Speech\SpeechProviderListener; |
| 22 | +use Symfony\Component\EventDispatcher\EventDispatcher; |
| 23 | + |
| 24 | +require_once dirname(__DIR__).'/bootstrap.php'; |
| 25 | + |
| 26 | +$eventDispatcher = new EventDispatcher(); |
| 27 | +$eventDispatcher->addSubscriber(new SpeechProviderListener([ |
| 28 | + new ElevenLabsSpeechProvider(PlatformFactory::create( |
| 29 | + apiKey: env('ELEVEN_LABS_API_KEY'), |
| 30 | + httpClient: http_client(), |
| 31 | + speechConfiguration: new SpeechConfiguration( |
| 32 | + ttsModel: 'eleven_multilingual_v2', |
| 33 | + ttsVoice: 'Dslrhjl3ZpzrctukrQSN', // Brad (https://elevenlabs.io/app/voice-library?voiceId=Dslrhjl3ZpzrctukrQSN) |
| 34 | + sttModel: 'eleven_multilingual_v2' |
| 35 | + )), |
| 36 | + ), |
| 37 | +], [ |
| 38 | + new ElevenLabsSpeechListener(PlatformFactory::create( |
| 39 | + apiKey: env('ELEVEN_LABS_API_KEY'), |
| 40 | + httpClient: http_client(), |
| 41 | + speechConfiguration: new SpeechConfiguration( |
| 42 | + sttModel: 'scribe_v1' |
| 43 | + )), |
| 44 | + ), |
| 45 | +])); |
| 46 | + |
| 47 | +$platform = OpenAiPlatformFactory::create(env('OPENAI_API_KEY'), httpClient: http_client(), eventDispatcher: $eventDispatcher); |
| 48 | + |
| 49 | +$agent = new Agent($platform, 'gpt-4o'); |
| 50 | +$answer = $agent->call(new MessageBag( |
| 51 | + Message::ofUser(Audio::fromFile(dirname(__DIR__, 2).'/fixtures/audio.mp3')) |
| 52 | +)); |
| 53 | + |
| 54 | +echo $answer->getSpeech('eleven_labs')->asBinary(); |
0 commit comments