talendor / elevenlabs-api
Laravel 对Elevenlabs API的包装客户端
Requires
- php: ^8.0
- guzzlehttp/guzzle: ^7.7
- illuminate/support: ^10.13
Requires (Dev)
- pestphp/pest: ^2.6
- vimeo/psalm: ^5.12
README
这是一个Laravel包,作为ElevenLabs语音生成API的包装器。它提供了根据提供的内容生成语音的简单易用的接口。
安装
您可以通过Composer安装此包。运行以下命令
composer require talendor/elevenlabs-api
使用方法
要开始,请确保设置您的ElevenLabs API密钥。您可以通过将以下密钥添加到您的.env文件中来实现
ELEVEN_API_KEY=your-api-key
然后,您可以通过访问ElevenLabsClient实例来使用此包。例如,您可以将以下路由添加到您的web.php或api.php文件中,以测试库是否正常工作
use Talendor\ElevenLabsClient\Facades\ElevenLabsClient; Route::get('/test_elevenlabsclient', function() { $elevenLabsClient = app()->make(ElevenLabsClient::class); return $elevenLabsClient->voices()->getAll(); });
语音类
命名空间
Talendor\ElevenLabsClient\Voice
类描述
Voice
类是 Talendor\ElevenLabsClient\Voice
命名空间的一部分。它实现了 VoiceInterface
。
getAll()
检索所有可用的语音。
getVoice(string $voice_id)
返回特定语音的元数据。
defaultSettings()
获取语音的默认设置。
voiceSettings(string $voice_id)
addVoice(string $name, ?string $description, string $files, ?string $labels = "American")
向VoiceLab中的语音集合中添加新的语音。
参数
$name
(string): 语音的名称。$description
(string|null): 语音的描述。$files
(string): 语音的文件路径。$labels
(string|null, default: "American"): 语音的标签。
editVoice(string $voice_id, string $name, ?string $description, ?string $files, ?string $labels = "American")
编辑VoiceLab中语音集合中的语音。
参数
$voice_id
(string): 语音的ID。$name
(string): 语音的新名称。$description
(string|null): 语音的新描述。$files
(string|null): 语音的新文件路径。$labels
(string|null, default: "American"): 语音的新标签。
deleteVoice(string $voice_id)
从VoiceLab中的语音集合中删除特定的语音。
参数
$voice_id
(string): 语音的ID。
文本到语音类
命名空间
Talendor\ElevenLabsClient\TextToSpeech
类描述
TextToSpeech
类是 Talendor\ElevenLabsClient\TextToSpeech
命名空间的一部分。它实现了 TextToSpeechInterface
。
generate(string $content, string $voice_id , ?bool $optimize_latency, ?string $model_id, ?array $voice_settings = [])
generate_stream(string $content, string $voice_id , ?bool $optimize_latency, ?string $model_id , ?array $voice_settings = [])
历史记录
命名空间
Talendor\ElevenLabsClient\History
类描述
History
类是 Talendor\ElevenLabsClient\History
命名空间的一部分。它实现了 HistoryInterface
。
getHistory()
返回所有生成的音频的元数据。
getHistoryItem(string $history_item_id)
通过其ID返回历史项的信息。
参数
$history_item_id
(string): 历史项的ID。
getHistoryItemAudio(string $history_item_id, string $fileName)
返回历史项的音频。
参数
$history_item_id
(string): 历史项的ID。$fileName
(string): 音频文件的期望文件名。
deleteHistoryItem(string $history_item_id)
通过其ID删除历史项。
参数
$history_item_id
(string): 历史项的ID。
downloadHistory(array $history_items, string $filename)
下载一个或多个历史项。如果提供一个历史项ID,将返回单个音频文件。如果提供多个历史项ID,则历史项将被打包到.zip文件中。
参数
$history_items
(数组):历史项目ID的数组。$filename
(字符串):下载文件的期望文件名。
Models
类
可用方法
getModels()
获取可用模型列表。
返回类型: 数组
User
类
命名空间
Talendor\ElevenLabsClient\User
类描述
User
类是 Talendor\ElevenLabsClient\User
命名空间的一部分。它实现了 UserInterface
。
可用方法
getUserInfo()
获取用户信息。
返回类型: 数组
描述: 此方法检索当前用户的信息。它向 user
端点发送 GET 请求,并以数组形式返回解码后的响应数据。
getUserSubscription()
获取用户订阅的扩展信息。
返回类型: 数组
描述: 此方法检索当前用户订阅的扩展信息。它向 user/subscription
端点发送 GET 请求,并以数组形式返回解码后的响应数据。
请随意在您的 Laravel 应用程序中使用这些方法来与 ElevenLabs 语音生成 API 进行交互。