Skip to content

Commit bda9668

Browse files
committed
ref
1 parent fc849eb commit bda9668

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

src/agent/composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@
4242
"symfony/dom-crawler": "^6.4 || ^7.1",
4343
"symfony/event-dispatcher": "^6.4 || ^7.1",
4444
"symfony/filesystem": "^7.3",
45-
"symfony/http-foundation": "^6.4 || ^7.1"
45+
"symfony/http-foundation": "^6.4 || ^7.1",
46+
"symfony/uid": "^6.4 || ^7.1"
4647
},
4748
"config": {
4849
"sort-packages": true

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

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,13 @@
1414
use Symfony\AI\Agent\Exception\RuntimeException;
1515
use Symfony\AI\Agent\Toolbox\Attribute\AsTool;
1616
use Symfony\Component\Filesystem\Filesystem;
17+
use Symfony\Component\Uid\Uuid;
1718
use Symfony\Contracts\HttpClient\HttpClientInterface;
1819

1920
/**
2021
* @author Guillaume Loulier <[email protected]>
2122
*/
22-
#[AsTool('eleven_labs', description: 'Convert text to speech / voice')]
23+
#[AsTool('text_to_speech', description: 'Convert text to speech / voice')]
2324
final readonly class ElevenLabs
2425
{
2526
public function __construct(
@@ -29,6 +30,13 @@ public function __construct(
2930
private string $model,
3031
private string $voice,
3132
) {
33+
if (!class_exists(Filesystem::class)) {
34+
throw new RuntimeException('For using the ElevenLabs TTS tool, the symfony/filesystem package is required. Try running "composer require symfony/filesystem".');
35+
}
36+
37+
if (!class_exists(Uuid::class)) {
38+
throw new RuntimeException('For using the ElevenLabs TTS tool, the symfony/uid package is required. Try running "composer require symfony/uid".');
39+
}
3240
}
3341

3442
/**
@@ -39,10 +47,6 @@ public function __construct(
3947
*/
4048
public function __invoke(string $text): array
4149
{
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-
4650
$response = $this->httpClient->request('POST', \sprintf('https://api.elevenlabs.io/v1/text-to-speech/%s?output_format=mp3_44100_128', $this->voice), [
4751
'headers' => [
4852
'xi-api-key' => $this->apiKey,
@@ -53,7 +57,7 @@ public function __invoke(string $text): array
5357
],
5458
]);
5559

56-
$file = \sprintf('%s/%s.mp3', $this->path, uniqid());
60+
$file = \sprintf('%s/%s.mp3', $this->path, Uuid::v4()->toRfc4122());
5761

5862
$filesystem = new Filesystem();
5963
$filesystem->dumpFile($file, $response->getContent());

0 commit comments

Comments
 (0)