elevenlabs 0.0.7 → 0.0.8

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2daafae7b6dbf3724b93ce2022b2fe6ac3703bfbcac12326b75e1a37cd188a39
4
- data.tar.gz: ba2227a765efc7538e4aadbe0fcb0917a55c1ba70540a2660b4c75b2545f85da
3
+ metadata.gz: ea563591f2116a24c1911bd964ed30bfee9dd468e9890db98a7f38ad84138bd4
4
+ data.tar.gz: e1c155f3dc9f5daaff7ceb283ccd7493335f639a1beb66df93adaf14ac8fac96
5
5
  SHA512:
6
- metadata.gz: 07d40969dd5fdf8926c2f09c21359df4b5060b1f212797de03ef16c4fcf0dc2b6495c476a9a0741247dccf95dd30fde8d6da7404370b6acc4b61a0ea0ce8f7cd
7
- data.tar.gz: 927e01fdc01e4f985466b62e2725f676117f757d3f809d8b4da7ea420e54c0e0a57ab2279cf031dd466451ce8c7a96dd76219da4a7e3d02ada842682a20246f8
6
+ metadata.gz: 8559ecdf9dc45be3f7018afb389cb784603ba6c255db024f7276df60490504da366f462cbf2fb3886eeaf39f305ff530ef5ee4f9dcee577df883e62e48684af7
7
+ data.tar.gz: 62c761c794c8641940d5b297a0252b37dc9f41e2afcaaad777701acf7c94ee8ec3089f76559eaffd26bdf4292930cf2a9f5827f5d7ed5c523445356fa3e085b4
data/README.md CHANGED
@@ -15,6 +15,7 @@ This gem provides an easy-to-use interface for:
15
15
  - **Designing a voice** based on a text description
16
16
  - **Streaming text-to-speech audio**
17
17
  - **Music Generation**
18
+ - **Sound Effect Generation**
18
19
 
19
20
  All requests are handled via [Faraday](https://github.com/lostisland/faraday).
20
21
 
@@ -340,6 +341,51 @@ plan = client.create_music_plan(prompt: "Upbeat pop song with verse and chorus",
340
341
  puts plan[:sections]
341
342
  ```
342
343
 
344
+ 15. **Create sound effects from a prompt**
345
+
346
+ Basic Usage: Simple Prompt
347
+ Generate a sound effect with only a text prompt, using default settings (output_format: "mp3_44100_128", duration_seconds: nil (auto-detected), prompt_influence: 0.3).
348
+
349
+ ```ruby
350
+ audio_data = client.sound_generation("Futuristic laser blast in a space battle")
351
+
352
+ # Save the audio to a file
353
+ File.open("laser_blast.mp3", "wb") { |f| f.write(audio_data) }
354
+ ```
355
+
356
+ Advanced Usage: Custom Duration, Influence, and Format
357
+ Specify duration_seconds, prompt_influence, and output_format for precise control over the sound effect.
358
+ # Generate a roaring dragon sound with specific settings
359
+ ```ruby
360
+ audio_data = client.sound_generation(
361
+ "Roaring dragon in a fantasy cave",
362
+ duration_seconds: 3.0,
363
+ prompt_influence: 0.7, # Higher influence for closer adherence to the prompt
364
+ output_format: "mp3_22050_32"
365
+ )
366
+
367
+ # Save the audio to a file
368
+ File.open("dragon_roar.mp3", "wb") { |f| f.write(audio_data) }
369
+ ```
370
+
371
+
372
+ Looping Sound Effect
373
+ Create a looping sound effect for continuous playback, such as background ambiance in a video game.
374
+ # Generate a looping ambient sound for a haunted forest
375
+ ```ruby
376
+ audio_data = client.sound_generation(
377
+ "Eerie wind and distant owl hoots in a haunted forest",
378
+ loop: true,
379
+ duration_seconds: 10.0,
380
+ prompt_influence: 0.5,
381
+ output_format: "mp3_22050_32"
382
+ )
383
+ # Save the audio to a file
384
+ File.open("haunted_forest_loop.mp3", "wb") { |f| f.write(audio_data) }
385
+ ```
386
+
387
+ For more details, see the ElevenLabs Sound Generation API documentation.
388
+
343
389
  ---
344
390
 
345
391
  ## Error Handling
@@ -396,7 +442,7 @@ gem build elevenlabs.gemspec
396
442
  Install the gem locally:
397
443
 
398
444
  ```bash
399
- gem install ./elevenlabs-0.0.7.gem
445
+ gem install ./elevenlabs-0.0.8.gem
400
446
  ```
401
447
 
402
448
  ---
@@ -9,13 +9,15 @@ module Elevenlabs
9
9
  BASE_URL = "https://api.elevenlabs.io"
10
10
 
11
11
  # Note the default param: `api_key: nil`
12
- def initialize(api_key: nil)
12
+ def initialize(api_key: nil, open_timeout: 5, read_timeout: 120)
13
13
  # If the caller doesn’t provide an api_key, use the gem-wide config
14
14
  @api_key = api_key || Elevenlabs.configuration&.api_key
15
15
 
16
16
  @connection = Faraday.new(url: BASE_URL) do |conn|
17
17
  conn.request :url_encoded
18
18
  conn.response :raise_error
19
+ conn.options.open_timeout = open_timeout # time to open connection
20
+ conn.options.timeout = read_timeout # time to wait for response
19
21
  conn.adapter Faraday.default_adapter
20
22
  end
21
23
  end
@@ -129,6 +131,48 @@ module Elevenlabs
129
131
  handle_error(e)
130
132
  end
131
133
 
134
+ #####################################################
135
+ # Sound Generation #
136
+ # (POST /v1/sound-generation) #
137
+ #####################################################
138
+
139
+ # Convert text to sound effects and retrieve audio (binary data)
140
+ # Documentation: https://elevenlabs.io/docs/api-reference/sound-generation
141
+ #
142
+ # @param [String] text - text prompt describing the sound effect
143
+ # @param [Hash] options - optional parameters
144
+ # :loop => Boolean (whether to create a looping sound effect, default: false)
145
+ # :duration_seconds => Float (0.5 to 30 seconds, default: nil for auto-detection)
146
+ # :prompt_influence => Float (0.0 to 1.0, default: 0.3)
147
+ # :output_format => String (e.g., "mp3_22050_32", default: "mp3_44100_128")
148
+ #
149
+ # @return [String] The binary audio data (usually an MP3).
150
+ def sound_generation(text, options = {})
151
+ endpoint = "/v1/sound-generation"
152
+ request_body = { text: text }
153
+
154
+ # Add optional parameters if provided
155
+ request_body[:loop] = options[:loop] unless options[:loop].nil?
156
+ request_body[:duration_seconds] = options[:duration_seconds] if options[:duration_seconds]
157
+ request_body[:prompt_influence] = options[:prompt_influence] if options[:prompt_influence]
158
+
159
+ headers = default_headers
160
+ headers["Accept"] = "audio/mpeg"
161
+
162
+ query = {}
163
+ query[:output_format] = options[:output_format] if options[:output_format]
164
+
165
+ response = @connection.post("#{endpoint}?#{URI.encode_www_form(query)}") do |req|
166
+ req.headers = headers
167
+ req.body = request_body.to_json
168
+ end
169
+
170
+ # Returns raw binary data (often MP3)
171
+ response.body
172
+ rescue Faraday::ClientError => e
173
+ handle_error(e)
174
+ end
175
+
132
176
  #####################################################
133
177
  # Design a Voice #
134
178
  # (POST /v1/text-to-voice/design) #
data/lib/elevenlabs.rb CHANGED
@@ -5,7 +5,7 @@ require_relative "elevenlabs/client"
5
5
  require_relative "elevenlabs/errors"
6
6
 
7
7
  module Elevenlabs
8
- VERSION = "0.0.7"
8
+ VERSION = "0.0.8"
9
9
 
10
10
  # Optional global configuration
11
11
  class << self
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.7
4
+ version: 0.0.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - hackliteracy
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2025-08-25 00:00:00.000000000 Z
11
+ date: 2025-09-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday