-
-
Notifications
You must be signed in to change notification settings - Fork 51
[Platform] Add ElevenLabs as platform #292
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,4 @@ | |
.transformers-cache | ||
composer.lock | ||
vendor | ||
tmp | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. instead of this, what about using There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Well, thing is, this directory is only used for examples, if we want the developer who's using the examples to access the file, the |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
use Symfony\AI\Platform\Bridge\ElevenLabs\ElevenLabs; | ||
use Symfony\AI\Platform\Bridge\ElevenLabs\PlatformFactory; | ||
use Symfony\AI\Platform\Message\Content\Audio; | ||
|
||
require_once dirname(__DIR__).'/bootstrap.php'; | ||
|
||
$platform = PlatformFactory::create( | ||
apiKey: env('ELEVEN_LABS_API_KEY'), | ||
outputPath: __DIR__.'/tmp', | ||
httpClient: http_client() | ||
); | ||
$model = new ElevenLabs(ElevenLabs::SCRIBE_V1); | ||
|
||
$result = $platform->invoke($model, Audio::fromFile(dirname(__DIR__, 2).'/fixtures/audio.mp3')); | ||
|
||
echo $result->asText().\PHP_EOL; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
use Symfony\AI\Platform\Bridge\ElevenLabs\ElevenLabs; | ||
use Symfony\AI\Platform\Bridge\ElevenLabs\PlatformFactory; | ||
use Symfony\AI\Platform\Message\Content\Text; | ||
|
||
require_once dirname(__DIR__).'/bootstrap.php'; | ||
|
||
$platform = PlatformFactory::create( | ||
apiKey: env('ELEVEN_LABS_API_KEY'), | ||
outputPath: dirname(__DIR__).'/tmp', | ||
httpClient: http_client(), | ||
); | ||
$model = new ElevenLabs(options: [ | ||
'voice' => 'Dslrhjl3ZpzrctukrQSN', // Brad (https://elevenlabs.io/app/voice-library?voiceId=Dslrhjl3ZpzrctukrQSN) | ||
]); | ||
|
||
$result = $platform->invoke($model, new Text('Hello world')); | ||
|
||
echo $result->asBase64().\PHP_EOL; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\AI\Platform\Bridge\ElevenLabs\Contract; | ||
|
||
use Symfony\AI\Platform\Message\Content\Audio; | ||
use Symfony\Component\Serializer\Normalizer\NormalizerInterface; | ||
|
||
/** | ||
* @author Guillaume Loulier <[email protected]> | ||
*/ | ||
final readonly class AudioNormalizer implements NormalizerInterface | ||
{ | ||
public function supportsNormalization(mixed $data, ?string $format = null, array $context = []): bool | ||
{ | ||
return $data instanceof Audio; | ||
} | ||
|
||
public function getSupportedTypes(?string $format): array | ||
{ | ||
return [ | ||
Audio::class => true, | ||
]; | ||
} | ||
|
||
/** | ||
* @param Audio $data | ||
* | ||
* @return array{type: 'input_audio', input_audio: array{ | ||
* data: string, | ||
* path: string, | ||
* format: 'mp3'|'wav'|string, | ||
* }} | ||
*/ | ||
public function normalize(mixed $data, ?string $format = null, array $context = []): array | ||
{ | ||
return [ | ||
'type' => 'input_audio', | ||
'input_audio' => [ | ||
'data' => $data->asBase64(), | ||
'path' => $data->asPath(), | ||
'format' => match ($data->getFormat()) { | ||
'audio/mpeg' => 'mp3', | ||
'audio/wav' => 'wav', | ||
default => $data->getFormat(), | ||
}, | ||
], | ||
]; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\AI\Platform\Bridge\ElevenLabs\Contract; | ||
|
||
use Symfony\AI\Platform\Contract; | ||
use Symfony\Component\Serializer\Normalizer\NormalizerInterface; | ||
|
||
/** | ||
* @author Guillaume Loulier <[email protected]> | ||
*/ | ||
final readonly class ElevenLabsContract extends Contract | ||
{ | ||
public static function create(NormalizerInterface ...$normalizer): Contract | ||
{ | ||
return parent::create( | ||
new AudioNormalizer(), | ||
...$normalizer, | ||
); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\AI\Platform\Bridge\ElevenLabs; | ||
|
||
use Symfony\AI\Platform\Model; | ||
|
||
/** | ||
* @author Guillaume Loulier <[email protected]> | ||
*/ | ||
final class ElevenLabs extends Model | ||
{ | ||
public const ELEVEN_V3 = 'eleven_v3'; | ||
public const ELEVEN_TTV_V3 = 'eleven_ttv_v3'; | ||
public const ELEVEN_MULTILINGUAL_V2 = 'eleven_multilingual_v2'; | ||
public const ELEVEN_FLASH_V250 = 'eleven_flash_v2_5'; | ||
public const ELEVEN_FLASH_V2 = 'eleven_flashv2'; | ||
public const ELEVEN_TURBO_V2_5 = 'eleven_turbo_v2_5'; | ||
public const ELEVEN_TURBO_v2 = 'eleven_turbo_v2'; | ||
public const ELEVEN_MULTILINGUAL_STS_V2 = 'eleven_multilingual_sts_v2'; | ||
public const ELEVEN_MULTILINGUAL_ttv_V2 = 'eleven_multilingual_ttv_v2'; | ||
public const ELEVEN_ENGLISH_STS_V2 = 'eleven_english_sts_v2'; | ||
public const SCRIBE_V1 = 'scribe_v1'; | ||
public const SCRIBE_V1_EXPERIMENTAL = 'scribe_v1_experimental'; | ||
|
||
public function __construct( | ||
string $name = self::ELEVEN_MULTILINGUAL_V2, | ||
array $options = [], | ||
) { | ||
parent::__construct($name, [], $options); | ||
} | ||
} |
Uh oh!
There was an error while loading. Please reload this page.