Class: ElevenlabsClient::Voices

Inherits:
Object
  • Object
show all
Defined in:
lib/elevenlabs_client/endpoints/voices.rb

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ Voices

Returns a new instance of Voices.



5
6
7
# File 'lib/elevenlabs_client/endpoints/voices.rb', line 5

def initialize(client)
  @client = client
end

Instance Method Details

#active?(voice_id) ⇒ Boolean

Check if a voice is active (exists in the voice list)

Parameters:

  • voice_id (String)

    The ID of the voice to check

Returns:

  • (Boolean)

    True if the voice is active



495
496
497
498
499
500
501
502
# File 'lib/elevenlabs_client/endpoints/voices.rb', line 495

def active?(voice_id)
  voices = list
  active_voice_ids = voices["voices"].map { |voice| voice["voice_id"] }
  active_voice_ids.include?(voice_id)
rescue ElevenlabsClient::ValidationError, ElevenlabsClient::APIError, ElevenlabsClient::NotFoundError
  # If we can't get the voice list, assume it's not active
  false
end

#add_pvc_samples(voice_id, audio_files, filenames, **options) ⇒ Array<Hash>

POST /v1/voices/pvc/voice_id/samples Add audio samples to a PVC voice Documentation: https://elevenlabs.io/docs/api-reference/voices/add-pvc-samples

Parameters:

  • voice_id (String)

    Voice ID

  • audio_files (Array<IO, File>)

    Audio files for the voice

  • filenames (Array<String>)

    Original filenames

  • options (Hash)

    Optional parameters

Options Hash (**options):

  • :remove_background_noise (Boolean)

    Remove background noise (default: false)

Returns:

  • (Array<Hash>)

    Array of sample information



299
300
301
302
303
304
305
306
307
308
309
310
311
312
# File 'lib/elevenlabs_client/endpoints/voices.rb', line 299

def add_pvc_samples(voice_id, audio_files, filenames, **options)
  endpoint = "/v1/voices/pvc/#{voice_id}/samples"
  
  payload = {}
  payload[:remove_background_noise] = options[:remove_background_noise] unless options[:remove_background_noise].nil?
  
  # Add audio files
  audio_files.each_with_index do |file, index|
    filename = filenames[index] || "audio_#{index}.mp3"
    payload["files[]"] = @client.file_part(file, filename)
  end

  @client.post_multipart(endpoint, payload)
end

#banned?(voice_id) ⇒ Boolean

Check if a voice is banned (safety control)

Parameters:

  • voice_id (String)

    The ID of the voice to check

Returns:

  • (Boolean)

    True if the voice is banned



484
485
486
487
488
489
490
# File 'lib/elevenlabs_client/endpoints/voices.rb', line 484

def banned?(voice_id)
  voice = get(voice_id)
  voice["safety_control"] == "BAN"
rescue ElevenlabsClient::ValidationError, ElevenlabsClient::APIError, ElevenlabsClient::NotFoundError
  # If we can't get the voice, assume it's not banned
  false
end

#create(name, samples = [], **options) ⇒ Hash Also known as: create_voice

POST /v1/voices/add Creates a new voice by cloning from audio samples Documentation: https://elevenlabs.io/docs/api-reference/voices/add-voice

Parameters:

  • name (String)

    Name of the voice

  • samples (Array<File, IO>) (defaults to: [])

    Array of audio files to train the voice

  • options (Hash)

    Additional parameters

Options Hash (**options):

  • :description (String)

    Description of the voice

  • :labels (Hash)

    Metadata labels for the voice

Returns:

  • (Hash)

    Response containing the new voice details



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/elevenlabs_client/endpoints/voices.rb', line 40

def create(name, samples = [], **options)
  endpoint = "/v1/voices/add"
  
  # Build multipart payload
  payload = {
    "name" => name,
    "description" => options[:description] || ""
  }

  # Add labels if provided
  if options[:labels]
    options[:labels].each do |key, value|
      payload["labels[#{key}]"] = value.to_s
    end
  end

  # Add sample files
  samples.each_with_index do |sample, index|
    payload["files"] = @client.file_part(sample, "audio/mpeg")
  end

  @client.post_multipart(endpoint, payload)
end

#create_ivc(name, audio_files, filenames, **options) ⇒ Hash

POST /v1/voices/add Creates a new IVC (Instant Voice Cloning) voice Documentation: https://elevenlabs.io/docs/api-reference/voices/add-voice

Parameters:

  • name (String)

    Name of the voice

  • audio_files (Array<IO, File>)

    Array of audio files for voice cloning

  • filenames (Array<String>)

    Array of original filenames

  • options (Hash)

    Optional parameters

Options Hash (**options):

  • :remove_background_noise (Boolean)

    Remove background noise (default: false)

  • :description (String)

    Description of the voice

  • :labels (String)

    Serialized labels dictionary

Returns:

  • (Hash)

    Response containing voice_id and requires_verification status



148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
# File 'lib/elevenlabs_client/endpoints/voices.rb', line 148

def create_ivc(name, audio_files, filenames, **options)
  endpoint = "/v1/voices/add"
  
  payload = { name: name }
  
  # Add optional parameters
  payload[:remove_background_noise] = options[:remove_background_noise] unless options[:remove_background_noise].nil?
  payload[:description] = options[:description] if options[:description]
  payload[:labels] = options[:labels] if options[:labels]
  
  # Add audio files
  audio_files.each_with_index do |file, index|
    filename = filenames[index] || "audio_#{index}.mp3"
    payload["files[]"] = @client.file_part(file, filename)
  end

  @client.post_multipart(endpoint, payload)
end

#create_pvc(name, language, **options) ⇒ Hash

POST /v1/voices/pvc Creates a new PVC (Professional Voice Cloning) voice with metadata but no samples Documentation: https://elevenlabs.io/docs/api-reference/voices/create-pvc

Parameters:

  • name (String)

    Name of the voice (max 100 characters)

  • language (String)

    Language used in the samples

  • options (Hash)

    Optional parameters

Options Hash (**options):

  • :description (String)

    Description (max 500 characters)

  • :labels (Hash)

    Serialized labels dictionary

Returns:

  • (Hash)

    Response containing voice_id



235
236
237
238
239
240
241
242
243
244
245
246
247
# File 'lib/elevenlabs_client/endpoints/voices.rb', line 235

def create_pvc(name, language, **options)
  endpoint = "/v1/voices/pvc"
  
  payload = {
    name: name,
    language: language
  }
  
  payload[:description] = options[:description] if options[:description]
  payload[:labels] = options[:labels] if options[:labels]

  @client.post(endpoint, payload)
end

#delete(voice_id) ⇒ Hash Also known as: delete_voice

DELETE /v1/voices/voice_id Deletes a voice from your account Documentation: https://elevenlabs.io/docs/api-reference/voices/delete-voice

Parameters:

  • voice_id (String)

    The ID of the voice to delete

Returns:

  • (Hash)

    Response confirming deletion



108
109
110
111
# File 'lib/elevenlabs_client/endpoints/voices.rb', line 108

def delete(voice_id)
  endpoint = "/v1/voices/#{voice_id}"
  @client.delete(endpoint)
end

#delete_pvc_sample(voice_id, sample_id) ⇒ Hash

DELETE /v1/voices/pvc/voice_id/samples/sample_id Delete a sample from a PVC voice Documentation: https://elevenlabs.io/docs/api-reference/voices/delete-pvc-sample

Parameters:

  • voice_id (String)

    Voice ID

  • sample_id (String)

    Sample ID

Returns:

  • (Hash)

    Response with status



345
346
347
348
# File 'lib/elevenlabs_client/endpoints/voices.rb', line 345

def delete_pvc_sample(voice_id, sample_id)
  endpoint = "/v1/voices/pvc/#{voice_id}/samples/#{sample_id}"
  @client.delete(endpoint)
end

#edit(voice_id, samples = [], **options) ⇒ Hash Also known as: edit_voice

POST /v1/voices/voice_id/edit Updates an existing voice Documentation: https://elevenlabs.io/docs/api-reference/voices/edit-voice

Parameters:

  • voice_id (String)

    The ID of the voice to edit

  • samples (Array<File, IO>) (defaults to: [])

    Array of audio files (optional)

  • options (Hash)

    Voice parameters to update

Options Hash (**options):

  • :name (String)

    New name for the voice

  • :description (String)

    New description for the voice

  • :labels (Hash)

    New labels for the voice

Returns:

  • (Hash)

    Response containing the updated voice details



75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/elevenlabs_client/endpoints/voices.rb', line 75

def edit(voice_id, samples = [], **options)
  endpoint = "/v1/voices/#{voice_id}/edit"
  
  # Build multipart payload
  payload = {}
  
  # Add text fields if provided
  payload["name"] = options[:name] if options[:name]
  payload["description"] = options[:description] if options[:description]

  # Add labels if provided
  if options[:labels]
    options[:labels].each do |key, value|
      payload["labels[#{key}]"] = value.to_s
    end
  end

  # Add sample files if provided
  if samples && !samples.empty?
    samples.each_with_index do |sample, index|
      payload["files"] = @client.file_part(sample, "audio/mpeg")
    end
  end

  @client.post_multipart(endpoint, payload)
end

#edit_settings(voice_id, **options) ⇒ Hash Also known as: update_settings

POST /v1/voices/voice_id/settings/edit Edit settings for a specific voice Documentation: https://elevenlabs.io/docs/api-reference/voices/edit-settings

Parameters:

  • voice_id (String)

    Voice ID

  • options (Hash)

    Voice settings to update

Options Hash (**options):

  • :stability (Float)

    Stability setting (0.0-1.0)

  • :use_speaker_boost (Boolean)

    Enable speaker boost

  • :similarity_boost (Float)

    Similarity boost setting (0.0-1.0)

  • :style (Float)

    Style exaggeration (0.0-1.0)

  • :speed (Float)

    Speed adjustment (0.25-4.0)

Returns:

  • (Hash)

    Response with status



200
201
202
203
204
205
206
207
208
209
210
211
# File 'lib/elevenlabs_client/endpoints/voices.rb', line 200

def edit_settings(voice_id, **options)
  endpoint = "/v1/voices/#{voice_id}/settings/edit"
  
  payload = {}
  payload[:stability] = options[:stability] if options[:stability]
  payload[:use_speaker_boost] = options[:use_speaker_boost] unless options[:use_speaker_boost].nil?
  payload[:similarity_boost] = options[:similarity_boost] if options[:similarity_boost]
  payload[:style] = options[:style] if options[:style]
  payload[:speed] = options[:speed] if options[:speed]

  @client.post(endpoint, payload)
end

#find_similar(audio_file, filename, **options) ⇒ Hash Also known as: similar_voices

POST /v1/similar-voices Returns a list of shared voices similar to the provided audio sample Documentation: https://elevenlabs.io/docs/api-reference/voices/similar-voices

Parameters:

  • audio_file (IO, File)

    Audio file to find similar voices for

  • filename (String)

    Original filename for the audio file

  • options (Hash)

    Optional parameters

Options Hash (**options):

  • :similarity_threshold (Float)

    Threshold for voice similarity (0-2)

  • :top_k (Integer)

    Number of most similar voices to return (1-100)

Returns:

  • (Hash)

    Response containing similar voices



123
124
125
126
127
128
129
130
131
132
133
134
# File 'lib/elevenlabs_client/endpoints/voices.rb', line 123

def find_similar(audio_file, filename, **options)
  endpoint = "/v1/similar-voices"
  
  payload = {
    audio_file: @client.file_part(audio_file, filename)
  }
  
  payload[:similarity_threshold] = options[:similarity_threshold] if options[:similarity_threshold]
  payload[:top_k] = options[:top_k] if options[:top_k]

  @client.post_multipart(endpoint, payload)
end

#get(voice_id) ⇒ Hash Also known as: get_voice

GET /v1/voices/voice_id Retrieves details about a single voice Documentation: https://elevenlabs.io/docs/api-reference/voices/get-voice

Parameters:

  • voice_id (String)

    The ID of the voice to retrieve

Returns:

  • (Hash)

    Details of the voice



15
16
17
18
# File 'lib/elevenlabs_client/endpoints/voices.rb', line 15

def get(voice_id)
  endpoint = "/v1/voices/#{voice_id}"
  @client.get(endpoint)
end

#get_default_settingsHash Also known as: default_settings

GET /v1/voices/settings/default Gets the default settings for voices Documentation: https://elevenlabs.io/docs/api-reference/voices/default-settings

Returns:

  • (Hash)

    Default voice settings



172
173
174
175
# File 'lib/elevenlabs_client/endpoints/voices.rb', line 172

def get_default_settings
  endpoint = "/v1/voices/settings/default"
  @client.get(endpoint)
end

#get_pvc_captcha(voice_id) ⇒ Hash

GET /v1/voices/pvc/voice_id/captcha Get captcha for PVC voice verification Documentation: https://elevenlabs.io/docs/api-reference/voices/get-pvc-captcha

Parameters:

  • voice_id (String)

    Voice ID

Returns:

  • (Hash)

    Captcha data



448
449
450
451
# File 'lib/elevenlabs_client/endpoints/voices.rb', line 448

def get_pvc_captcha(voice_id)
  endpoint = "/v1/voices/pvc/#{voice_id}/captcha"
  @client.get(endpoint)
end

#get_pvc_sample_audio(voice_id, sample_id, **options) ⇒ Hash

GET /v1/voices/pvc/voice_id/samples/sample_id/audio Retrieve voice sample audio with or without noise removal Documentation: https://elevenlabs.io/docs/api-reference/voices/get-pvc-sample-audio

Parameters:

  • voice_id (String)

    Voice ID

  • sample_id (String)

    Sample ID

  • options (Hash)

    Optional parameters

Options Hash (**options):

  • :remove_background_noise (Boolean)

    Remove background noise (default: false)

Returns:

  • (Hash)

    Response with base64 audio data and metadata



359
360
361
362
363
364
365
366
# File 'lib/elevenlabs_client/endpoints/voices.rb', line 359

def get_pvc_sample_audio(voice_id, sample_id, **options)
  endpoint = "/v1/voices/pvc/#{voice_id}/samples/#{sample_id}/audio"
  
  params = {}
  params[:remove_background_noise] = options[:remove_background_noise] unless options[:remove_background_noise].nil?

  @client.get(endpoint, params)
end

#get_pvc_sample_waveform(voice_id, sample_id) ⇒ Hash

GET /v1/voices/pvc/voice_id/samples/sample_id/waveform Retrieve the visual waveform of a voice sample Documentation: https://elevenlabs.io/docs/api-reference/voices/get-pvc-waveform

Parameters:

  • voice_id (String)

    Voice ID

  • sample_id (String)

    Sample ID

Returns:

  • (Hash)

    Response with sample_id and visual_waveform array



375
376
377
378
# File 'lib/elevenlabs_client/endpoints/voices.rb', line 375

def get_pvc_sample_waveform(voice_id, sample_id)
  endpoint = "/v1/voices/pvc/#{voice_id}/samples/#{sample_id}/waveform"
  @client.get(endpoint)
end

#get_pvc_separated_speaker_audio(voice_id, sample_id, speaker_id) ⇒ Hash

GET /v1/voices/pvc/voice_id/samples/sample_id/speakers/speaker_id/audio Retrieve separated audio for a specific speaker Documentation: https://elevenlabs.io/docs/api-reference/voices/get-separated-speaker-audio

Parameters:

  • voice_id (String)

    Voice ID

  • sample_id (String)

    Sample ID

  • speaker_id (String)

    Speaker ID

Returns:

  • (Hash)

    Response with base64 audio data and metadata



412
413
414
415
# File 'lib/elevenlabs_client/endpoints/voices.rb', line 412

def get_pvc_separated_speaker_audio(voice_id, sample_id, speaker_id)
  endpoint = "/v1/voices/pvc/#{voice_id}/samples/#{sample_id}/speakers/#{speaker_id}/audio"
  @client.get(endpoint)
end

#get_pvc_speaker_separation_status(voice_id, sample_id) ⇒ Hash

GET /v1/voices/pvc/voice_id/samples/sample_id/speakers Retrieve speaker separation status and detected speakers Documentation: https://elevenlabs.io/docs/api-reference/voices/get-pvc-speakers

Parameters:

  • voice_id (String)

    Voice ID

  • sample_id (String)

    Sample ID

Returns:

  • (Hash)

    Response with separation status and speakers



387
388
389
390
# File 'lib/elevenlabs_client/endpoints/voices.rb', line 387

def get_pvc_speaker_separation_status(voice_id, sample_id)
  endpoint = "/v1/voices/pvc/#{voice_id}/samples/#{sample_id}/speakers"
  @client.get(endpoint)
end

#get_sample_audio(voice_id, sample_id) ⇒ String

GET /v1/voices/voice_id/samples/sample_id/audio Returns the audio corresponding to a sample attached to a voice Documentation: https://elevenlabs.io/docs/api-reference/voices/get-sample-audio

Parameters:

  • voice_id (String)

    Voice ID

  • sample_id (String)

    Sample ID

Returns:

  • (String)

    Binary audio data



220
221
222
223
# File 'lib/elevenlabs_client/endpoints/voices.rb', line 220

def get_sample_audio(voice_id, sample_id)
  endpoint = "/v1/voices/#{voice_id}/samples/#{sample_id}/audio"
  @client.get(endpoint)
end

#get_settings(voice_id) ⇒ Hash Also known as: voice_settings

GET /v1/voices/voice_id/settings Returns the settings for a specific voice Documentation: https://elevenlabs.io/docs/api-reference/voices/get-settings

Parameters:

  • voice_id (String)

    Voice ID

Returns:

  • (Hash)

    Voice settings



183
184
185
186
# File 'lib/elevenlabs_client/endpoints/voices.rb', line 183

def get_settings(voice_id)
  endpoint = "/v1/voices/#{voice_id}/settings"
  @client.get(endpoint)
end

#listHash Also known as: list_voices

GET /v1/voices Retrieves all voices associated with your Elevenlabs account Documentation: https://elevenlabs.io/docs/api-reference/voices

Returns:

  • (Hash)

    The JSON response containing an array of voices



25
26
27
28
# File 'lib/elevenlabs_client/endpoints/voices.rb', line 25

def list
  endpoint = "/v1/voices"
  @client.get(endpoint)
end

#request_pvc_verification(voice_id, verification_files, filenames, **options) ⇒ Hash

POST /v1/voices/pvc/voice_id/verification Request manual verification for a PVC voice Documentation: https://elevenlabs.io/docs/api-reference/voices/request-pvc-verification

Parameters:

  • voice_id (String)

    Voice ID

  • verification_files (Array<IO, File>)

    Verification documents

  • filenames (Array<String>)

    Original filenames

  • options (Hash)

    Optional parameters

Options Hash (**options):

  • :extra_text (String)

    Extra text for verification process

Returns:

  • (Hash)

    Response with status



427
428
429
430
431
432
433
434
435
436
437
438
439
440
# File 'lib/elevenlabs_client/endpoints/voices.rb', line 427

def request_pvc_verification(voice_id, verification_files, filenames, **options)
  endpoint = "/v1/voices/pvc/#{voice_id}/verification"
  
  payload = {}
  payload[:extra_text] = options[:extra_text] if options[:extra_text]
  
  # Add verification files
  verification_files.each_with_index do |file, index|
    filename = filenames[index] || "verification_#{index}.pdf"
    payload["files[]"] = @client.file_part(file, filename)
  end

  @client.post_multipart(endpoint, payload)
end

#start_pvc_speaker_separation(voice_id, sample_id) ⇒ Hash

POST /v1/voices/pvc/voice_id/samples/sample_id/separate-speakers Start speaker separation process for a sample Documentation: https://elevenlabs.io/docs/api-reference/voices/start-speaker-separation

Parameters:

  • voice_id (String)

    Voice ID

  • sample_id (String)

    Sample ID

Returns:

  • (Hash)

    Response with status



399
400
401
402
# File 'lib/elevenlabs_client/endpoints/voices.rb', line 399

def start_pvc_speaker_separation(voice_id, sample_id)
  endpoint = "/v1/voices/pvc/#{voice_id}/samples/#{sample_id}/separate-speakers"
  @client.post(endpoint)
end

#train_pvc(voice_id, **options) ⇒ Hash

POST /v1/voices/pvc/voice_id/train Start PVC training process for a voice Documentation: https://elevenlabs.io/docs/api-reference/voices/train-pvc

Parameters:

  • voice_id (String)

    Voice ID

  • options (Hash)

    Optional parameters

Options Hash (**options):

  • :model_id (String)

    Model ID to use for conversion

Returns:

  • (Hash)

    Response with status



280
281
282
283
284
285
286
287
# File 'lib/elevenlabs_client/endpoints/voices.rb', line 280

def train_pvc(voice_id, **options)
  endpoint = "/v1/voices/pvc/#{voice_id}/train"
  
  payload = {}
  payload[:model_id] = options[:model_id] if options[:model_id]

  @client.post(endpoint, payload)
end

#update_pvc(voice_id, **options) ⇒ Hash

POST /v1/voices/pvc/voice_id Edit PVC voice metadata Documentation: https://elevenlabs.io/docs/api-reference/voices/update-pvc

Parameters:

  • voice_id (String)

    Voice ID

  • options (Hash)

    Parameters to update

Options Hash (**options):

  • :name (String)

    New name (max 100 characters)

  • :language (String)

    New language

  • :description (String)

    New description (max 500 characters)

  • :labels (Hash)

    New labels dictionary

Returns:

  • (Hash)

    Response containing voice_id



260
261
262
263
264
265
266
267
268
269
270
# File 'lib/elevenlabs_client/endpoints/voices.rb', line 260

def update_pvc(voice_id, **options)
  endpoint = "/v1/voices/pvc/#{voice_id}"
  
  payload = {}
  payload[:name] = options[:name] if options[:name]
  payload[:language] = options[:language] if options[:language]
  payload[:description] = options[:description] if options[:description]
  payload[:labels] = options[:labels] if options[:labels]

  @client.post(endpoint, payload)
end

#update_pvc_sample(voice_id, sample_id, **options) ⇒ Hash

POST /v1/voices/pvc/voice_id/samples/sample_id Update a PVC voice sample - apply noise removal or select speaker Documentation: https://elevenlabs.io/docs/api-reference/voices/update-pvc-sample

Parameters:

  • voice_id (String)

    Voice ID

  • sample_id (String)

    Sample ID

  • options (Hash)

    Update parameters

Options Hash (**options):

  • :remove_background_noise (Boolean)

    Remove background noise

  • :selected_speaker_ids (Array<String>)

    Speaker IDs for training

  • :trim_start_time (Integer)

    Start time in milliseconds

  • :trim_end_time (Integer)

    End time in milliseconds

Returns:

  • (Hash)

    Response containing voice_id



326
327
328
329
330
331
332
333
334
335
336
# File 'lib/elevenlabs_client/endpoints/voices.rb', line 326

def update_pvc_sample(voice_id, sample_id, **options)
  endpoint = "/v1/voices/pvc/#{voice_id}/samples/#{sample_id}"
  
  payload = {}
  payload[:remove_background_noise] = options[:remove_background_noise] unless options[:remove_background_noise].nil?
  payload[:selected_speaker_ids] = options[:selected_speaker_ids] if options[:selected_speaker_ids]
  payload[:trim_start_time] = options[:trim_start_time] if options[:trim_start_time]
  payload[:trim_end_time] = options[:trim_end_time] if options[:trim_end_time]

  @client.post(endpoint, payload)
end

#verify_pvc_captcha(voice_id, recording_file, filename) ⇒ Hash

POST /v1/voices/pvc/voice_id/captcha Submit captcha verification for PVC voice Documentation: https://elevenlabs.io/docs/api-reference/voices/verify-pvc-captcha

Parameters:

  • voice_id (String)

    Voice ID

  • recording_file (IO, File)

    Audio recording of the user

  • filename (String)

    Original filename for the recording

Returns:

  • (Hash)

    Response with status



461
462
463
464
465
466
467
468
469
# File 'lib/elevenlabs_client/endpoints/voices.rb', line 461

def verify_pvc_captcha(voice_id, recording_file, filename)
  endpoint = "/v1/voices/pvc/#{voice_id}/captcha"
  
  payload = {
    recording: @client.file_part(recording_file, filename)
  }

  @client.post_multipart(endpoint, payload)
end