Skip to content

Commit 694bd2d

Browse files
committed
ref
1 parent a8b12ef commit 694bd2d

File tree

6 files changed

+108
-3
lines changed

6 files changed

+108
-3
lines changed

src/platform/composer.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@
4646
"symfony/event-dispatcher": "^6.4 || ^7.1",
4747
"symfony/filesystem": "^7.3",
4848
"symfony/finder": "^6.4 || ^7.1",
49-
"symfony/mime": "^7.3",
5049
"symfony/process": "^6.4 || ^7.1",
5150
"symfony/var-dumper": "^6.4 || ^7.1"
5251
},
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <[email protected]>
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+
namespace Symfony\AI\Platform\Bridge\ElevenLabs\Contract;
13+
14+
use Symfony\AI\Platform\Message\Content\Audio;
15+
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
16+
17+
/**
18+
* @author Guillaume Loulier <[email protected]>
19+
*/
20+
final readonly class AudioNormalizer implements NormalizerInterface
21+
{
22+
public function supportsNormalization(mixed $data, ?string $format = null, array $context = []): bool
23+
{
24+
return $data instanceof Audio;
25+
}
26+
27+
public function getSupportedTypes(?string $format): array
28+
{
29+
return [
30+
Audio::class => true,
31+
];
32+
}
33+
34+
/**
35+
* @param Audio $data
36+
*
37+
* @return array{type: 'input_audio', input_audio: array{
38+
* data: string,
39+
* path: string,
40+
* format: 'mp3'|'wav'|string,
41+
* }}
42+
*/
43+
public function normalize(mixed $data, ?string $format = null, array $context = []): array
44+
{
45+
return [
46+
'type' => 'input_audio',
47+
'input_audio' => [
48+
'data' => $data->asBase64(),
49+
'path' => $data->asPath(),
50+
'format' => match ($data->getFormat()) {
51+
'audio/mpeg' => 'mp3',
52+
'audio/wav' => 'wav',
53+
default => $data->getFormat(),
54+
},
55+
],
56+
];
57+
}
58+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <[email protected]>
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+
namespace Symfony\AI\Platform\Bridge\ElevenLabs\Contract;
13+
14+
use Symfony\AI\Platform\Contract;
15+
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
16+
17+
/**
18+
* @author Guillaume Loulier <[email protected]>
19+
*/
20+
final readonly class ElevenLabsContract extends Contract
21+
{
22+
public static function create(NormalizerInterface ...$normalizer): Contract
23+
{
24+
return parent::create(
25+
new AudioNormalizer(),
26+
...$normalizer,
27+
);
28+
}
29+
}

src/platform/src/Bridge/ElevenLabs/PlatformFactory.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

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

14+
use Symfony\AI\Platform\Bridge\ElevenLabs\Contract\ElevenLabsContract;
1415
use Symfony\AI\Platform\Contract;
1516
use Symfony\AI\Platform\Platform;
1617
use Symfony\Component\HttpClient\EventSourceHttpClient;
@@ -33,7 +34,7 @@ public static function create(
3334
return new Platform(
3435
[new ElevenLabsClient($httpClient, $apiKey, $hostUrl)],
3536
[new ElevenLabsResultConverter($outputPath)],
36-
$contract ?? Contract::create(),
37+
$contract ?? ElevenLabsContract::create(),
3738
);
3839
}
3940
}

src/platform/src/Contract/Normalizer/Message/Content/AudioNormalizer.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ public function normalize(mixed $data, ?string $format = null, array $context =
4545
'type' => 'input_audio',
4646
'input_audio' => [
4747
'data' => $data->asBase64(),
48-
'path' => $data->asPath(),
4948
'format' => match ($data->getFormat()) {
5049
'audio/mpeg' => 'mp3',
5150
'audio/wav' => 'wav',
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <[email protected]>
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+
namespace Bridge\ElevenLabs\Contract;
13+
14+
use PHPUnit\Framework\TestCase;
15+
16+
final class ElevenLabsContractTest extends TestCase
17+
{
18+
19+
}

0 commit comments

Comments
 (0)