Class: ElevenlabsClient::TextToDialogue

Inherits:
Object
  • Object
show all
Defined in:
lib/elevenlabs_client/endpoints/text_to_dialogue.rb

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ TextToDialogue

Returns a new instance of TextToDialogue.



5
6
7
# File 'lib/elevenlabs_client/endpoints/text_to_dialogue.rb', line 5

def initialize(client)
  @client = client
end

Instance Method Details

#convert(inputs, **options) ⇒ String Also known as: text_to_dialogue

POST /v1/text-to-dialogue Converts a list of text and voice ID pairs into speech (dialogue) and returns audio. Documentation: https://elevenlabs.io/docs/api-reference/text-to-dialogue/convert

Parameters:

  • inputs (Array<Hash>)

    A list of dialogue inputs, each containing text and a voice ID

  • options (Hash)

    Optional parameters

Options Hash (inputs):

  • :text (String)

    The text to be converted to speech

  • :voice_id (String)

    The voice ID to use for this text

Options Hash (**options):

  • :model_id (String)

    Identifier of the model to be used

  • :settings (Hash)

    Settings controlling the dialogue generation

  • :seed (Integer)

    Best effort to sample deterministically

Returns:

  • (String)

    The binary audio data (usually an MP3)



21
22
23
24
25
26
27
28
29
30
31
# File 'lib/elevenlabs_client/endpoints/text_to_dialogue.rb', line 21

def convert(inputs, **options)
  endpoint = "/v1/text-to-dialogue"
  request_body = { inputs: inputs }

  # Add optional parameters
  request_body[:model_id] = options[:model_id] if options[:model_id]
  request_body[:settings] = options[:settings] if options[:settings] && !options[:settings].empty?
  request_body[:seed] = options[:seed] if options[:seed]

  @client.post_binary(endpoint, request_body)
end

#stream(inputs, **options, &block) ⇒ Faraday::Response Also known as: text_to_dialogue_stream

POST /v1/text-to-dialogue/stream Converts a list of text and voice ID pairs into speech (dialogue) and returns an audio stream. Documentation: https://elevenlabs.io/docs/api-reference/text-to-dialogue/stream

Parameters:

  • inputs (Array<Hash>)

    A list of dialogue inputs, each containing text and a voice ID

  • options (Hash)

    Optional parameters

  • block (Proc)

    Block to handle each audio chunk

Options Hash (**options):

  • :model_id (String)

    Identifier of the model to be used (default: "eleven_v3")

  • :language_code (String)

    ISO 639-1 language code

  • :settings (Hash)

    Settings controlling the dialogue generation

  • :pronunciation_dictionary_locators (Array<Hash>)

    Pronunciation dictionary locators (max 3)

  • :seed (Integer)

    Deterministic sampling seed (0-4294967295)

  • :apply_text_normalization (String)

    Text normalization mode ("auto", "on", "off")

  • :output_format (String)

    Output format (defaults to "mp3_44100_128")

Returns:

  • (Faraday::Response)

    The response object



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/elevenlabs_client/endpoints/text_to_dialogue.rb', line 48

def stream(inputs, **options, &block)
  # Build endpoint with optional query params
  output_format = options[:output_format] || "mp3_44100_128"
  endpoint = "/v1/text-to-dialogue/stream?output_format=#{output_format}"

  # Build request body
  request_body = { inputs: inputs }
  request_body[:model_id] = options[:model_id] if options[:model_id]
  request_body[:language_code] = options[:language_code] if options[:language_code]
  request_body[:settings] = options[:settings] if options[:settings]
  request_body[:pronunciation_dictionary_locators] = options[:pronunciation_dictionary_locators] if options[:pronunciation_dictionary_locators]
  request_body[:seed] = options[:seed] if options[:seed]
  request_body[:apply_text_normalization] = options[:apply_text_normalization] if options[:apply_text_normalization]

  @client.post_streaming(endpoint, request_body, &block)
end