generated from spatie/package-skeleton-laravel
-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
145 additions
and
101 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
The MIT License (MIT) | ||
|
||
Copyright (c) ArdaGnsrn <[email protected]> | ||
Copyright (c) Arda Günsüren <[email protected]> | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<?php | ||
|
||
return [ | ||
'api_key' => env('ELEVENLABS_API_KEY'), | ||
]; |
This file was deleted.
Oops, something went wrong.
19 changes: 0 additions & 19 deletions
19
database/migrations/create_elevenlabs_laravel_table.php.stub
This file was deleted.
Oops, something went wrong.
Empty file.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
|
||
namespace ArdaGnsrn\ElevenLabs\Responses; | ||
|
||
use Illuminate\Support\Facades\Storage; | ||
use Psr\Http\Message\ResponseInterface; | ||
|
||
class TextToSpeechResponse | ||
{ | ||
private ResponseInterface $response; | ||
|
||
public function __construct(ResponseInterface $response) | ||
{ | ||
$this->response = $response; | ||
} | ||
|
||
public function getResponse() | ||
{ | ||
return $this->response; | ||
} | ||
|
||
public function saveFile($file): void | ||
{ | ||
Storage::put($file, $this->response->getBody()->getContents()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?php | ||
|
||
namespace ArdaGnsrn\ElevenLabs\Traits; | ||
|
||
use ArdaGnsrn\ElevenLabs\Utils\API; | ||
|
||
trait ModelsTrait | ||
{ | ||
/** | ||
* Get all models | ||
*/ | ||
public function getModels(): array | ||
{ | ||
return API::request('GET', 'models'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php | ||
|
||
namespace ArdaGnsrn\ElevenLabs\Traits; | ||
|
||
use ArdaGnsrn\ElevenLabs\Responses\TextToSpeechResponse; | ||
use ArdaGnsrn\ElevenLabs\Utils\API; | ||
|
||
trait TextToSpeechTrait | ||
{ | ||
/** | ||
* Text to speech | ||
*/ | ||
public function textToSpeech(string $voiceId, string $text, string $modelId = 'eleven_multilingual_v2', array $voiceSettings = ['stability' => 0.95, 'similarity_boost' => 0.75, 'style' => 0.06, 'use_speaker_boost' => true]): TextToSpeechResponse | ||
{ | ||
$response = API::request('POST', "text-to-speech/$voiceId", [ | ||
'json' => [ | ||
'text' => $text, | ||
'model_id' => $modelId, | ||
'voice_settings' => $voiceSettings, | ||
], | ||
'headers' => [ | ||
'Accept' => 'audio/mpeg', | ||
], | ||
'stream' => true, | ||
], false); | ||
|
||
return new TextToSpeechResponse($response); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php | ||
|
||
namespace ArdaGnsrn\ElevenLabs\Utils; | ||
|
||
use GuzzleHttp\Client; | ||
use Illuminate\Support\Facades\Config; | ||
use Psr\Http\Message\ResponseInterface; | ||
|
||
class API | ||
{ | ||
private const BASE_URL = 'https://api.elevenlabs.io/'; | ||
|
||
public static function request($method, $endpoint, $options = [], $isJson = true): ResponseInterface|array | ||
{ | ||
try { | ||
$client = new Client([ | ||
'base_uri' => self::BASE_URL, | ||
'headers' => [ | ||
'xi-api-key' => Config::get('elevenlabs.api_key'), | ||
'Content-Type' => 'application/json', | ||
], | ||
]); | ||
$response = $client->request($method, 'v1/'.$endpoint, $options); | ||
if ($isJson) { | ||
return json_decode($response->getBody()->getContents(), true); | ||
} | ||
|
||
return $response; | ||
} catch (\GuzzleHttp\Exception\ClientException $exception) { | ||
if ($exception->getCode() === 401) { | ||
throw new \Exception('Invalid API key'); | ||
} | ||
throw $exception; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,16 @@ | ||
<?php | ||
|
||
it('can test', function () { | ||
expect(true)->toBeTrue(); | ||
describe('Methods Unit Test', function () { | ||
test('getModels() function', function () { | ||
$models = \ArdaGnsrn\ElevenLabs\Facades\ElevenLabs::getModels(); | ||
expect($models)->toBeArray(); | ||
expect($models)->not->toBeEmpty(); | ||
}); | ||
test('textToSpeech() function', function () { | ||
$response = \ArdaGnsrn\ElevenLabs\Facades\ElevenLabs::textToSpeech('2EiwWnXFnvU5JabPnv8n', 'H'); | ||
expect($response)->toBeInstanceOf(\ArdaGnsrn\ElevenLabs\Responses\TextToSpeechResponse::class); | ||
|
||
$response->saveFile('test.mp3'); | ||
expect(\Illuminate\Support\Facades\Storage::exists('test.mp3'))->toBeTrue(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters