Skip to content

Commit bab79a8

Browse files
committed
tests && ref
1 parent 08a825d commit bab79a8

File tree

8 files changed

+27
-6
lines changed

8 files changed

+27
-6
lines changed

src/platform/src/Bridge/ElevenLabs/ElevenLabsClient.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,14 @@ public function request(Model $model, array|string $payload, array $options = []
4040
return match ($model->getName()) {
4141
ElevenLabs::SPEECH_TO_TEXT => $this->doSpeechToTextRequest($model, $payload, $options),
4242
ElevenLabs::TEXT_TO_SPEECH => $this->doTextToSpeechRequest($model, $payload, $options),
43+
default => throw new InvalidArgumentException(sprintf('The model "%s" is not supported.', $model->getName())),
4344
};
4445
}
4546

47+
/**
48+
* @param array<string|int, mixed> $payload
49+
* @param array<string, mixed> $options
50+
*/
4651
private function doSpeechToTextRequest(Model $model, array|string $payload, array $options): RawHttpResult
4752
{
4853
if (!array_key_exists('model', $model->getOptions())) {
@@ -60,12 +65,16 @@ private function doSpeechToTextRequest(Model $model, array|string $payload, arra
6065
'xi-api-key' => $this->apiKey,
6166
],
6267
'body' => [
63-
'file' => $payload['input_audio']['resource'],
68+
'file' => fopen($payload['input_audio']['path'], 'r'),
6469
'model_id' => $model,
6570
],
6671
]));
6772
}
6873

74+
/**
75+
* @param array<string|int, mixed> $payload
76+
* @param array<string, mixed> $options
77+
*/
6978
private function doTextToSpeechRequest(Model $model, array|string $payload, array $options): RawHttpResult
7079
{
7180
if (!array_key_exists('model', $model->getOptions())) {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public function normalize(mixed $data, ?string $format = null, array $context =
4545
'type' => 'input_audio',
4646
'input_audio' => [
4747
'data' => $data->asBase64(),
48-
'resource' => $data->asResource(),
48+
'path' => $data->asPath(),
4949
'format' => match ($data->getFormat()) {
5050
'audio/mpeg' => 'mp3',
5151
'audio/wav' => 'wav',

src/platform/src/Message/Content/File.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,11 @@ public function asDataUrl(): string
7373
return \sprintf('data:%s;base64,%s', $this->format, $this->asBase64());
7474
}
7575

76+
public function asPath(): string
77+
{
78+
return $this->path;
79+
}
80+
7681
/**
7782
* @return resource|false
7883
*/

src/platform/src/Result/AudioResult.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public function __construct(
2222
) {
2323
}
2424

25-
public function getContent(): string|iterable|object|null
25+
public function getContent(): string
2626
{
2727
return file_get_contents($this->path);
2828
}

src/platform/src/Result/ResultPromise.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,11 @@ public function asBinary(): string
7575

7676
public function asAudio(): string
7777
{
78-
return $this->as(AudioResult::class)->getPath();
78+
$result = $this->as(AudioResult::class);
79+
80+
\assert($result instanceof AudioResult);
81+
82+
return $result->getPath();
7983
}
8084

8185
public function asBase64(): string

src/platform/tests/Bridge/ElevenLabs/ElevenLabsConverterTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public function getInfo(): string
6464
return 'text-to-speech';
6565
}
6666

67-
public function getContent()
67+
public function getContent(): string
6868
{
6969
return file_get_contents(dirname(__DIR__, 5).'/fixtures/audio.mp3');
7070
}

src/platform/tests/Contract/Normalizer/Message/Content/AudioNormalizerTest.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public function testGetSupportedTypes()
4545
#[DataProvider('provideAudioData')]
4646
public function testNormalize(string $data, string $format, array $expected)
4747
{
48-
$audio = new Audio(base64_decode($data), $format);
48+
$audio = new Audio(base64_decode($data), $format, dirname(__DIR__, 7).'/fixtures/audio.mp3');
4949

5050
$this->assertSame($expected, $this->normalizer->normalize($audio));
5151
}
@@ -59,6 +59,7 @@ public static function provideAudioData(): \Generator
5959
'type' => 'input_audio',
6060
'input_audio' => [
6161
'data' => 'SUQzBAAAAAAAfVREUkMAAAAMAAADMg==',
62+
'path' => pathinfo(dirname(__DIR__, 7).'/fixtures/audio.mp3', \PATHINFO_DIRNAME).'/audio.mp3',
6263
'format' => 'mp3',
6364
],
6465
],
@@ -71,6 +72,7 @@ public static function provideAudioData(): \Generator
7172
'type' => 'input_audio',
7273
'input_audio' => [
7374
'data' => 'UklGRiQAAABXQVZFZm10IBA=',
75+
'path' => pathinfo(dirname(__DIR__, 7).'/fixtures/audio.mp3', \PATHINFO_DIRNAME).'/audio.mp3',
7476
'format' => 'wav',
7577
],
7678
],

src/platform/tests/ContractTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ public static function providePayloadTestCases(): iterable
113113
'type' => 'input_audio',
114114
'input_audio' => [
115115
'data' => $audio->asBase64(),
116+
'path' => pathinfo(dirname(__DIR__, 3).'/fixtures/audio.mp3', \PATHINFO_DIRNAME).'/audio.mp3',
116117
'format' => 'mp3',
117118
],
118119
],

0 commit comments

Comments
 (0)