Skip to content

Commit c78c329

Browse files
committed
ref
1 parent ce5b2f0 commit c78c329

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

src/agent/src/Toolbox/Tool/ElevenLabs.php

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

1212
namespace Symfony\AI\Agent\Toolbox\Tool;
1313

14+
use Symfony\AI\Agent\Exception\RuntimeException;
1415
use Symfony\AI\Agent\Toolbox\Attribute\AsTool;
1516
use Symfony\Component\Filesystem\Filesystem;
1617
use Symfony\Contracts\HttpClient\HttpClientInterface;
1718

1819
/**
1920
* @author Guillaume Loulier <[email protected]>
2021
*/
21-
#[AsTool('eleven_labs', description: 'convert text to speech / voice')]
22+
#[AsTool('eleven_labs', description: 'Convert text to speech / voice')]
2223
final readonly class ElevenLabs
2324
{
2425
public function __construct(
@@ -30,8 +31,18 @@ public function __construct(
3031
) {
3132
}
3233

34+
/**
35+
* @return array{
36+
* input: string,
37+
* path: string,
38+
* }
39+
*/
3340
public function __invoke(string $text): array
3441
{
42+
if (!class_exists(Filesystem::class)) {
43+
throw new RuntimeException('For using the ElevenLabs TTS tool, the symfony/filesystem package is required. Try running "composer require symfony/filesystem".');
44+
}
45+
3546
$response = $this->httpClient->request('POST', \sprintf('https://api.elevenlabs.io/v1/text-to-speech/%s?output_format=mp3_44100_128', $this->voice), [
3647
'headers' => [
3748
'xi-api-key' => $this->apiKey,

src/agent/tests/Toolbox/Tool/ElevenLabsTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public function testTextToSpeech()
3737

3838
$this->assertCount(2, $result);
3939
$this->assertSame('Hello World', $result['input']);
40-
$this->assertNull($result['file']);
40+
$this->assertNotEmpty($result['path']);
4141
$this->assertSame(1, $httpClient->getRequestsCount());
4242
}
4343
}

0 commit comments

Comments
 (0)