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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +228 -10
- data/README.md +219 -90
- data/lib/elevenlabs_client/client.rb +126 -6
- data/lib/elevenlabs_client/endpoints/models.rb +26 -0
- data/lib/elevenlabs_client/endpoints/music.rb +127 -0
- data/lib/elevenlabs_client/endpoints/sound_generation.rb +46 -0
- data/lib/elevenlabs_client/endpoints/text_to_dialogue.rb +40 -0
- data/lib/elevenlabs_client/endpoints/text_to_speech.rb +50 -0
- data/lib/elevenlabs_client/endpoints/text_to_speech_stream.rb +42 -0
- data/lib/elevenlabs_client/endpoints/text_to_voice.rb +95 -0
- data/lib/elevenlabs_client/endpoints/voices.rb +147 -0
- data/lib/elevenlabs_client/errors.rb +3 -0
- data/lib/elevenlabs_client/version.rb +1 -1
- data/lib/elevenlabs_client.rb +9 -1
- metadata +10 -2
- /data/lib/elevenlabs_client/{dubs.rb โ endpoints/dubs.rb} +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d6c150778cecf2c843fc1b5492d1cfbaed14306f010b240557945c631b083fa1
|
4
|
+
data.tar.gz: 62ba8f400b1be939bfc5839b47a5e636a5e888d812b8eabc04c1ca26196c9c63
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9df813daf9c443428e92cd323b94f05fa0791ab046b34f5c0ddd12bc19654235888c98bc47299355e2b9c6bf5d5a417d0b639f59b6d0af16b86f5e3f700202ad
|
7
|
+
data.tar.gz: 50b4a3229dbd3f2e25c5614d5178d4b688c812d9a01181748879a8490a66df457e4fb24b3b6110d0e72e1def3e877072045e84fecb18b175128b1b18fb96e2ad
|
data/CHANGELOG.md
CHANGED
@@ -5,7 +5,233 @@ All notable changes to this project will be documented in this file.
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
6
6
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
7
7
|
|
8
|
-
## [
|
8
|
+
## [0.3.0] - 2025-09-12
|
9
|
+
|
10
|
+
### Added
|
11
|
+
- **๐ต Music Generation API** - AI-powered music composition and streaming
|
12
|
+
- `client.music.compose(options)` - Generate music from text prompts
|
13
|
+
- `client.music.compose_stream(options, &block)` - Real-time music streaming
|
14
|
+
- `client.music.compose_detailed(options)` - Generate music with metadata
|
15
|
+
- `client.music.create_plan(options)` - Create structured composition plans
|
16
|
+
- **๐ญ Voice Management API** - Complete CRUD operations for individual voices
|
17
|
+
- `client.voices.get(voice_id)` - Get detailed voice information
|
18
|
+
- `client.voices.list()` - List all voices in account
|
19
|
+
- `client.voices.create(name, samples, **options)` - Create custom voices from audio samples
|
20
|
+
- `client.voices.edit(voice_id, samples, **options)` - Edit existing voices
|
21
|
+
- `client.voices.delete(voice_id)` - Delete voices from account
|
22
|
+
- `client.voices.banned?(voice_id)` - Check voice safety status
|
23
|
+
- `client.voices.active?(voice_id)` - Check voice availability
|
24
|
+
- **๐ Enhanced Rakefile** - Comprehensive gem management and development tasks
|
25
|
+
- Build, install, push, and clean gem operations
|
26
|
+
- Development tools (linting, testing, security audit)
|
27
|
+
- Documentation generation and serving
|
28
|
+
- Release preparation and management
|
29
|
+
- Maintenance and cleanup tasks
|
30
|
+
|
31
|
+
### Enhanced
|
32
|
+
- **๐จ Consolidated Error Handling** - Unified error handling across all endpoints
|
33
|
+
- Merged `handle_response`, `handle_binary_response`, and `handle_streaming_response` into single method
|
34
|
+
- Enhanced error message extraction from JSON, nested objects, arrays, and plain text
|
35
|
+
- More specific error types: `BadRequestError`, `NotFoundError`, `UnprocessableEntityError`
|
36
|
+
- Better error messages extracted from actual API responses instead of generic fallbacks
|
37
|
+
- **๐ง HTTP Client Improvements** - Added missing HTTP methods and consolidated functionality
|
38
|
+
- Added `delete` method for DELETE requests
|
39
|
+
- Enhanced `post_with_custom_headers` for flexible header management
|
40
|
+
- Consistent error handling across all HTTP methods (GET, POST, DELETE, multipart, binary, streaming)
|
41
|
+
- **๐ Documentation Organization** - Comprehensive documentation for all new features
|
42
|
+
- [MUSIC.md](docs/MUSIC.md) - Complete music generation guide (570 lines)
|
43
|
+
- [VOICES.md](docs/VOICES.md) - Voice management documentation (519 lines)
|
44
|
+
- Enhanced README with music capabilities and updated feature list
|
45
|
+
- Professional Rails integration examples
|
46
|
+
|
47
|
+
### New Error Classes
|
48
|
+
- `ElevenlabsClient::BadRequestError` (400) - Invalid parameters or malformed requests
|
49
|
+
- `ElevenlabsClient::NotFoundError` (404) - Resource not found
|
50
|
+
- `ElevenlabsClient::UnprocessableEntityError` (422) - Valid request but invalid data
|
51
|
+
|
52
|
+
### Music Generation Features
|
53
|
+
- **๐ผ Composition Styles** - Support for all major music genres
|
54
|
+
- Electronic: EDM, House, Techno, Ambient, Synthwave
|
55
|
+
- Orchestral: Classical, Film Score, Epic Orchestral
|
56
|
+
- Popular: Pop, Rock, Hip-Hop, Country, Folk
|
57
|
+
- Jazz & Blues: Traditional Jazz, Smooth Jazz, Blues
|
58
|
+
- World Music: Celtic, Medieval, New Age, Ethnic
|
59
|
+
- **๐๏ธ Advanced Controls** - Detailed composition parameters
|
60
|
+
- Custom composition plans with sections, tempo, key, instruments
|
61
|
+
- Multiple output formats (MP3, WAV) with quality settings
|
62
|
+
- Music length control (5 seconds to 5 minutes)
|
63
|
+
- Model selection for different generation approaches
|
64
|
+
- **๐ก Streaming Support** - Real-time music generation and playback
|
65
|
+
- Chunk-based streaming for immediate playback
|
66
|
+
- Memory-efficient processing for long compositions
|
67
|
+
- WebSocket integration for live applications
|
68
|
+
|
69
|
+
### Voice Management Features
|
70
|
+
- **๐ค Voice Creation** - Create custom voices from audio samples
|
71
|
+
- Multiple sample upload support for better quality
|
72
|
+
- Voice metadata and labeling system
|
73
|
+
- Quality validation and optimization
|
74
|
+
- **๐ง Voice Editing** - Modify existing voices
|
75
|
+
- Add new samples to improve voice quality
|
76
|
+
- Update voice metadata and descriptions
|
77
|
+
- Batch voice operations
|
78
|
+
- **๐ Voice Discovery** - Advanced voice management
|
79
|
+
- Search and filter voices by category, labels, quality
|
80
|
+
- Voice status checking (active, banned, available)
|
81
|
+
- Voice analytics and usage tracking
|
82
|
+
|
83
|
+
### Rails Integration Examples
|
84
|
+
- **[MusicController](examples/music_controller.rb)** - Complete music generation implementation
|
85
|
+
- Basic and advanced music generation endpoints
|
86
|
+
- Streaming music with real-time playback
|
87
|
+
- Composition planning and structured music creation
|
88
|
+
- Batch generation and music library management
|
89
|
+
- Interactive music generation with user preferences
|
90
|
+
- **[VoicesController](examples/voices_controller.rb)** - Voice management implementation
|
91
|
+
- Full CRUD operations for voice management
|
92
|
+
- File upload handling for voice samples
|
93
|
+
- Voice search and filtering capabilities
|
94
|
+
- Batch voice operations and management workflows
|
95
|
+
|
96
|
+
### Technical Improvements
|
97
|
+
- **๐งช Comprehensive Testing** - Expanded test coverage
|
98
|
+
- **57 new music tests** (24 unit + 33 integration)
|
99
|
+
- **Enhanced error handling tests** across all endpoints
|
100
|
+
- **Total test coverage**: 300+ tests with consistent passing
|
101
|
+
- **๐๏ธ Architecture Consolidation** - Cleaner codebase
|
102
|
+
- Removed duplicate error handling methods
|
103
|
+
- Consolidated HTTP response processing
|
104
|
+
- Enhanced error message extraction with fallback handling
|
105
|
+
- Improved code organization and maintainability
|
106
|
+
- **๐ฆ Release Management** - Professional release workflow
|
107
|
+
- Automated release preparation tasks
|
108
|
+
- Version management and changelog automation
|
109
|
+
- Security auditing and dependency management
|
110
|
+
- Documentation generation and validation
|
111
|
+
|
112
|
+
### Breaking Changes
|
113
|
+
- **Error Handling** - More specific error types may require catch block updates
|
114
|
+
```ruby
|
115
|
+
# Before (v0.2.0)
|
116
|
+
rescue ElevenlabsClient::ValidationError => e
|
117
|
+
# Handle all 4xx errors
|
118
|
+
end
|
119
|
+
|
120
|
+
# After (v0.3.0) - More specific handling
|
121
|
+
rescue ElevenlabsClient::BadRequestError => e
|
122
|
+
# Handle 400 Bad Request
|
123
|
+
rescue ElevenlabsClient::NotFoundError => e
|
124
|
+
# Handle 404 Not Found
|
125
|
+
rescue ElevenlabsClient::UnprocessableEntityError => e
|
126
|
+
# Handle 422 Unprocessable Entity
|
127
|
+
rescue ElevenlabsClient::ValidationError => e
|
128
|
+
# Handle other 4xx errors
|
129
|
+
end
|
130
|
+
```
|
131
|
+
|
132
|
+
### Migration Guide
|
133
|
+
```ruby
|
134
|
+
# New Music API Usage
|
135
|
+
client = ElevenlabsClient.new
|
136
|
+
|
137
|
+
# Generate music
|
138
|
+
music_data = client.music.compose(
|
139
|
+
prompt: "Upbeat electronic dance track",
|
140
|
+
music_length_ms: 30000
|
141
|
+
)
|
142
|
+
|
143
|
+
# Stream music generation
|
144
|
+
client.music.compose_stream(prompt: "Relaxing ambient") do |chunk|
|
145
|
+
# Process audio chunk in real-time
|
146
|
+
end
|
147
|
+
|
148
|
+
# Voice management
|
149
|
+
voices = client.voices.list
|
150
|
+
voice = client.voices.get("voice_id")
|
151
|
+
|
152
|
+
# Create custom voice
|
153
|
+
File.open("sample.mp3", "rb") do |sample|
|
154
|
+
voice = client.voices.create("My Voice", [sample])
|
155
|
+
end
|
156
|
+
```
|
157
|
+
|
158
|
+
## [0.2.0] - 2025-09-12
|
159
|
+
|
160
|
+
### Added
|
161
|
+
- **Text-to-Speech API** - Convert text to natural-sounding speech with voice customization
|
162
|
+
- **Text-to-Speech Streaming API** - Real-time audio streaming for live applications
|
163
|
+
- **Text-to-Dialogue API** - Multi-speaker conversation generation
|
164
|
+
- **Sound Generation API** - AI-generated sound effects and ambient audio
|
165
|
+
- **Comprehensive Documentation** - Separate documentation files for each API endpoint
|
166
|
+
- **Rails Integration Examples** - Complete controller examples for all endpoints
|
167
|
+
- **Enhanced Configuration** - Flexible configuration with Settings module
|
168
|
+
- **Streaming Support** - Real-time audio chunk processing with block callbacks
|
169
|
+
- **Binary Response Handling** - Proper handling of audio data responses
|
170
|
+
- **Query Parameter Support** - URL query parameters for API requests
|
171
|
+
|
172
|
+
### Enhanced
|
173
|
+
- **Endpoint Organization** - Moved all endpoints to dedicated `lib/elevenlabs_client/endpoints/` directory
|
174
|
+
- **Client Architecture** - Separated HTTP client logic from endpoint-specific functionality
|
175
|
+
- **Error Handling** - Enhanced error handling with streaming-specific exceptions
|
176
|
+
- **Test Coverage** - Expanded test suite to 187+ tests covering all new functionality
|
177
|
+
- **Configuration System** - Priority-based configuration (explicit > Settings > ENV)
|
178
|
+
|
179
|
+
### Documentation
|
180
|
+
- **Modular Documentation** - Split endpoint documentation into separate files:
|
181
|
+
- [DUBBING.md](docs/DUBBING.md) - Audio/video dubbing functionality
|
182
|
+
- [TEXT_TO_SPEECH.md](docs/TEXT_TO_SPEECH.md) - Text-to-speech conversion
|
183
|
+
- [TEXT_TO_SPEECH_STREAMING.md](docs/TEXT_TO_SPEECH_STREAMING.md) - Real-time streaming
|
184
|
+
- [TEXT_TO_DIALOGUE.md](docs/TEXT_TO_DIALOGUE.md) - Multi-speaker dialogues
|
185
|
+
- [SOUND_GENERATION.md](docs/SOUND_GENERATION.md) - Sound effect generation
|
186
|
+
- **Improved README** - Streamlined main README with quick start guide
|
187
|
+
- **Rails Examples** - Complete controller implementations for all endpoints
|
188
|
+
- **Usage Examples** - Comprehensive examples for each API feature
|
189
|
+
|
190
|
+
### New Endpoints
|
191
|
+
- `client.text_to_speech.*` - Text-to-speech conversion with voice settings
|
192
|
+
- `client.text_to_speech_stream.*` - Real-time streaming text-to-speech
|
193
|
+
- `client.text_to_dialogue.*` - Multi-speaker dialogue generation
|
194
|
+
- `client.sound_generation.*` - AI sound effect and ambient audio generation
|
195
|
+
|
196
|
+
### New Features
|
197
|
+
- **Voice Customization** - Stability, similarity boost, style controls
|
198
|
+
- **Audio Formats** - Multiple output formats (MP3, PCM) with quality options
|
199
|
+
- **Looping Audio** - Generate seamless looping sound effects
|
200
|
+
- **Deterministic Generation** - Seed support for consistent results
|
201
|
+
- **Batch Processing** - Multiple sound generation in single requests
|
202
|
+
- **WebSocket Integration** - Real-time streaming to WebSocket connections
|
203
|
+
- **File Format Support** - Enhanced support for various audio/video formats
|
204
|
+
|
205
|
+
### Technical Improvements
|
206
|
+
- **Modular Architecture** - Clean separation of concerns with endpoint classes
|
207
|
+
- **HTTP Client Enhancement** - Added streaming, binary, and custom header support
|
208
|
+
- **Settings Management** - Centralized configuration with Rails initializer support
|
209
|
+
- **Memory Management** - Efficient handling of large audio files and streams
|
210
|
+
- **Concurrent Testing** - Parallel test execution for faster development
|
211
|
+
|
212
|
+
### Examples Added
|
213
|
+
- `examples/dubs_controller.rb` - Complete dubbing workflow with batch processing
|
214
|
+
- `examples/text_to_speech_controller.rb` - TTS with voice customization
|
215
|
+
- `examples/streaming_audio_controller.rb` - Real-time streaming with WebSocket support
|
216
|
+
- `examples/text_to_dialogue_controller.rb` - Specialized dialogue endpoints
|
217
|
+
- `examples/sound_generation_controller.rb` - Sound effects with presets and batch processing
|
218
|
+
- `examples/rails_initializer.rb` - Rails configuration example
|
219
|
+
|
220
|
+
### Breaking Changes
|
221
|
+
- **Endpoint Access** - Dubbing methods moved from `client.create_dub` to `client.dubs.create`
|
222
|
+
- **File Structure** - Endpoint classes moved to `lib/elevenlabs_client/endpoints/`
|
223
|
+
- **Configuration** - Enhanced configuration system with new precedence rules
|
224
|
+
|
225
|
+
### Migration Guide
|
226
|
+
```ruby
|
227
|
+
# Before (v0.1.0)
|
228
|
+
client.create_dub(file_io: file, filename: "video.mp4", target_languages: ["es"])
|
229
|
+
|
230
|
+
# After (v0.2.0)
|
231
|
+
client.dubs.create(file_io: file, filename: "video.mp4", target_languages: ["es"])
|
232
|
+
```
|
233
|
+
|
234
|
+
## [0.1.0] - 2025-09-12
|
9
235
|
|
10
236
|
### Added
|
11
237
|
- Initial release of ElevenLabs Client gem
|
@@ -26,12 +252,4 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
26
252
|
- **File Support**: Multiple video and audio formats (MP4, MOV, MP3, WAV, etc.)
|
27
253
|
- **Language Support**: Multiple target languages for dubbing
|
28
254
|
- **Configuration**: Flexible API key and endpoint configuration
|
29
|
-
- **Testing**: Comprehensive test suite with integration tests
|
30
|
-
|
31
|
-
## [0.1.0] - 2025-01-XX
|
32
|
-
|
33
|
-
### Added
|
34
|
-
- Initial implementation of ElevenLabs Client
|
35
|
-
- Basic dubbing functionality
|
36
|
-
- Error handling and validation
|
37
|
-
- Documentation and examples
|
255
|
+
- **Testing**: Comprehensive test suite with integration tests
|
data/README.md
CHANGED
@@ -1,24 +1,48 @@
|
|
1
1
|
# ElevenlabsClient
|
2
2
|
|
3
|
-
|
3
|
+
[](https://badge.fury.io/rb/elevenlabs_client)
|
4
|
+
|
5
|
+
A comprehensive Ruby client library for the ElevenLabs API, supporting voice synthesis, dubbing, dialogue generation, sound effects, and AI music composition.
|
6
|
+
|
7
|
+
## Features
|
8
|
+
|
9
|
+
๐๏ธ **Text-to-Speech** - Convert text to natural-sounding speech
|
10
|
+
๐ฌ **Dubbing** - Create dubbed versions of audio/video content
|
11
|
+
๐ฌ **Dialogue Generation** - Multi-speaker conversations
|
12
|
+
๐ **Sound Generation** - AI-generated sound effects and ambient audio
|
13
|
+
๐ต **Music Generation** - AI-powered music composition and streaming
|
14
|
+
๐จ **Voice Design** - Create custom voices from text descriptions
|
15
|
+
๐ญ **Voice Management** - Create, edit, and manage individual voices
|
16
|
+
๐ค **Models** - List available models and their capabilities
|
17
|
+
๐ก **Streaming** - Real-time audio streaming
|
18
|
+
โ๏ธ **Configurable** - Flexible configuration options
|
19
|
+
๐งช **Well-tested** - Comprehensive test coverage
|
4
20
|
|
5
21
|
## Installation
|
6
22
|
|
7
23
|
Add this line to your application's Gemfile:
|
8
24
|
|
9
25
|
```ruby
|
10
|
-
gem 'elevenlabs_client'
|
26
|
+
gem 'elevenlabs_client'
|
11
27
|
```
|
12
28
|
|
13
29
|
And then execute:
|
14
30
|
|
15
|
-
|
31
|
+
```bash
|
32
|
+
$ bundle install
|
33
|
+
```
|
16
34
|
|
17
|
-
|
35
|
+
Or install it yourself as:
|
36
|
+
|
37
|
+
```bash
|
38
|
+
$ gem install elevenlabs_client
|
39
|
+
```
|
40
|
+
|
41
|
+
## Quick Start
|
18
42
|
|
19
43
|
### Configuration
|
20
44
|
|
21
|
-
#### Rails
|
45
|
+
#### Rails Applications (Recommended)
|
22
46
|
|
23
47
|
Create `config/initializers/elevenlabs_client.rb`:
|
24
48
|
|
@@ -26,149 +50,254 @@ Create `config/initializers/elevenlabs_client.rb`:
|
|
26
50
|
ElevenlabsClient::Settings.configure do |config|
|
27
51
|
config.properties = {
|
28
52
|
elevenlabs_base_uri: ENV["ELEVENLABS_BASE_URL"],
|
29
|
-
elevenlabs_api_key: ENV["ELEVENLABS_API_KEY"]
|
53
|
+
elevenlabs_api_key: ENV["ELEVENLABS_API_KEY"]
|
30
54
|
}
|
31
55
|
end
|
32
56
|
```
|
33
57
|
|
34
|
-
|
58
|
+
Set your environment variables:
|
35
59
|
|
36
|
-
```
|
37
|
-
|
38
|
-
#
|
60
|
+
```bash
|
61
|
+
export ELEVENLABS_API_KEY="your_api_key_here"
|
62
|
+
export ELEVENLABS_BASE_URL="https://api.elevenlabs.io" # Optional, defaults to official API
|
39
63
|
```
|
40
64
|
|
41
|
-
####
|
42
|
-
|
43
|
-
You can also use the module-level configure method:
|
65
|
+
#### Direct Configuration
|
44
66
|
|
45
67
|
```ruby
|
68
|
+
# Module-level configuration
|
46
69
|
ElevenlabsClient.configure do |config|
|
47
70
|
config.properties = {
|
48
71
|
elevenlabs_base_uri: "https://api.elevenlabs.io",
|
49
72
|
elevenlabs_api_key: "your_api_key_here"
|
50
73
|
}
|
51
74
|
end
|
52
|
-
```
|
53
|
-
|
54
|
-
#### Configuration Precedence
|
55
|
-
|
56
|
-
The client uses the following precedence order for configuration:
|
57
|
-
|
58
|
-
1. **Explicit parameters** passed to `Client.new` (highest priority)
|
59
|
-
2. **Settings.properties** configured via initializer
|
60
|
-
3. **Environment variables** (lowest priority)
|
61
|
-
|
62
|
-
This allows you to set defaults in your initializer while still being able to override them when needed.
|
63
|
-
|
64
|
-
### Client Initialization
|
65
|
-
|
66
|
-
There are several ways to create a client:
|
67
75
|
|
68
|
-
|
69
|
-
|
70
|
-
client = ElevenlabsClient.new
|
71
|
-
|
72
|
-
# Passing API key directly
|
73
|
-
client = ElevenlabsClient::Client.new(api_key: "your_api_key_here")
|
74
|
-
|
75
|
-
# Custom base URL
|
76
|
-
client = ElevenlabsClient::Client.new(
|
76
|
+
# Or pass directly to client
|
77
|
+
client = ElevenlabsClient.new(
|
77
78
|
api_key: "your_api_key_here",
|
78
|
-
base_url: "https://
|
79
|
-
)
|
80
|
-
|
81
|
-
# Custom environment variable names
|
82
|
-
client = ElevenlabsClient::Client.new(
|
83
|
-
api_key_env: "MY_CUSTOM_API_KEY_VAR",
|
84
|
-
base_url_env: "MY_CUSTOM_BASE_URL_VAR"
|
79
|
+
base_url: "https://api.elevenlabs.io"
|
85
80
|
)
|
86
81
|
```
|
87
82
|
|
88
83
|
### Basic Usage
|
89
84
|
|
90
85
|
```ruby
|
91
|
-
|
92
|
-
|
93
|
-
# Create a client
|
86
|
+
# Initialize client (uses configured settings)
|
94
87
|
client = ElevenlabsClient.new
|
95
88
|
|
96
|
-
#
|
89
|
+
# Text-to-Speech
|
90
|
+
audio_data = client.text_to_speech.convert("21m00Tcm4TlvDq8ikWAM", "Hello, world!")
|
91
|
+
File.open("hello.mp3", "wb") { |f| f.write(audio_data) }
|
92
|
+
|
93
|
+
# Dubbing
|
97
94
|
File.open("video.mp4", "rb") do |file|
|
98
95
|
result = client.dubs.create(
|
99
96
|
file_io: file,
|
100
97
|
filename: "video.mp4",
|
101
|
-
target_languages: ["es", "
|
102
|
-
name: "My Video Dub",
|
103
|
-
drop_background_audio: true,
|
104
|
-
use_profanity_filter: false
|
98
|
+
target_languages: ["es", "fr", "de"]
|
105
99
|
)
|
106
|
-
|
107
|
-
puts "Dubbing job created: #{result['dubbing_id']}"
|
108
100
|
end
|
109
101
|
|
110
|
-
#
|
111
|
-
|
112
|
-
|
102
|
+
# Dialogue Generation
|
103
|
+
dialogue = [
|
104
|
+
{ text: "Hello, how are you?", voice_id: "voice_1" },
|
105
|
+
{ text: "I'm doing great, thanks!", voice_id: "voice_2" }
|
106
|
+
]
|
107
|
+
audio_data = client.text_to_dialogue.convert(dialogue)
|
108
|
+
|
109
|
+
# Sound Generation
|
110
|
+
audio_data = client.sound_generation.generate("Ocean waves crashing on rocks")
|
113
111
|
|
114
|
-
#
|
115
|
-
|
116
|
-
|
112
|
+
# Voice Design
|
113
|
+
design_result = client.text_to_voice.design("Warm, professional female voice")
|
114
|
+
generated_voice_id = design_result["previews"].first["generated_voice_id"]
|
117
115
|
|
118
|
-
|
119
|
-
|
120
|
-
|
116
|
+
voice_result = client.text_to_voice.create(
|
117
|
+
"Professional Voice",
|
118
|
+
"Warm, professional female voice",
|
119
|
+
generated_voice_id
|
120
|
+
)
|
121
|
+
|
122
|
+
# List Available Models
|
123
|
+
models = client.models.list
|
124
|
+
fastest_model = models["models"].min_by { |m| m["token_cost_factor"] }
|
125
|
+
puts "Fastest model: #{fastest_model['name']}"
|
126
|
+
|
127
|
+
# Voice Management
|
128
|
+
voices = client.voices.list
|
129
|
+
puts "Total voices: #{voices['voices'].length}"
|
130
|
+
|
131
|
+
# Create custom voice from audio samples
|
132
|
+
File.open("sample1.mp3", "rb") do |sample|
|
133
|
+
voice = client.voices.create("My Voice", [sample], description: "Custom narrator voice")
|
134
|
+
puts "Created voice: #{voice['voice_id']}"
|
135
|
+
end
|
136
|
+
|
137
|
+
# Music Generation
|
138
|
+
music_data = client.music.compose(
|
139
|
+
prompt: "Upbeat electronic dance track with synthesizers",
|
140
|
+
music_length_ms: 30000
|
141
|
+
)
|
142
|
+
File.open("generated_music.mp3", "wb") { |f| f.write(music_data) }
|
143
|
+
|
144
|
+
# Streaming Text-to-Speech
|
145
|
+
client.text_to_speech_stream.stream("voice_id", "Streaming text") do |chunk|
|
146
|
+
# Process audio chunk in real-time
|
147
|
+
puts "Received #{chunk.bytesize} bytes"
|
148
|
+
end
|
121
149
|
```
|
122
150
|
|
123
|
-
|
151
|
+
## API Documentation
|
124
152
|
|
125
|
-
|
153
|
+
### Core APIs
|
126
154
|
|
127
|
-
-
|
128
|
-
-
|
129
|
-
-
|
130
|
-
-
|
155
|
+
- **[Dubbing API](docs/DUBBING.md)** - Create dubbed versions of audio/video content
|
156
|
+
- **[Text-to-Speech API](docs/TEXT_TO_SPEECH.md)** - Convert text to natural speech
|
157
|
+
- **[Text-to-Speech Streaming API](docs/TEXT_TO_SPEECH_STREAMING.md)** - Real-time audio streaming
|
158
|
+
- **[Text-to-Dialogue API](docs/TEXT_TO_DIALOGUE.md)** - Multi-speaker conversations
|
159
|
+
- **[Sound Generation API](docs/SOUND_GENERATION.md)** - AI-generated sound effects
|
160
|
+
- **[Music Generation API](docs/MUSIC.md)** - AI-powered music composition and streaming
|
161
|
+
- **[Text-to-Voice API](docs/TEXT_TO_VOICE.md)** - Design and create custom voices
|
162
|
+
- **[Voice Management API](docs/VOICES.md)** - Manage individual voices (CRUD operations)
|
163
|
+
- **[Models API](docs/MODELS.md)** - List available models and capabilities
|
131
164
|
|
132
|
-
|
165
|
+
### Available Endpoints
|
133
166
|
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
167
|
+
| Endpoint | Description | Documentation |
|
168
|
+
|----------|-------------|---------------|
|
169
|
+
| `client.dubs.*` | Audio/video dubbing | [DUBBING.md](docs/DUBBING.md) |
|
170
|
+
| `client.text_to_speech.*` | Text-to-speech conversion | [TEXT_TO_SPEECH.md](docs/TEXT_TO_SPEECH.md) |
|
171
|
+
| `client.text_to_speech_stream.*` | Streaming TTS | [TEXT_TO_SPEECH_STREAMING.md](docs/TEXT_TO_SPEECH_STREAMING.md) |
|
172
|
+
| `client.text_to_dialogue.*` | Dialogue generation | [TEXT_TO_DIALOGUE.md](docs/TEXT_TO_DIALOGUE.md) |
|
173
|
+
| `client.sound_generation.*` | Sound effect generation | [SOUND_GENERATION.md](docs/SOUND_GENERATION.md) |
|
174
|
+
| `client.music.*` | AI music composition and streaming | [MUSIC.md](docs/MUSIC.md) |
|
175
|
+
| `client.text_to_voice.*` | Voice design and creation | [TEXT_TO_VOICE.md](docs/TEXT_TO_VOICE.md) |
|
176
|
+
| `client.voices.*` | Voice management (CRUD) | [VOICES.md](docs/VOICES.md) |
|
177
|
+
| `client.models.*` | Model information and capabilities | [MODELS.md](docs/MODELS.md) |
|
178
|
+
|
179
|
+
## Configuration Options
|
180
|
+
|
181
|
+
### Configuration Precedence
|
182
|
+
|
183
|
+
1. **Explicit parameters** (highest priority)
|
184
|
+
2. **Settings.properties** (configured via initializer)
|
185
|
+
3. **Environment variables** (lowest priority)
|
186
|
+
|
187
|
+
### Environment Variables
|
188
|
+
|
189
|
+
- `ELEVENLABS_API_KEY` - Your ElevenLabs API key (required)
|
190
|
+
- `ELEVENLABS_BASE_URL` - API base URL (optional, defaults to `https://api.elevenlabs.io`)
|
191
|
+
|
192
|
+
### Custom Environment Variable Names
|
193
|
+
|
194
|
+
```ruby
|
195
|
+
client = ElevenlabsClient.new(
|
196
|
+
api_key_env: "CUSTOM_API_KEY_VAR",
|
197
|
+
base_url_env: "CUSTOM_BASE_URL_VAR"
|
198
|
+
)
|
199
|
+
```
|
145
200
|
|
146
201
|
## Error Handling
|
147
202
|
|
148
|
-
The client
|
203
|
+
The client provides specific exception types for different error conditions:
|
149
204
|
|
150
205
|
```ruby
|
151
206
|
begin
|
152
|
-
client.
|
153
|
-
rescue ElevenlabsClient::AuthenticationError
|
154
|
-
puts "Invalid API key
|
155
|
-
rescue ElevenlabsClient::RateLimitError
|
156
|
-
puts "Rate limit exceeded
|
207
|
+
result = client.text_to_speech.convert(voice_id, text)
|
208
|
+
rescue ElevenlabsClient::AuthenticationError
|
209
|
+
puts "Invalid API key"
|
210
|
+
rescue ElevenlabsClient::RateLimitError
|
211
|
+
puts "Rate limit exceeded"
|
157
212
|
rescue ElevenlabsClient::ValidationError => e
|
158
|
-
puts "
|
213
|
+
puts "Invalid parameters: #{e.message}"
|
159
214
|
rescue ElevenlabsClient::APIError => e
|
160
215
|
puts "API error: #{e.message}"
|
161
216
|
end
|
162
217
|
```
|
163
218
|
|
219
|
+
### Exception Types
|
220
|
+
|
221
|
+
- `AuthenticationError` - Invalid API key or authentication failure
|
222
|
+
- `RateLimitError` - Rate limit exceeded
|
223
|
+
- `ValidationError` - Invalid request parameters
|
224
|
+
- `APIError` - General API errors
|
225
|
+
|
226
|
+
## Rails Integration
|
227
|
+
|
228
|
+
The gem is designed to work seamlessly with Rails applications. See the [examples](examples/) directory for complete controller implementations:
|
229
|
+
|
230
|
+
- [DubsController](examples/dubs_controller.rb) - Complete dubbing workflow
|
231
|
+
- [TextToSpeechController](examples/text_to_speech_controller.rb) - TTS with error handling
|
232
|
+
- [StreamingAudioController](examples/streaming_audio_controller.rb) - Real-time streaming
|
233
|
+
- [TextToDialogueController](examples/text_to_dialogue_controller.rb) - Dialogue generation
|
234
|
+
- [SoundGenerationController](examples/sound_generation_controller.rb) - Sound effects
|
235
|
+
- [MusicController](examples/music_controller.rb) - AI music composition and streaming
|
236
|
+
- [TextToVoiceController](examples/text_to_voice_controller.rb) - Voice design and creation
|
237
|
+
- [VoicesController](examples/voices_controller.rb) - Voice management (CRUD operations)
|
238
|
+
|
164
239
|
## Development
|
165
240
|
|
166
|
-
After checking out the repo, run
|
241
|
+
After checking out the repo, run:
|
242
|
+
|
243
|
+
```bash
|
244
|
+
bin/setup # Install dependencies
|
245
|
+
bundle exec rspec # Run tests
|
246
|
+
```
|
247
|
+
|
248
|
+
To install this gem onto your local machine:
|
249
|
+
|
250
|
+
```bash
|
251
|
+
bundle exec rake install
|
252
|
+
```
|
253
|
+
|
254
|
+
To release a new version:
|
255
|
+
|
256
|
+
1. Update the version number in `version.rb`
|
257
|
+
2. Update `CHANGELOG.md`
|
258
|
+
3. Run `bundle exec rake release`
|
259
|
+
|
260
|
+
## Testing
|
261
|
+
|
262
|
+
The gem includes comprehensive test coverage with RSpec:
|
263
|
+
|
264
|
+
```bash
|
265
|
+
# Run all tests
|
266
|
+
bundle exec rspec
|
267
|
+
|
268
|
+
# Run specific test files
|
269
|
+
bundle exec rspec spec/elevenlabs_client/endpoints/
|
270
|
+
bundle exec rspec spec/elevenlabs_client/client
|
271
|
+
bundle exec rspec spec/integration/
|
272
|
+
|
273
|
+
# Run with documentation format
|
274
|
+
bundle exec rspec --format documentation
|
275
|
+
```
|
167
276
|
|
168
277
|
## Contributing
|
169
278
|
|
170
|
-
Bug reports and pull requests are welcome on GitHub.
|
279
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/yourusername/elevenlabs_client.
|
280
|
+
|
281
|
+
1. Fork it
|
282
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
283
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
284
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
285
|
+
5. Create a new Pull Request
|
171
286
|
|
172
287
|
## License
|
173
288
|
|
174
289
|
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
290
|
+
|
291
|
+
## Changelog
|
292
|
+
|
293
|
+
See [CHANGELOG.md](CHANGELOG.md) for a detailed list of changes and version history.
|
294
|
+
|
295
|
+
## Support
|
296
|
+
|
297
|
+
- ๐ **Documentation**: [API Documentation](docs/)
|
298
|
+
- ๐ **Issues**: [GitHub Issues](https://github.com/yourusername/elevenlabs_client/issues)
|
299
|
+
- ๐ฌ **Discussions**: [GitHub Discussions](https://github.com/yourusername/elevenlabs_client/discussions)
|
300
|
+
|
301
|
+
---
|
302
|
+
|
303
|
+
Made with โค๏ธ for the Ruby community
|