Class: ElevenlabsClient::SoundGeneration
- Inherits:
-
Object
- Object
- ElevenlabsClient::SoundGeneration
- Defined in:
- lib/elevenlabs_client/endpoints/sound_generation.rb
Instance Method Summary collapse
-
#generate(text, **options) ⇒ String
(also: #sound_generation)
POST /v1/sound-generation Convert text to sound effects and retrieve audio (binary data) Documentation: https://elevenlabs.io/docs/api-reference/sound-generation.
-
#initialize(client) ⇒ SoundGeneration
constructor
A new instance of SoundGeneration.
Constructor Details
#initialize(client) ⇒ SoundGeneration
Returns a new instance of SoundGeneration.
5 6 7 |
# File 'lib/elevenlabs_client/endpoints/sound_generation.rb', line 5 def initialize(client) @client = client end |
Instance Method Details
#generate(text, **options) ⇒ String Also known as: sound_generation
POST /v1/sound-generation Convert text to sound effects and retrieve audio (binary data) Documentation: https://elevenlabs.io/docs/api-reference/sound-generation
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/elevenlabs_client/endpoints/sound_generation.rb', line 20 def generate(text, **) endpoint = "/v1/sound-generation" request_body = { text: text } # Add optional parameters if provided request_body[:loop] = [:loop] unless [:loop].nil? request_body[:duration_seconds] = [:duration_seconds] if [:duration_seconds] request_body[:prompt_influence] = [:prompt_influence] if [:prompt_influence] # Handle output_format as query parameter query_params = {} query_params[:output_format] = [:output_format] if [:output_format] # Build endpoint with query parameters if any full_endpoint = query_params.any? ? "#{endpoint}?#{URI.encode_www_form(query_params)}" : endpoint @client.post_binary(full_endpoint, request_body) end |