elevenlabs_client 0.1.0 → 0.3.0

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.
@@ -0,0 +1,147 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ElevenlabsClient
4
+ class Voices
5
+ def initialize(client)
6
+ @client = client
7
+ end
8
+
9
+ # GET /v1/voices/{voice_id}
10
+ # Retrieves details about a single voice
11
+ # Documentation: https://elevenlabs.io/docs/api-reference/voices/get-voice
12
+ #
13
+ # @param voice_id [String] The ID of the voice to retrieve
14
+ # @return [Hash] Details of the voice
15
+ def get(voice_id)
16
+ endpoint = "/v1/voices/#{voice_id}"
17
+ @client.get(endpoint)
18
+ end
19
+
20
+ # GET /v1/voices
21
+ # Retrieves all voices associated with your Elevenlabs account
22
+ # Documentation: https://elevenlabs.io/docs/api-reference/voices
23
+ #
24
+ # @return [Hash] The JSON response containing an array of voices
25
+ def list
26
+ endpoint = "/v1/voices"
27
+ @client.get(endpoint)
28
+ end
29
+
30
+ # POST /v1/voices/add
31
+ # Creates a new voice by cloning from audio samples
32
+ # Documentation: https://elevenlabs.io/docs/api-reference/voices/add-voice
33
+ #
34
+ # @param name [String] Name of the voice
35
+ # @param samples [Array<File, IO>] Array of audio files to train the voice
36
+ # @param options [Hash] Additional parameters
37
+ # @option options [String] :description Description of the voice
38
+ # @option options [Hash] :labels Metadata labels for the voice
39
+ # @return [Hash] Response containing the new voice details
40
+ def create(name, samples = [], **options)
41
+ endpoint = "/v1/voices/add"
42
+
43
+ # Build multipart payload
44
+ payload = {
45
+ "name" => name,
46
+ "description" => options[:description] || ""
47
+ }
48
+
49
+ # Add labels if provided
50
+ if options[:labels]
51
+ options[:labels].each do |key, value|
52
+ payload["labels[#{key}]"] = value.to_s
53
+ end
54
+ end
55
+
56
+ # Add sample files
57
+ samples.each_with_index do |sample, index|
58
+ payload["files"] = @client.file_part(sample, "audio/mpeg")
59
+ end
60
+
61
+ @client.post_multipart(endpoint, payload)
62
+ end
63
+
64
+ # POST /v1/voices/{voice_id}/edit
65
+ # Updates an existing voice
66
+ # Documentation: https://elevenlabs.io/docs/api-reference/voices/edit-voice
67
+ #
68
+ # @param voice_id [String] The ID of the voice to edit
69
+ # @param samples [Array<File, IO>] Array of audio files (optional)
70
+ # @param options [Hash] Voice parameters to update
71
+ # @option options [String] :name New name for the voice
72
+ # @option options [String] :description New description for the voice
73
+ # @option options [Hash] :labels New labels for the voice
74
+ # @return [Hash] Response containing the updated voice details
75
+ def edit(voice_id, samples = [], **options)
76
+ endpoint = "/v1/voices/#{voice_id}/edit"
77
+
78
+ # Build multipart payload
79
+ payload = {}
80
+
81
+ # Add text fields if provided
82
+ payload["name"] = options[:name] if options[:name]
83
+ payload["description"] = options[:description] if options[:description]
84
+
85
+ # Add labels if provided
86
+ if options[:labels]
87
+ options[:labels].each do |key, value|
88
+ payload["labels[#{key}]"] = value.to_s
89
+ end
90
+ end
91
+
92
+ # Add sample files if provided
93
+ if samples && !samples.empty?
94
+ samples.each_with_index do |sample, index|
95
+ payload["files"] = @client.file_part(sample, "audio/mpeg")
96
+ end
97
+ end
98
+
99
+ @client.post_multipart(endpoint, payload)
100
+ end
101
+
102
+ # DELETE /v1/voices/{voice_id}
103
+ # Deletes a voice from your account
104
+ # Documentation: https://elevenlabs.io/docs/api-reference/voices/delete-voice
105
+ #
106
+ # @param voice_id [String] The ID of the voice to delete
107
+ # @return [Hash] Response confirming deletion
108
+ def delete(voice_id)
109
+ endpoint = "/v1/voices/#{voice_id}"
110
+ @client.delete(endpoint)
111
+ end
112
+
113
+ # Check if a voice is banned (safety control)
114
+ # @param voice_id [String] The ID of the voice to check
115
+ # @return [Boolean] True if the voice is banned
116
+ def banned?(voice_id)
117
+ voice = get(voice_id)
118
+ voice["safety_control"] == "BAN"
119
+ rescue ElevenlabsClient::ValidationError, ElevenlabsClient::APIError, ElevenlabsClient::NotFoundError
120
+ # If we can't get the voice, assume it's not banned
121
+ false
122
+ end
123
+
124
+ # Check if a voice is active (exists in the voice list)
125
+ # @param voice_id [String] The ID of the voice to check
126
+ # @return [Boolean] True if the voice is active
127
+ def active?(voice_id)
128
+ voices = list
129
+ active_voice_ids = voices["voices"].map { |voice| voice["voice_id"] }
130
+ active_voice_ids.include?(voice_id)
131
+ rescue ElevenlabsClient::ValidationError, ElevenlabsClient::APIError, ElevenlabsClient::NotFoundError
132
+ # If we can't get the voice list, assume it's not active
133
+ false
134
+ end
135
+
136
+ # Alias methods for backward compatibility and convenience
137
+ alias_method :get_voice, :get
138
+ alias_method :list_voices, :list
139
+ alias_method :create_voice, :create
140
+ alias_method :edit_voice, :edit
141
+ alias_method :delete_voice, :delete
142
+
143
+ private
144
+
145
+ attr_reader :client
146
+ end
147
+ end
@@ -6,4 +6,7 @@ module ElevenlabsClient
6
6
  class AuthenticationError < Error; end
7
7
  class RateLimitError < Error; end
8
8
  class ValidationError < Error; end
9
+ class NotFoundError < Error; end
10
+ class BadRequestError < Error; end
11
+ class UnprocessableEntityError < Error; end
9
12
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ElevenlabsClient
4
- VERSION = "0.1.0"
4
+ VERSION = "0.3.0"
5
5
  end
@@ -3,7 +3,15 @@
3
3
  require_relative "elevenlabs_client/version"
4
4
  require_relative "elevenlabs_client/errors"
5
5
  require_relative "elevenlabs_client/settings"
6
- require_relative "elevenlabs_client/dubs"
6
+ require_relative "elevenlabs_client/endpoints/dubs"
7
+ require_relative "elevenlabs_client/endpoints/text_to_speech"
8
+ require_relative "elevenlabs_client/endpoints/text_to_speech_stream"
9
+ require_relative "elevenlabs_client/endpoints/text_to_dialogue"
10
+ require_relative "elevenlabs_client/endpoints/sound_generation"
11
+ require_relative "elevenlabs_client/endpoints/text_to_voice"
12
+ require_relative "elevenlabs_client/endpoints/models"
13
+ require_relative "elevenlabs_client/endpoints/voices"
14
+ require_relative "elevenlabs_client/endpoints/music"
7
15
  require_relative "elevenlabs_client/client"
8
16
 
9
17
  module ElevenlabsClient
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: elevenlabs_client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vitor Oliveira
@@ -121,7 +121,15 @@ files:
121
121
  - README.md
122
122
  - lib/elevenlabs_client.rb
123
123
  - lib/elevenlabs_client/client.rb
124
- - lib/elevenlabs_client/dubs.rb
124
+ - lib/elevenlabs_client/endpoints/dubs.rb
125
+ - lib/elevenlabs_client/endpoints/models.rb
126
+ - lib/elevenlabs_client/endpoints/music.rb
127
+ - lib/elevenlabs_client/endpoints/sound_generation.rb
128
+ - lib/elevenlabs_client/endpoints/text_to_dialogue.rb
129
+ - lib/elevenlabs_client/endpoints/text_to_speech.rb
130
+ - lib/elevenlabs_client/endpoints/text_to_speech_stream.rb
131
+ - lib/elevenlabs_client/endpoints/text_to_voice.rb
132
+ - lib/elevenlabs_client/endpoints/voices.rb
125
133
  - lib/elevenlabs_client/errors.rb
126
134
  - lib/elevenlabs_client/settings.rb
127
135
  - lib/elevenlabs_client/version.rb