elevenlabs_client 0.5.0 → 0.7.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.
@@ -1,26 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module ElevenlabsClient
4
- class Models
5
- def initialize(client)
6
- @client = client
7
- end
8
-
9
- # GET /v1/models
10
- # Gets a list of available models
11
- # Documentation: https://elevenlabs.io/docs/api-reference/models/list
12
- #
13
- # @return [Hash] The JSON response containing an array of models
14
- def list
15
- endpoint = "/v1/models"
16
- @client.get(endpoint)
17
- end
18
-
19
- # Alias for backward compatibility and convenience
20
- alias_method :list_models, :list
21
-
22
- private
23
-
24
- attr_reader :client
25
- end
26
- end
@@ -1,50 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module ElevenlabsClient
4
- class TextToDialogueStream
5
- def initialize(client)
6
- @client = client
7
- end
8
-
9
- # POST /v1/text-to-dialogue/stream
10
- # Converts a list of text and voice ID pairs into speech (dialogue) and returns an audio stream.
11
- # Documentation: https://elevenlabs.io/docs/api-reference/text-to-dialogue/stream
12
- #
13
- # @param inputs [Array<Hash>] A list of dialogue inputs, each containing text and a voice ID
14
- # @param options [Hash] Optional parameters
15
- # @option options [String] :model_id Identifier of the model to be used (default: "eleven_v3")
16
- # @option options [String] :language_code ISO 639-1 language code
17
- # @option options [Hash] :settings Settings controlling the dialogue generation
18
- # @option options [Array<Hash>] :pronunciation_dictionary_locators Pronunciation dictionary locators (max 3)
19
- # @option options [Integer] :seed Deterministic sampling seed (0-4294967295)
20
- # @option options [String] :apply_text_normalization Text normalization mode ("auto", "on", "off")
21
- # @option options [String] :output_format Output format (defaults to "mp3_44100_128")
22
- # @param block [Proc] Block to handle each audio chunk
23
- # @return [Faraday::Response] The response object
24
- def stream(inputs, **options, &block)
25
- # Build endpoint with optional query params
26
- output_format = options[:output_format] || "mp3_44100_128"
27
- endpoint = "/v1/text-to-dialogue/stream?output_format=#{output_format}"
28
-
29
- # Build request body
30
- request_body = { inputs: inputs }
31
- request_body[:model_id] = options[:model_id] if options[:model_id]
32
- request_body[:language_code] = options[:language_code] if options[:language_code]
33
- request_body[:settings] = options[:settings] if options[:settings]
34
- request_body[:pronunciation_dictionary_locators] = options[:pronunciation_dictionary_locators] if options[:pronunciation_dictionary_locators]
35
- request_body[:seed] = options[:seed] if options[:seed]
36
- request_body[:apply_text_normalization] = options[:apply_text_normalization] if options[:apply_text_normalization]
37
-
38
- @client.post_streaming(endpoint, request_body, &block)
39
- end
40
-
41
- # Alias for convenience
42
- alias_method :text_to_dialogue_stream, :stream
43
-
44
- private
45
-
46
- attr_reader :client
47
- end
48
- end
49
-
50
-
@@ -1,43 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module ElevenlabsClient
4
- class TextToSpeechStream
5
- def initialize(client)
6
- @client = client
7
- end
8
-
9
- # POST /v1/text-to-speech/{voice_id}/stream
10
- # Stream text-to-speech audio in real-time chunks
11
- # Documentation: https://elevenlabs.io/docs/api-reference/text-to-speech/stream
12
- #
13
- # @param voice_id [String] The ID of the voice to use
14
- # @param text [String] Text to synthesize
15
- # @param options [Hash] Optional TTS parameters
16
- # @option options [String] :model_id Model to use (defaults to "eleven_multilingual_v2")
17
- # @option options [String] :output_format Output format (defaults to "mp3_44100_128")
18
- # @option options [Hash] :voice_settings Voice configuration
19
- # @param block [Proc] Block to handle each audio chunk
20
- # @return [Faraday::Response] The response object
21
- def stream(voice_id, text, **options, &block)
22
- output_format = options[:output_format] || "mp3_44100_128"
23
- endpoint = "/v1/text-to-speech/#{voice_id}/stream?output_format=#{output_format}"
24
-
25
- request_body = {
26
- text: text,
27
- model_id: options[:model_id] || "eleven_multilingual_v2"
28
- }
29
-
30
- # Add voice_settings if provided
31
- request_body[:voice_settings] = options[:voice_settings] if options[:voice_settings]
32
-
33
- @client.post_streaming(endpoint, request_body, &block)
34
- end
35
-
36
- # Alias for backward compatibility
37
- alias_method :text_to_speech_stream, :stream
38
-
39
- private
40
-
41
- attr_reader :client
42
- end
43
- end
@@ -1,75 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module ElevenlabsClient
4
- class TextToSpeechStreamWithTimestamps
5
- def initialize(client)
6
- @client = client
7
- end
8
-
9
- # POST /v1/text-to-speech/{voice_id}/stream/with-timestamps
10
- # Stream text-to-speech audio with character-level timing information
11
- # Documentation: https://elevenlabs.io/docs/api-reference/text-to-speech/stream-with-timestamps
12
- #
13
- # @param voice_id [String] Voice ID to be used
14
- # @param text [String] The text that will get converted into speech
15
- # @param options [Hash] Optional TTS parameters
16
- # @option options [String] :model_id Model identifier (defaults to "eleven_multilingual_v2")
17
- # @option options [String] :language_code ISO 639-1 language code for text normalization
18
- # @option options [Hash] :voice_settings Voice settings overriding stored settings
19
- # @option options [Array<Hash>] :pronunciation_dictionary_locators Pronunciation dictionary locators (max 3)
20
- # @option options [Integer] :seed Deterministic sampling seed (0-4294967295)
21
- # @option options [String] :previous_text Text that came before current request
22
- # @option options [String] :next_text Text that comes after current request
23
- # @option options [Array<String>] :previous_request_ids Request IDs of previous samples (max 3)
24
- # @option options [Array<String>] :next_request_ids Request IDs of next samples (max 3)
25
- # @option options [String] :apply_text_normalization Text normalization mode ("auto", "on", "off")
26
- # @option options [Boolean] :apply_language_text_normalization Language text normalization
27
- # @option options [Boolean] :use_pvc_as_ivc Use IVC version instead of PVC (deprecated)
28
- # @option options [Boolean] :enable_logging Enable logging (defaults to true)
29
- # @option options [Integer] :optimize_streaming_latency Latency optimizations (0-4, deprecated)
30
- # @option options [String] :output_format Output format (defaults to "mp3_44100_128")
31
- # @param block [Proc] Block to handle each streaming chunk containing audio and timing data
32
- # @return [Faraday::Response] The response object
33
- def stream(voice_id, text, **options, &block)
34
- # Build query parameters
35
- query_params = {}
36
- query_params[:enable_logging] = options[:enable_logging] unless options[:enable_logging].nil?
37
- query_params[:optimize_streaming_latency] = options[:optimize_streaming_latency] if options[:optimize_streaming_latency]
38
- query_params[:output_format] = options[:output_format] if options[:output_format]
39
-
40
- # Build endpoint with query parameters
41
- endpoint = "/v1/text-to-speech/#{voice_id}/stream/with-timestamps"
42
- if query_params.any?
43
- query_string = query_params.map { |k, v| "#{k}=#{v}" }.join("&")
44
- endpoint += "?#{query_string}"
45
- end
46
-
47
- # Build request body
48
- request_body = { text: text }
49
-
50
- # Add optional body parameters
51
- request_body[:model_id] = options[:model_id] if options[:model_id]
52
- request_body[:language_code] = options[:language_code] if options[:language_code]
53
- request_body[:voice_settings] = options[:voice_settings] if options[:voice_settings]
54
- request_body[:pronunciation_dictionary_locators] = options[:pronunciation_dictionary_locators] if options[:pronunciation_dictionary_locators]
55
- request_body[:seed] = options[:seed] if options[:seed]
56
- request_body[:previous_text] = options[:previous_text] if options[:previous_text]
57
- request_body[:next_text] = options[:next_text] if options[:next_text]
58
- request_body[:previous_request_ids] = options[:previous_request_ids] if options[:previous_request_ids]
59
- request_body[:next_request_ids] = options[:next_request_ids] if options[:next_request_ids]
60
- request_body[:apply_text_normalization] = options[:apply_text_normalization] if options[:apply_text_normalization]
61
- request_body[:apply_language_text_normalization] = options[:apply_language_text_normalization] unless options[:apply_language_text_normalization].nil?
62
- request_body[:use_pvc_as_ivc] = options[:use_pvc_as_ivc] unless options[:use_pvc_as_ivc].nil?
63
-
64
- # Use streaming method with JSON parsing for timestamp data
65
- @client.post_streaming_with_timestamps(endpoint, request_body, &block)
66
- end
67
-
68
- # Alias for backward compatibility
69
- alias_method :text_to_speech_stream_with_timestamps, :stream
70
-
71
- private
72
-
73
- attr_reader :client
74
- end
75
- end
@@ -1,73 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module ElevenlabsClient
4
- class TextToSpeechWithTimestamps
5
- def initialize(client)
6
- @client = client
7
- end
8
-
9
- # POST /v1/text-to-speech/{voice_id}/with-timestamps
10
- # Generate speech from text with precise character-level timing information
11
- # Documentation: https://elevenlabs.io/docs/api-reference/text-to-speech/with-timestamps
12
- #
13
- # @param voice_id [String] Voice ID to be used
14
- # @param text [String] The text that will get converted into speech
15
- # @param options [Hash] Optional TTS parameters
16
- # @option options [String] :model_id Model identifier (defaults to "eleven_multilingual_v2")
17
- # @option options [String] :language_code ISO 639-1 language code for text normalization
18
- # @option options [Hash] :voice_settings Voice settings overriding stored settings
19
- # @option options [Array<Hash>] :pronunciation_dictionary_locators Pronunciation dictionary locators (max 3)
20
- # @option options [Integer] :seed Deterministic sampling seed (0-4294967295)
21
- # @option options [String] :previous_text Text that came before current request
22
- # @option options [String] :next_text Text that comes after current request
23
- # @option options [Array<String>] :previous_request_ids Request IDs of previous samples (max 3)
24
- # @option options [Array<String>] :next_request_ids Request IDs of next samples (max 3)
25
- # @option options [String] :apply_text_normalization Text normalization mode ("auto", "on", "off")
26
- # @option options [Boolean] :apply_language_text_normalization Language text normalization
27
- # @option options [Boolean] :use_pvc_as_ivc Use IVC version instead of PVC (deprecated)
28
- # @option options [Boolean] :enable_logging Enable logging (defaults to true)
29
- # @option options [Integer] :optimize_streaming_latency Latency optimizations (0-4, deprecated)
30
- # @option options [String] :output_format Output format (defaults to "mp3_44100_128")
31
- # @return [Hash] Response containing audio_base64, alignment, and normalized_alignment
32
- def generate(voice_id, text, **options)
33
- # Build query parameters
34
- query_params = {}
35
- query_params[:enable_logging] = options[:enable_logging] unless options[:enable_logging].nil?
36
- query_params[:optimize_streaming_latency] = options[:optimize_streaming_latency] if options[:optimize_streaming_latency]
37
- query_params[:output_format] = options[:output_format] if options[:output_format]
38
-
39
- # Build endpoint with query parameters
40
- endpoint = "/v1/text-to-speech/#{voice_id}/with-timestamps"
41
- if query_params.any?
42
- query_string = query_params.map { |k, v| "#{k}=#{v}" }.join("&")
43
- endpoint += "?#{query_string}"
44
- end
45
-
46
- # Build request body
47
- request_body = { text: text }
48
-
49
- # Add optional body parameters
50
- request_body[:model_id] = options[:model_id] if options[:model_id]
51
- request_body[:language_code] = options[:language_code] if options[:language_code]
52
- request_body[:voice_settings] = options[:voice_settings] if options[:voice_settings]
53
- request_body[:pronunciation_dictionary_locators] = options[:pronunciation_dictionary_locators] if options[:pronunciation_dictionary_locators]
54
- request_body[:seed] = options[:seed] if options[:seed]
55
- request_body[:previous_text] = options[:previous_text] if options[:previous_text]
56
- request_body[:next_text] = options[:next_text] if options[:next_text]
57
- request_body[:previous_request_ids] = options[:previous_request_ids] if options[:previous_request_ids]
58
- request_body[:next_request_ids] = options[:next_request_ids] if options[:next_request_ids]
59
- request_body[:apply_text_normalization] = options[:apply_text_normalization] if options[:apply_text_normalization]
60
- request_body[:apply_language_text_normalization] = options[:apply_language_text_normalization] unless options[:apply_language_text_normalization].nil?
61
- request_body[:use_pvc_as_ivc] = options[:use_pvc_as_ivc] unless options[:use_pvc_as_ivc].nil?
62
-
63
- @client.post(endpoint, request_body)
64
- end
65
-
66
- # Alias for backward compatibility
67
- alias_method :text_to_speech_with_timestamps, :generate
68
-
69
- private
70
-
71
- attr_reader :client
72
- end
73
- end