Skip to content

Commit 1ce622e

Browse files
committed
ref
1 parent e5bda4c commit 1ce622e

File tree

3 files changed

+31
-4
lines changed

3 files changed

+31
-4
lines changed

src/platform/src/Bridge/ElevenLabs/ElevenLabsSpeechPlatform.php

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,15 @@
1111

1212
namespace Symfony\AI\Platform\Bridge\ElevenLabs;
1313

14+
use Symfony\AI\Platform\Exception\RuntimeException;
1415
use Symfony\AI\Platform\Message\Content\Text;
1516
use Symfony\AI\Platform\Message\MessageBag;
1617
use Symfony\AI\Platform\ModelCatalog\ModelCatalogInterface;
1718
use Symfony\AI\Platform\PlatformInterface;
1819
use Symfony\AI\Platform\Result\DeferredResult;
1920
use Symfony\AI\Platform\Speech\Speech;
2021
use Symfony\AI\Platform\Speech\SpeechPlatformInterface;
22+
use Symfony\Component\OptionsResolver\OptionsResolver;
2123

2224
/**
2325
* @author Guillaume Loulier <personal@guillaumeloulier.fr>
@@ -29,8 +31,16 @@ final class ElevenLabsSpeechPlatform implements PlatformInterface, SpeechPlatfor
2931
*/
3032
public function __construct(
3133
private readonly PlatformInterface $platform,
32-
private readonly array $speechConfiguration,
34+
private array $speechConfiguration,
3335
) {
36+
if (!class_exists(OptionsResolver::class)) {
37+
throw new RuntimeException('For using elevenlabs as as speech platform, a symfony/options-resolver implementation is required. Try running "composer require symfony/options-resolver".');
38+
}
39+
40+
$optionsResolver = new OptionsResolver();
41+
self::configureOptions($optionsResolver);
42+
43+
$this->speechConfiguration = $optionsResolver->resolve($speechConfiguration);
3444
}
3545

3646
public function invoke(string $model, object|array|string $input, array $options = []): DeferredResult
@@ -75,4 +85,20 @@ public function getModelCatalog(): ModelCatalogInterface
7585
{
7686
return $this->platform->getModelCatalog();
7787
}
88+
89+
private static function configureOptions(OptionsResolver $options): void
90+
{
91+
$options
92+
->define('tts_model')
93+
->allowedTypes('string', 'null')
94+
->define('tts_voice')
95+
->allowedTypes('string', 'null')
96+
->define('tts_options')
97+
->allowedTypes('array')
98+
->define('stt_model')
99+
->allowedTypes('string', 'null')
100+
->define('stt_options')
101+
->allowedTypes('array')
102+
;
103+
}
78104
}

src/platform/src/Bridge/ElevenLabs/Tests/ElevenLabsSpeechPlatformTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
* file that was distributed with this source code.
1010
*/
1111

12-
namespace Bridge\ElevenLabs;
12+
namespace Symfony\AI\Platform\Bridge\ElevenLabs\Tests;
1313

1414
use PHPUnit\Framework\TestCase;
1515
use Symfony\AI\Platform\Bridge\ElevenLabs\ElevenLabsSpeechPlatform;
@@ -95,7 +95,7 @@ public function testListenerCanListenOnMessageBag()
9595
]);
9696

9797
$text = $speechAwarePlatform->listen(new MessageBag(
98-
Message::ofUser(Audio::fromFile(\dirname(__DIR__, 5).'/fixtures/audio.mp3')),
98+
Message::ofUser(Audio::fromFile(\dirname(__DIR__, 6).'/fixtures/audio.mp3')),
9999
), []);
100100

101101
$this->assertInstanceOf(Text::class, $text);

src/platform/src/Bridge/ElevenLabs/composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@
3333
"require-dev": {
3434
"phpstan/phpstan": "^2.1",
3535
"phpstan/phpstan-strict-rules": "^2.0",
36-
"phpunit/phpunit": "^11.5.46"
36+
"phpunit/phpunit": "^11.5.46",
37+
"symfony/options-resolver": "^7.3|^8.0"
3738
},
3839
"minimum-stability": "dev",
3940
"autoload": {

0 commit comments

Comments
 (0)