elevenlabs 0.0.4 → 0.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +211 -51
- data/lib/elevenlabs/client.rb +146 -0
- data/lib/elevenlabs/errors.rb +1 -1
- data/lib/elevenlabs.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 22770e41ca0d3c88d2dc5f83e3e4d9de510610bf1a0adaf9bf675951a647ab30
|
|
4
|
+
data.tar.gz: 8f6ffc3ef844da02c3f45385a730ebbddfe3c711d11e1b983837153c8dbd859a
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 1b094e808358b342f7fe8cb08cf993dbafe2bac989bcb1e4655d5de5dd2884ff83626cb098da9b7c06d60a697302d33e848419f80a26fb53f34198f7894390b7
|
|
7
|
+
data.tar.gz: 44ad5334ed45f2628a22be91a0ed307b74f7e8611f6ba71cca0b4ee79f7e510f1f655e45321e47060b413e476ed9ea9913e304a44a789ec388bb7411235d42b4
|
data/README.md
CHANGED
|
@@ -12,6 +12,8 @@ This gem provides an easy-to-use interface for:
|
|
|
12
12
|
- **Editing an existing voice**
|
|
13
13
|
- **Deleting a voice**
|
|
14
14
|
- **Converting text to speech** and retrieving the generated audio
|
|
15
|
+
- **Designing a voice** based on a text description
|
|
16
|
+
- **Streaming text-to-speech audio**
|
|
15
17
|
|
|
16
18
|
All requests are handled via [Faraday](https://github.com/lostisland/faraday).
|
|
17
19
|
|
|
@@ -39,6 +41,7 @@ All requests are handled via [Faraday](https://github.com/lostisland/faraday).
|
|
|
39
41
|
|
|
40
42
|
- **Simple and intuitive API client** for ElevenLabs.
|
|
41
43
|
- **Multipart file uploads** for training custom voices.
|
|
44
|
+
- **Voice design** via text prompts to generate voice previews.
|
|
42
45
|
- **Automatic authentication** via API key configuration.
|
|
43
46
|
- **Error handling** with custom exceptions.
|
|
44
47
|
- **Rails integration support** (including credentials storage).
|
|
@@ -52,16 +55,25 @@ Add the gem to your `Gemfile`:
|
|
|
52
55
|
```ruby
|
|
53
56
|
gem "elevenlabs"
|
|
54
57
|
```
|
|
58
|
+
|
|
55
59
|
Then run:
|
|
56
|
-
|
|
60
|
+
|
|
61
|
+
```bash
|
|
57
62
|
bundle install
|
|
58
63
|
```
|
|
64
|
+
|
|
59
65
|
Or install it directly using:
|
|
60
|
-
|
|
66
|
+
|
|
67
|
+
```bash
|
|
61
68
|
gem install elevenlabs
|
|
62
69
|
```
|
|
63
|
-
|
|
64
|
-
|
|
70
|
+
|
|
71
|
+
---
|
|
72
|
+
|
|
73
|
+
## Usage
|
|
74
|
+
|
|
75
|
+
### Basic Example (Standalone Ruby)
|
|
76
|
+
|
|
65
77
|
```ruby
|
|
66
78
|
require "elevenlabs"
|
|
67
79
|
|
|
@@ -85,27 +97,58 @@ audio_data = client.text_to_speech(voice_id, text)
|
|
|
85
97
|
# 5. Save the audio file
|
|
86
98
|
File.open("output.mp3", "wb") { |f| f.write(audio_data) }
|
|
87
99
|
puts "Audio file saved to output.mp3"
|
|
100
|
+
|
|
101
|
+
# 6. Design a voice with a text prompt
|
|
102
|
+
response = client.design_voice(
|
|
103
|
+
"A deep, resonant male voice with a British accent, suitable for storytelling",
|
|
104
|
+
output_format: "mp3_44100_192",
|
|
105
|
+
model_id: "eleven_multilingual_ttv_v2",
|
|
106
|
+
text: "In a land far away, where the mountains meet the sky, a great adventure began. Brave heroes embarked on a quest to find the lost artifact, facing challenges and forging bonds that would last a lifetime. Their journey took them through enchanted forests, across raging rivers, and into the heart of ancient ruins.",
|
|
107
|
+
auto_generate_text: false,
|
|
108
|
+
loudness: 0.5,
|
|
109
|
+
seed: 12345,
|
|
110
|
+
guidance_scale: 5.0,
|
|
111
|
+
stream_previews: false
|
|
112
|
+
)
|
|
113
|
+
|
|
114
|
+
# 7. Save voice preview audio
|
|
115
|
+
require "base64"
|
|
116
|
+
response["previews"].each_with_index do |preview, index|
|
|
117
|
+
audio_data = Base64.decode64(preview["audio_base_64"])
|
|
118
|
+
File.open("preview_#{index}.mp3", "wb") { |f| f.write(audio_data) }
|
|
119
|
+
puts "Saved preview #{index + 1} to preview_#{index}.mp3"
|
|
120
|
+
end
|
|
88
121
|
```
|
|
122
|
+
|
|
89
123
|
Note: You can override the API key per request:
|
|
124
|
+
|
|
90
125
|
```ruby
|
|
91
126
|
client = Elevenlabs::Client.new(api_key: "DIFFERENT_API_KEY")
|
|
92
127
|
```
|
|
93
|
-
|
|
94
|
-
|
|
128
|
+
|
|
129
|
+
### Rails Integration
|
|
130
|
+
|
|
131
|
+
#### Store API Key in Rails Credentials
|
|
132
|
+
|
|
95
133
|
1. Open your encrypted credentials:
|
|
96
|
-
|
|
134
|
+
|
|
135
|
+
```bash
|
|
97
136
|
EDITOR=vim rails credentials:edit
|
|
98
137
|
```
|
|
99
138
|
|
|
100
139
|
2. Add the ElevenLabs API key:
|
|
101
|
-
|
|
140
|
+
|
|
141
|
+
```yaml
|
|
102
142
|
eleven_labs:
|
|
103
143
|
api_key: YOUR_SECURE_KEY
|
|
104
144
|
```
|
|
145
|
+
|
|
105
146
|
3. Save and exit. Rails will securely encrypt your API key.
|
|
106
147
|
|
|
107
|
-
Rails Initializer
|
|
108
|
-
|
|
148
|
+
#### Rails Initializer
|
|
149
|
+
|
|
150
|
+
Create an initializer file: `config/initializers/elevenlabs.rb`
|
|
151
|
+
|
|
109
152
|
```ruby
|
|
110
153
|
# config/initializers/elevenlabs.rb
|
|
111
154
|
require "elevenlabs"
|
|
@@ -116,59 +159,108 @@ Rails.application.config.to_prepare do
|
|
|
116
159
|
end
|
|
117
160
|
end
|
|
118
161
|
```
|
|
162
|
+
|
|
119
163
|
Now you can simply call:
|
|
164
|
+
|
|
120
165
|
```ruby
|
|
121
166
|
client = Elevenlabs::Client.new
|
|
122
167
|
```
|
|
168
|
+
|
|
123
169
|
without manually providing an API key.
|
|
124
170
|
|
|
125
|
-
|
|
126
|
-
|
|
171
|
+
#### Controller Example
|
|
172
|
+
|
|
173
|
+
```ruby
|
|
174
|
+
class AudioController < ApplicationController
|
|
175
|
+
def generate
|
|
176
|
+
client = Elevenlabs::Client.new
|
|
177
|
+
voice_id = params[:voice_id]
|
|
178
|
+
text = params[:text]
|
|
179
|
+
|
|
180
|
+
begin
|
|
181
|
+
audio_data = client.text_to_speech(voice_id, text)
|
|
182
|
+
send_data audio_data, type: "audio/mpeg", disposition: "attachment", filename: "output.mp3"
|
|
183
|
+
rescue Elevenlabs::APIError => e
|
|
184
|
+
render json: { error: e.message }, status: :bad_request
|
|
185
|
+
end
|
|
186
|
+
end
|
|
187
|
+
end
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
---
|
|
191
|
+
|
|
192
|
+
## Endpoints
|
|
193
|
+
|
|
194
|
+
1. **List Voices**
|
|
195
|
+
|
|
127
196
|
```ruby
|
|
128
197
|
client.list_voices
|
|
129
198
|
# => { "voices" => [...] }
|
|
130
|
-
|
|
131
|
-
2.
|
|
199
|
+
|
|
200
|
+
2. List Models
|
|
201
|
+
|
|
202
|
+
client.list_models
|
|
203
|
+
# => [...]
|
|
204
|
+
|
|
205
|
+
3. **Get Voice Details**
|
|
206
|
+
|
|
132
207
|
```ruby
|
|
133
208
|
client.get_voice("VOICE_ID")
|
|
134
209
|
# => { "voice_id" => "...", "name" => "...", ... }
|
|
135
210
|
```
|
|
136
|
-
|
|
211
|
+
|
|
212
|
+
4. **Create a Custom Voice**
|
|
213
|
+
|
|
137
214
|
```ruby
|
|
138
215
|
sample_files = [File.open("sample1.mp3", "rb")]
|
|
139
216
|
client.create_voice("Custom Voice", sample_files, description: "My custom AI voice")
|
|
140
217
|
# => JSON response with new voice details
|
|
141
218
|
```
|
|
142
|
-
|
|
219
|
+
|
|
220
|
+
5. **Check if a Voice is Banned**
|
|
221
|
+
|
|
143
222
|
```ruby
|
|
144
223
|
sample_files = [File.open("trump.mp3", "rb")]
|
|
145
224
|
client.create_voice("Donald Trump", sample_files, description: "My Trump Voice")
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
=> true
|
|
225
|
+
# => {"voice_id"=>"<RETURNED_VOICE_ID>", "requires_verification"=>false}
|
|
226
|
+
trump = "<RETURNED_VOICE_ID>"
|
|
227
|
+
client.banned?(trump)
|
|
228
|
+
# => true
|
|
150
229
|
```
|
|
151
|
-
|
|
230
|
+
|
|
231
|
+
6. **Edit a Voice**
|
|
232
|
+
|
|
152
233
|
```ruby
|
|
153
234
|
client.edit_voice("VOICE_ID", name: "Updated Voice Name")
|
|
154
235
|
# => JSON response with updated details
|
|
155
236
|
```
|
|
156
|
-
|
|
237
|
+
|
|
238
|
+
7. **Delete a Voice**
|
|
239
|
+
|
|
157
240
|
```ruby
|
|
158
241
|
client.delete_voice("VOICE_ID")
|
|
159
242
|
# => JSON response acknowledging deletion
|
|
160
243
|
```
|
|
161
|
-
|
|
244
|
+
|
|
245
|
+
8. **Convert Text to Speech**
|
|
246
|
+
|
|
162
247
|
```ruby
|
|
163
248
|
audio_data = client.text_to_speech("VOICE_ID", "Hello world!")
|
|
164
249
|
File.open("output.mp3", "wb") { |f| f.write(audio_data) }
|
|
165
250
|
```
|
|
166
|
-
8 Stream Text to Speech
|
|
167
|
-
stream from terminal
|
|
168
|
-
```ruby
|
|
169
|
-
Mac: brew install sox
|
|
170
|
-
Linux: sudo apt install sox
|
|
171
251
|
|
|
252
|
+
9. **Stream Text to Speech**
|
|
253
|
+
|
|
254
|
+
Stream from terminal:
|
|
255
|
+
|
|
256
|
+
```bash
|
|
257
|
+
# Mac: Install sox
|
|
258
|
+
brew install sox
|
|
259
|
+
# Linux: Install sox
|
|
260
|
+
sudo apt install sox
|
|
261
|
+
```
|
|
262
|
+
|
|
263
|
+
```ruby
|
|
172
264
|
IO.popen("play -t mp3 -", "wb") do |audio_pipe| # Notice "wb" (write binary)
|
|
173
265
|
client.text_to_speech_stream("VOICE_ID", "Some text to stream back in chunks") do |chunk|
|
|
174
266
|
audio_pipe.write(chunk.b) # Ensure chunk is written as binary
|
|
@@ -176,19 +268,71 @@ IO.popen("play -t mp3 -", "wb") do |audio_pipe| # Notice "wb" (write binary)
|
|
|
176
268
|
end
|
|
177
269
|
```
|
|
178
270
|
|
|
179
|
-
|
|
271
|
+
10. **Create a Voice from a Design**
|
|
272
|
+
|
|
273
|
+
Once you’ve generated a voice design using client.design_voice, you can turn it into a permanent voice in your account by passing its generated_voice_id to client.create_from_generated_voice.
|
|
274
|
+
|
|
275
|
+
# Step 1: Design a voice (returns previews + generated_voice_id)
|
|
276
|
+
```ruby
|
|
277
|
+
design_response = client.design_voice(
|
|
278
|
+
"A warm, friendly female voice with a slight Australian accent",
|
|
279
|
+
model_id: "eleven_multilingual_ttv_v2",
|
|
280
|
+
text: "Welcome to our podcast, where every story is an adventure, taking you on a journey through fascinating worlds, inspiring voices, and unforgettable moments.",
|
|
281
|
+
auto_generate_text: false
|
|
282
|
+
)
|
|
283
|
+
|
|
284
|
+
generated_voice_id = design_response["previews"].first["generated_voice_id"] #three previews are given, but for this example we will use the first to create a voice here
|
|
285
|
+
|
|
286
|
+
# Step 2: Create the permanent voice
|
|
287
|
+
create_response = client.create_from_generated_voice(
|
|
288
|
+
"Friendly Aussie",
|
|
289
|
+
"A warm, friendly Australian-accented voice for podcasts",
|
|
290
|
+
generated_voice_id,
|
|
291
|
+
)
|
|
292
|
+
|
|
293
|
+
voice_id = create_response["voice_id"] # This is the ID you can use for TTS
|
|
294
|
+
|
|
295
|
+
# Step 3: Use the new voice for TTS
|
|
296
|
+
audio_data = client.text_to_speech(voice_id, "This is my new permanent designed voice.")
|
|
297
|
+
File.open("friendly_aussie.mp3", "wb") { |f| f.write(audio_data) }
|
|
298
|
+
```
|
|
299
|
+
Important notes:
|
|
300
|
+
|
|
301
|
+
Always store the returned voice_id from create_voice_from_design. This is the permanent identifier for TTS.
|
|
302
|
+
|
|
303
|
+
Designed voices cannot be used for TTS until they are created in your account.
|
|
304
|
+
|
|
305
|
+
If the voice is not immediately available for TTS, wait a few seconds or check its status via client.get_voice(voice_id) until it’s "active".
|
|
306
|
+
|
|
307
|
+
10. Create a multi-speaker dialogue
|
|
308
|
+
```ruby
|
|
309
|
+
inputs = [{text: "It smells like updog in here", voice_id: "TX3LPaxmHKxFdv7VOQHJ"}, {text: "What's updog?", voice_id: "RILOU7YmBhvwJGDGjNmP"}, {text: "Not much, you?", voice_id: "TX3LPaxmHKxFdv7VOQHJ"}]
|
|
310
|
+
|
|
311
|
+
audio_data = client.text_to_dialogue(inputs)
|
|
312
|
+
File.open("what's updog.mp3", "wb") { |f| f.write(audio_data) }
|
|
313
|
+
```
|
|
314
|
+
|
|
315
|
+
---
|
|
316
|
+
|
|
317
|
+
## Error Handling
|
|
318
|
+
|
|
180
319
|
When the API returns an error, the gem raises specific exceptions:
|
|
181
320
|
|
|
182
|
-
Exception
|
|
183
|
-
|
|
184
|
-
Elevenlabs::
|
|
185
|
-
Elevenlabs::
|
|
186
|
-
Elevenlabs::
|
|
321
|
+
| Exception | Meaning |
|
|
322
|
+
|-------------------------------|----------------------------------|
|
|
323
|
+
| `Elevenlabs::BadRequestError` | Invalid request parameters |
|
|
324
|
+
| `Elevenlabs::AuthenticationError` | Invalid API key |
|
|
325
|
+
| `Elevenlabs::NotFoundError` | Resource (voice) not found |
|
|
326
|
+
| `Elevenlabs::UnprocessableEntityError` | Unprocessable entity (e.g., invalid input format) |
|
|
327
|
+
| `Elevenlabs::APIError` | General API failure |
|
|
328
|
+
|
|
187
329
|
Example:
|
|
188
330
|
|
|
189
331
|
```ruby
|
|
190
332
|
begin
|
|
191
|
-
client.
|
|
333
|
+
client.design_voice("Short description") # Too short, will raise error
|
|
334
|
+
rescue Elevenlabs::UnprocessableEntityError => e
|
|
335
|
+
puts "Validation error: #{e.message}"
|
|
192
336
|
rescue Elevenlabs::AuthenticationError => e
|
|
193
337
|
puts "Invalid API key: #{e.message}"
|
|
194
338
|
rescue Elevenlabs::NotFoundError => e
|
|
@@ -198,38 +342,54 @@ rescue Elevenlabs::APIError => e
|
|
|
198
342
|
end
|
|
199
343
|
```
|
|
200
344
|
|
|
201
|
-
|
|
202
|
-
|
|
345
|
+
---
|
|
346
|
+
|
|
347
|
+
## Development
|
|
348
|
+
|
|
349
|
+
Clone this repository:
|
|
350
|
+
|
|
203
351
|
```bash
|
|
204
352
|
git clone https://github.com/your-username/elevenlabs.git
|
|
205
353
|
cd elevenlabs
|
|
206
354
|
```
|
|
207
|
-
|
|
355
|
+
|
|
356
|
+
Install dependencies:
|
|
357
|
+
|
|
208
358
|
```bash
|
|
209
359
|
bundle install
|
|
210
360
|
```
|
|
211
|
-
|
|
361
|
+
|
|
362
|
+
Build the gem:
|
|
363
|
+
|
|
212
364
|
```bash
|
|
213
365
|
gem build elevenlabs.gemspec
|
|
214
366
|
```
|
|
215
|
-
|
|
367
|
+
|
|
368
|
+
Install the gem locally:
|
|
369
|
+
|
|
216
370
|
```bash
|
|
217
|
-
gem install ./elevenlabs-0.0.
|
|
371
|
+
gem install ./elevenlabs-0.0.5.gem
|
|
218
372
|
```
|
|
219
|
-
|
|
373
|
+
|
|
374
|
+
---
|
|
375
|
+
|
|
376
|
+
## Contributing
|
|
377
|
+
|
|
220
378
|
Contributions are welcome! Please follow these steps:
|
|
221
379
|
|
|
222
|
-
Fork the repository
|
|
223
|
-
Create a feature branch (git checkout -b feature/my-new-feature)
|
|
224
|
-
Commit your changes (git commit -am 'Add new feature')
|
|
225
|
-
Push to your branch (git push origin feature/my-new-feature)
|
|
226
|
-
Create a Pull Request describing your changes
|
|
380
|
+
1. Fork the repository
|
|
381
|
+
2. Create a feature branch (`git checkout -b feature/my-new-feature`)
|
|
382
|
+
3. Commit your changes (`git commit -am 'Add new feature'`)
|
|
383
|
+
4. Push to your branch (`git push origin feature/my-new-feature`)
|
|
384
|
+
5. Create a Pull Request describing your changes
|
|
385
|
+
|
|
227
386
|
For bug reports, please open an issue with details.
|
|
228
387
|
|
|
229
|
-
|
|
388
|
+
---
|
|
389
|
+
|
|
390
|
+
## License
|
|
391
|
+
|
|
230
392
|
This project is licensed under the MIT License. See the LICENSE file for details.
|
|
231
393
|
|
|
232
|
-
⭐ Thank you for using the Elevenlabs Ruby Gem!
|
|
394
|
+
⭐ Thank you for using the Elevenlabs Ruby Gem!
|
|
233
395
|
If you have any questions or suggestions, feel free to open an issue or submit a Pull Request!
|
|
234
|
-
|
|
235
|
-
# elevenlabs
|
data/lib/elevenlabs/client.rb
CHANGED
|
@@ -88,6 +88,133 @@ module Elevenlabs
|
|
|
88
88
|
handle_error(e)
|
|
89
89
|
end
|
|
90
90
|
|
|
91
|
+
#####################################################
|
|
92
|
+
# Text-to-Dialogue #
|
|
93
|
+
# (POST /v1/text-to-dialogue) #
|
|
94
|
+
#####################################################
|
|
95
|
+
|
|
96
|
+
# Converts a list of text and voice ID pairs into speech (dialogue) and returns audio.
|
|
97
|
+
# Documentation: https://elevenlabs.io/docs/api-reference/text-to-dialogue/convert
|
|
98
|
+
#
|
|
99
|
+
# @param [Array[Objects]] inputs - A list of dialogue inputs, each containing text and a voice ID which will be converted into speech
|
|
100
|
+
# :text => String
|
|
101
|
+
# :voice_id => String
|
|
102
|
+
# @param [String] model_id - optional Identifier of the model to be used
|
|
103
|
+
# @param [Hash] settings - optinal Settings controlling the dialogue generation
|
|
104
|
+
# :stability => double - 0.0 = Creative, 0.5 = Natural, 1.0 = Robust
|
|
105
|
+
# :use_speaker_boost => boolean
|
|
106
|
+
# @param [Integer] seed - optional Best effort to sample deterministically.
|
|
107
|
+
#
|
|
108
|
+
# @return [String] The binary audio data (usually an MP3).
|
|
109
|
+
def text_to_dialogue(inputs, model_id = nil, settings = {}, seed = nil)
|
|
110
|
+
endpoint = "/v1/text-to-dialogue"
|
|
111
|
+
request_body = {}.tap do |r|
|
|
112
|
+
r[:inputs] = inputs
|
|
113
|
+
r[:model_id] = model_id if model_id
|
|
114
|
+
r[:settings] = settings unless settings.empty?
|
|
115
|
+
r[:seed] = seed if seed
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
headers = default_headers
|
|
119
|
+
headers["Accept"] = "audio/mpeg"
|
|
120
|
+
|
|
121
|
+
response = @connection.post(endpoint) do |req|
|
|
122
|
+
req.headers = headers
|
|
123
|
+
req.body = request_body.to_json
|
|
124
|
+
end
|
|
125
|
+
|
|
126
|
+
# Returns raw binary data (often MP3)
|
|
127
|
+
response.body
|
|
128
|
+
rescue Faraday::ClientError => e
|
|
129
|
+
handle_error(e)
|
|
130
|
+
end
|
|
131
|
+
|
|
132
|
+
#####################################################
|
|
133
|
+
# Design a Voice #
|
|
134
|
+
# (POST /v1/text-to-voice/design) #
|
|
135
|
+
#####################################################
|
|
136
|
+
|
|
137
|
+
# Designs a voice based on a description
|
|
138
|
+
# Documentation: https://elevenlabs.io/docs/api-reference/text-to-voice/design
|
|
139
|
+
#
|
|
140
|
+
# @param [String] voice_description - Description of the voice (20-1000 characters)
|
|
141
|
+
# @param [Hash] options - Optional parameters
|
|
142
|
+
# :output_format => String (e.g., "mp3_44100_192", default: "mp3_44100_192")
|
|
143
|
+
# :model_id => String (e.g., "eleven_multilingual_ttv_v2", "eleven_ttv_v3")
|
|
144
|
+
# :text => String (100-1000 characters, optional)
|
|
145
|
+
# :auto_generate_text => Boolean (default: false)
|
|
146
|
+
# :loudness => Float (-1 to 1, default: 0.5)
|
|
147
|
+
# :seed => Integer (0 to 2147483647, optional)
|
|
148
|
+
# :guidance_scale => Float (0 to 100, default: 5)
|
|
149
|
+
# :stream_previews => Boolean (default: false)
|
|
150
|
+
# :remixing_session_id => String (optional)
|
|
151
|
+
# :remixing_session_iteration_id => String (optional)
|
|
152
|
+
# :quality => Float (-1 to 1, optional)
|
|
153
|
+
# :reference_audio_base64 => String (base64 encoded audio, optional, requires eleven_ttv_v3)
|
|
154
|
+
# :prompt_strength => Float (0 to 1, optional, requires eleven_ttv_v3)
|
|
155
|
+
#
|
|
156
|
+
# @return [Hash] JSON response containing previews and text
|
|
157
|
+
def design_voice(voice_description, options = {})
|
|
158
|
+
endpoint = "/v1/text-to-voice/design"
|
|
159
|
+
request_body = { voice_description: voice_description }
|
|
160
|
+
|
|
161
|
+
# Add optional parameters if provided
|
|
162
|
+
request_body[:output_format] = options[:output_format] if options[:output_format]
|
|
163
|
+
request_body[:model_id] = options[:model_id] if options[:model_id]
|
|
164
|
+
request_body[:text] = options[:text] if options[:text]
|
|
165
|
+
request_body[:auto_generate_text] = options[:auto_generate_text] unless options[:auto_generate_text].nil?
|
|
166
|
+
request_body[:loudness] = options[:loudness] if options[:loudness]
|
|
167
|
+
request_body[:seed] = options[:seed] if options[:seed]
|
|
168
|
+
request_body[:guidance_scale] = options[:guidance_scale] if options[:guidance_scale]
|
|
169
|
+
request_body[:stream_previews] = options[:stream_previews] unless options[:stream_previews].nil?
|
|
170
|
+
request_body[:remixing_session_id] = options[:remixing_session_id] if options[:remixing_session_id]
|
|
171
|
+
request_body[:remixing_session_iteration_id] = options[:remixing_session_iteration_id] if options[:remixing_session_iteration_id]
|
|
172
|
+
request_body[:quality] = options[:quality] if options[:quality]
|
|
173
|
+
request_body[:reference_audio_base64] = options[:reference_audio_base64] if options[:reference_audio_base64]
|
|
174
|
+
request_body[:prompt_strength] = options[:prompt_strength] if options[:prompt_strength]
|
|
175
|
+
|
|
176
|
+
response = @connection.post(endpoint) do |req|
|
|
177
|
+
req.headers = default_headers
|
|
178
|
+
req.body = request_body.to_json
|
|
179
|
+
end
|
|
180
|
+
|
|
181
|
+
JSON.parse(response.body)
|
|
182
|
+
rescue Faraday::ClientError => e
|
|
183
|
+
handle_error(e)
|
|
184
|
+
end
|
|
185
|
+
|
|
186
|
+
#####################################################
|
|
187
|
+
# Create a Voice #
|
|
188
|
+
# (POST /v1/text-to-voice/create) #
|
|
189
|
+
#####################################################
|
|
190
|
+
# Creates a voice from the designed voice generated_voice_id
|
|
191
|
+
# Documentation: https://elevenlabs.io/docs/api-reference/text-to-voice
|
|
192
|
+
#
|
|
193
|
+
# @param [String] voice_name - Name of the voice
|
|
194
|
+
# @param [String] voice_description - Description of the voice (20-1000 characters)
|
|
195
|
+
# @param [String] generated_voice_id - The generated voice ID from design_voice
|
|
196
|
+
# @param [Hash] labels - Optional metadata for the voice
|
|
197
|
+
# @param [Array<String>] played_not_selected_voice_ids - Optional list of voice IDs played but not selected
|
|
198
|
+
#
|
|
199
|
+
# @return [Hash] JSON response containing voice_id and other voice details
|
|
200
|
+
def create_from_generated_voice(voice_name, voice_description, generated_voice_id, labels: nil, played_not_selected_voice_ids: nil)
|
|
201
|
+
endpoint = "/v1/text-to-voice"
|
|
202
|
+
request_body = {
|
|
203
|
+
voice_name: voice_name,
|
|
204
|
+
voice_description: voice_description,
|
|
205
|
+
generated_voice_id: generated_voice_id,
|
|
206
|
+
labels: labels,
|
|
207
|
+
played_not_selected_voice_ids: played_not_selected_voice_ids
|
|
208
|
+
}.compact
|
|
209
|
+
|
|
210
|
+
response = @connection.post(endpoint) do |req|
|
|
211
|
+
req.headers = default_headers
|
|
212
|
+
req.body = request_body.to_json
|
|
213
|
+
end
|
|
214
|
+
JSON.parse(response.body)
|
|
215
|
+
rescue Faraday::ClientError => e
|
|
216
|
+
handle_error(e)
|
|
217
|
+
end
|
|
91
218
|
|
|
92
219
|
#####################################################
|
|
93
220
|
# GET Voices #
|
|
@@ -108,6 +235,25 @@ module Elevenlabs
|
|
|
108
235
|
handle_error(e)
|
|
109
236
|
end
|
|
110
237
|
|
|
238
|
+
#####################################################
|
|
239
|
+
# GET models #
|
|
240
|
+
# (GET /v1/models) #
|
|
241
|
+
#####################################################
|
|
242
|
+
|
|
243
|
+
# Gets a list of available models
|
|
244
|
+
# Documentation: https://elevenlabs.io/docs/api-reference/models/list
|
|
245
|
+
#
|
|
246
|
+
# @return [Hash] The JSON response containing an array of models
|
|
247
|
+
def list_models
|
|
248
|
+
endpoint = "/v1/models"
|
|
249
|
+
response = @connection.get(endpoint) do |req|
|
|
250
|
+
req.headers = default_headers
|
|
251
|
+
end
|
|
252
|
+
JSON.parse(response.body)
|
|
253
|
+
rescue Faraday::ClientError => e
|
|
254
|
+
handle_error(e)
|
|
255
|
+
end
|
|
256
|
+
|
|
111
257
|
#####################################################
|
|
112
258
|
# GET a Single Voice #
|
|
113
259
|
# (GET /v1/voices/{voice_id}) #
|
data/lib/elevenlabs/errors.rb
CHANGED
data/lib/elevenlabs.rb
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: elevenlabs
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.0.
|
|
4
|
+
version: 0.0.6
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- hackliteracy
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2025-
|
|
11
|
+
date: 2025-08-23 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: faraday
|
|
@@ -39,7 +39,7 @@ dependencies:
|
|
|
39
39
|
- !ruby/object:Gem::Version
|
|
40
40
|
version: '1.1'
|
|
41
41
|
description: This gem provides a convenient Ruby interface to the ElevenLabs TTS,
|
|
42
|
-
Voice Cloning, and Streaming endpoints.
|
|
42
|
+
Voice Cloning, Voice Design, Voice dialogues and Streaming endpoints.
|
|
43
43
|
email:
|
|
44
44
|
- hackliteracy@gmail.com
|
|
45
45
|
executables: []
|