eleven_rb 0.1.0 → 0.2.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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +12 -0
- data/README.md +34 -1
- data/lib/eleven_rb/client.rb +23 -1
- data/lib/eleven_rb/configuration.rb +7 -0
- data/lib/eleven_rb/errors.rb +5 -0
- data/lib/eleven_rb/http/client.rb +1 -0
- data/lib/eleven_rb/resources/sound_effects.rb +65 -0
- data/lib/eleven_rb/version.rb +1 -1
- data/lib/eleven_rb.rb +1 -0
- metadata +4 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 80d8ceea950da279e7f35661aa4597eef9f6ff51fb67e38e607f634eaaa54feb
|
|
4
|
+
data.tar.gz: 8afa2939e1c267ee50c74ae2c6fe4fe8ea4f9fe0618ebb3d3cb52bc09f0c2683
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 0cb196287b9bad7eafa9e34ac6b3c30933f9d9e316d42728fd9a609cb83db95e0b63d307568a8000bfcaf1613d059026c63ff83e75cd70e9c2f686874be72d0a
|
|
7
|
+
data.tar.gz: 22e29e9eab3a7e04a3ca040bf4cd564b70dd0077a777acbf095dc17eb5f64f3958578c457eb9f487c95a3194b7b62a9b97cf590bc8744c50f392c14af3532027
|
data/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,18 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [0.2.0] - 2026-02-07
|
|
11
|
+
|
|
12
|
+
### Added
|
|
13
|
+
|
|
14
|
+
- Sound effects generation via `client.sound_effects.generate` (`POST /v1/sound-generation`)
|
|
15
|
+
- `ElevenRb::Error` top-level alias for `ElevenRb::Errors::Base`
|
|
16
|
+
- `Client#configured?` and `Configuration#configured?` predicate methods
|
|
17
|
+
|
|
18
|
+
### Changed
|
|
19
|
+
|
|
20
|
+
- API key validation deferred to first API call (lazy configuration) — `Client.new` no longer raises without a key
|
|
21
|
+
|
|
10
22
|
## [0.1.0] - 2026-01-21
|
|
11
23
|
|
|
12
24
|
### Added
|
data/README.md
CHANGED
|
@@ -4,11 +4,12 @@
|
|
|
4
4
|
[](https://github.com/webventures/eleven_rb/actions/workflows/ci.yml)
|
|
5
5
|
[](https://opensource.org/licenses/MIT)
|
|
6
6
|
|
|
7
|
-
A Ruby client for the [ElevenLabs](https://try.elevenlabs.io/qyk2j8gumrjz) Text-to-Speech API.
|
|
7
|
+
A Ruby client for the [ElevenLabs](https://try.elevenlabs.io/qyk2j8gumrjz) Text-to-Speech and Sound Effects API.
|
|
8
8
|
|
|
9
9
|
## Features
|
|
10
10
|
|
|
11
11
|
- Text-to-Speech generation and streaming
|
|
12
|
+
- Sound effects generation from text descriptions
|
|
12
13
|
- Voice management (list, get, create, update, delete)
|
|
13
14
|
- Voice Library access (search 10,000+ community voices)
|
|
14
15
|
- Voice Slot Manager for automatic slot management within account limits
|
|
@@ -86,6 +87,28 @@ File.open("output.mp3", "wb") do |file|
|
|
|
86
87
|
end
|
|
87
88
|
```
|
|
88
89
|
|
|
90
|
+
### Sound Effects
|
|
91
|
+
|
|
92
|
+
```ruby
|
|
93
|
+
# Generate a sound effect from a text description
|
|
94
|
+
audio = client.sound_effects.generate("thunder rumbling in the distance")
|
|
95
|
+
audio.save_to_file("thunder.mp3")
|
|
96
|
+
|
|
97
|
+
# With options
|
|
98
|
+
audio = client.sound_effects.generate(
|
|
99
|
+
"footsteps on gravel",
|
|
100
|
+
duration_seconds: 3.0,
|
|
101
|
+
prompt_influence: 0.5,
|
|
102
|
+
output_format: "mp3_44100_192"
|
|
103
|
+
)
|
|
104
|
+
|
|
105
|
+
# Generate a loopable sound effect
|
|
106
|
+
audio = client.sound_effects.generate("gentle rain", loop: true)
|
|
107
|
+
|
|
108
|
+
# Convenience method
|
|
109
|
+
audio = client.generate_sound_effect("explosion")
|
|
110
|
+
```
|
|
111
|
+
|
|
89
112
|
### Voice Management
|
|
90
113
|
|
|
91
114
|
```ruby
|
|
@@ -248,10 +271,20 @@ rescue ElevenRb::Errors::ValidationError => e
|
|
|
248
271
|
rescue ElevenRb::Errors::APIError => e
|
|
249
272
|
puts "API error: #{e.message} (status: #{e.http_status})"
|
|
250
273
|
end
|
|
274
|
+
|
|
275
|
+
# Or use the top-level alias to catch all ElevenRb errors
|
|
276
|
+
begin
|
|
277
|
+
audio = client.tts.generate("Hello", voice_id: "abc123")
|
|
278
|
+
rescue ElevenRb::Error => e
|
|
279
|
+
puts "Something went wrong: #{e.message}"
|
|
280
|
+
end
|
|
251
281
|
```
|
|
252
282
|
|
|
253
283
|
## Rails Integration
|
|
254
284
|
|
|
285
|
+
The client can be initialized without an API key and won't raise until the first API call,
|
|
286
|
+
making it safe to use in test/CI environments where the key may not be set.
|
|
287
|
+
|
|
255
288
|
```ruby
|
|
256
289
|
# config/initializers/eleven_rb.rb
|
|
257
290
|
ElevenRb.configure do |config|
|
data/lib/eleven_rb/client.rb
CHANGED
|
@@ -34,10 +34,16 @@ module ElevenRb
|
|
|
34
34
|
api_key: api_key || ENV.fetch('ELEVENLABS_API_KEY', nil),
|
|
35
35
|
**options
|
|
36
36
|
)
|
|
37
|
-
@config.validate!
|
|
38
37
|
@http_client = HTTP::Client.new(@config)
|
|
39
38
|
end
|
|
40
39
|
|
|
40
|
+
# Check if the client is configured with an API key
|
|
41
|
+
#
|
|
42
|
+
# @return [Boolean]
|
|
43
|
+
def configured?
|
|
44
|
+
config.configured?
|
|
45
|
+
end
|
|
46
|
+
|
|
41
47
|
# Voice management resource
|
|
42
48
|
#
|
|
43
49
|
# @return [Resources::Voices]
|
|
@@ -73,6 +79,13 @@ module ElevenRb
|
|
|
73
79
|
@user ||= Resources::User.new(http_client)
|
|
74
80
|
end
|
|
75
81
|
|
|
82
|
+
# Sound effects resource
|
|
83
|
+
#
|
|
84
|
+
# @return [Resources::SoundEffects]
|
|
85
|
+
def sound_effects
|
|
86
|
+
@sound_effects ||= Resources::SoundEffects.new(http_client)
|
|
87
|
+
end
|
|
88
|
+
|
|
76
89
|
# Voice slot manager
|
|
77
90
|
#
|
|
78
91
|
# @return [VoiceSlotManager]
|
|
@@ -90,6 +103,15 @@ module ElevenRb
|
|
|
90
103
|
tts.generate(text, voice_id: voice_id, **options)
|
|
91
104
|
end
|
|
92
105
|
|
|
106
|
+
# Convenience method: generate sound effect
|
|
107
|
+
#
|
|
108
|
+
# @param text [String] description of the sound effect
|
|
109
|
+
# @param options [Hash] additional options
|
|
110
|
+
# @return [Objects::Audio]
|
|
111
|
+
def generate_sound_effect(text, **options)
|
|
112
|
+
sound_effects.generate(text, **options)
|
|
113
|
+
end
|
|
114
|
+
|
|
93
115
|
# Convenience method: stream speech
|
|
94
116
|
#
|
|
95
117
|
# @param text [String] the text to convert
|
|
@@ -57,6 +57,13 @@ module ElevenRb
|
|
|
57
57
|
end
|
|
58
58
|
end
|
|
59
59
|
|
|
60
|
+
# Check if the configuration has an API key
|
|
61
|
+
#
|
|
62
|
+
# @return [Boolean]
|
|
63
|
+
def configured?
|
|
64
|
+
!api_key.nil? && !api_key.to_s.empty?
|
|
65
|
+
end
|
|
66
|
+
|
|
60
67
|
# Validate the configuration
|
|
61
68
|
#
|
|
62
69
|
# @raise [Errors::ConfigurationError] if configuration is invalid
|
data/lib/eleven_rb/errors.rb
CHANGED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module ElevenRb
|
|
4
|
+
module Resources
|
|
5
|
+
# Sound effects generation resource
|
|
6
|
+
#
|
|
7
|
+
# @example Generate a sound effect
|
|
8
|
+
# audio = client.sound_effects.generate("thunder rumbling in the distance")
|
|
9
|
+
# audio.save_to_file("thunder.mp3")
|
|
10
|
+
#
|
|
11
|
+
# @example With options
|
|
12
|
+
# audio = client.sound_effects.generate(
|
|
13
|
+
# "footsteps on gravel",
|
|
14
|
+
# duration_seconds: 3.0,
|
|
15
|
+
# prompt_influence: 0.5
|
|
16
|
+
# )
|
|
17
|
+
class SoundEffects < Base
|
|
18
|
+
DEFAULT_MODEL = 'eleven_text_to_sound_v2'
|
|
19
|
+
|
|
20
|
+
# Generate a sound effect from a text description
|
|
21
|
+
#
|
|
22
|
+
# @param text [String] description of the sound effect to generate
|
|
23
|
+
# @param model_id [String] the model to use (default: eleven_text_to_sound_v2)
|
|
24
|
+
# @param duration_seconds [Float, nil] desired duration in seconds (optional, API decides if omitted)
|
|
25
|
+
# @param prompt_influence [Float, nil] how closely to follow the prompt (0.0-1.0)
|
|
26
|
+
# @param loop [Boolean, nil] whether to generate a loopable sound effect
|
|
27
|
+
# @param output_format [String] audio output format
|
|
28
|
+
# @return [Objects::Audio]
|
|
29
|
+
def generate(text, model_id: DEFAULT_MODEL, duration_seconds: nil, prompt_influence: nil, loop: nil,
|
|
30
|
+
output_format: 'mp3_44100_128')
|
|
31
|
+
validate_presence!(text, 'text')
|
|
32
|
+
|
|
33
|
+
body = {
|
|
34
|
+
text: text,
|
|
35
|
+
model_id: model_id
|
|
36
|
+
}
|
|
37
|
+
body[:duration_seconds] = duration_seconds unless duration_seconds.nil?
|
|
38
|
+
body[:prompt_influence] = prompt_influence unless prompt_influence.nil?
|
|
39
|
+
body[:loop] = loop unless loop.nil?
|
|
40
|
+
|
|
41
|
+
path = "/sound-generation?output_format=#{output_format}"
|
|
42
|
+
response = post_binary(path, body)
|
|
43
|
+
|
|
44
|
+
audio = Objects::Audio.new(
|
|
45
|
+
data: response,
|
|
46
|
+
format: output_format,
|
|
47
|
+
voice_id: nil,
|
|
48
|
+
text: text,
|
|
49
|
+
model_id: model_id
|
|
50
|
+
)
|
|
51
|
+
|
|
52
|
+
cost_info = Objects::CostInfo.new(text: text, voice_id: 'sound_effect', model_id: model_id)
|
|
53
|
+
http_client.config.trigger(
|
|
54
|
+
:on_audio_generated,
|
|
55
|
+
audio: audio,
|
|
56
|
+
voice_id: nil,
|
|
57
|
+
text: text,
|
|
58
|
+
cost_info: cost_info.to_h
|
|
59
|
+
)
|
|
60
|
+
|
|
61
|
+
audio
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
end
|
data/lib/eleven_rb/version.rb
CHANGED
data/lib/eleven_rb.rb
CHANGED
|
@@ -106,6 +106,7 @@ require_relative 'eleven_rb/resources/text_to_speech'
|
|
|
106
106
|
require_relative 'eleven_rb/resources/voice_library'
|
|
107
107
|
require_relative 'eleven_rb/resources/models'
|
|
108
108
|
require_relative 'eleven_rb/resources/user'
|
|
109
|
+
require_relative 'eleven_rb/resources/sound_effects'
|
|
109
110
|
|
|
110
111
|
# High-level components
|
|
111
112
|
require_relative 'eleven_rb/voice_slot_manager'
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: eleven_rb
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.2.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Web Ventures Ltd
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2026-
|
|
11
|
+
date: 2026-02-07 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: base64
|
|
@@ -156,6 +156,7 @@ files:
|
|
|
156
156
|
- lib/eleven_rb/objects/voice_settings.rb
|
|
157
157
|
- lib/eleven_rb/resources/base.rb
|
|
158
158
|
- lib/eleven_rb/resources/models.rb
|
|
159
|
+
- lib/eleven_rb/resources/sound_effects.rb
|
|
159
160
|
- lib/eleven_rb/resources/text_to_speech.rb
|
|
160
161
|
- lib/eleven_rb/resources/user.rb
|
|
161
162
|
- lib/eleven_rb/resources/voice_library.rb
|
|
@@ -186,7 +187,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
186
187
|
- !ruby/object:Gem::Version
|
|
187
188
|
version: '0'
|
|
188
189
|
requirements: []
|
|
189
|
-
rubygems_version: 3.5.
|
|
190
|
+
rubygems_version: 3.5.3
|
|
190
191
|
signing_key:
|
|
191
192
|
specification_version: 4
|
|
192
193
|
summary: Ruby client for the ElevenLabs Text-to-Speech API
|