Class: Elevenlabs::Client
- Inherits:
-
Object
- Object
- Elevenlabs::Client
- Defined in:
- lib/elevenlabs/client.rb,
lib/elevenlabs/rb/version.rb
Defined Under Namespace
Classes: Error
Constant Summary collapse
- ELEVENLABS_FQDN =
'https://api.elevenlabs.io'
- DEFAULT_STABILITY =
0.5
- DEFAULT_STYLE =
0.5
- DEFAULT_MODEL =
'eleven_monolingual_v1'
- VERSION =
"0.2.0"
Instance Attribute Summary collapse
-
#api_key ⇒ Object
Returns the value of attribute api_key.
Instance Method Summary collapse
-
#initialize(api_key:) ⇒ Client
constructor
A new instance of Client.
- #list_voices ⇒ Object
- #text_to_speech(voice_id:, optimize_streaming_latency: 0, text:, style: DEFAULT_STYLE, stability: DEFAULT_STABILITY, model: DEFAULT_MODEL, stream: false) ⇒ Object
- #text_to_speech_stream(voice_id:, optimize_streaming_latency: 0, text:, stability: DEFAULT_STABILITY, model: DEFAULT_MODEL) ⇒ Object
Constructor Details
#initialize(api_key:) ⇒ Client
Returns a new instance of Client.
17 18 19 |
# File 'lib/elevenlabs/client.rb', line 17 def initialize(api_key:) @api_key = api_key end |
Instance Attribute Details
#api_key ⇒ Object
Returns the value of attribute api_key.
13 14 15 |
# File 'lib/elevenlabs/client.rb', line 13 def api_key @api_key end |
Instance Method Details
#list_voices ⇒ Object
40 41 42 |
# File 'lib/elevenlabs/client.rb', line 40 def list_voices JSON.parse(.get("#{ELEVENLABS_FQDN}/v1/voices").to_s) end |
#text_to_speech(voice_id:, optimize_streaming_latency: 0, text:, style: DEFAULT_STYLE, stability: DEFAULT_STABILITY, model: DEFAULT_MODEL, stream: false) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/elevenlabs/client.rb', line 21 def text_to_speech(voice_id:, optimize_streaming_latency: 0, text:, style: DEFAULT_STYLE, stability: DEFAULT_STABILITY, model: DEFAULT_MODEL, stream: false) body = { text: text, model_id: model, voice_settings: { stability: stability, similarity_boost: 0, style: style } } url_path = stream ? "#{ELEVENLABS_FQDN}/v1/text-to-speech/#{voice_id}/stream" : "#{ELEVENLABS_FQDN}/v1/text-to-speech/#{voice_id}" .post(url_path, :params => {optimize_streaming_latency: optimize_streaming_latency}, json: body).to_s end |
#text_to_speech_stream(voice_id:, optimize_streaming_latency: 0, text:, stability: DEFAULT_STABILITY, model: DEFAULT_MODEL) ⇒ Object
36 37 38 |
# File 'lib/elevenlabs/client.rb', line 36 def text_to_speech_stream(voice_id:, optimize_streaming_latency: 0, text:, stability: DEFAULT_STABILITY, model: DEFAULT_MODEL) text_to_speech(stream: true, voice_id: voice_id, optimize_streaming_latency: optimize_streaming_latency, text: text, stability: stability, model: model) end |