Class: Telnyx::Resources::TextToSpeech

Inherits:
Object
  • Object
show all
Defined in:
lib/telnyx/resources/text_to_speech.rb

Instance Method Summary collapse

Constructor Details

#initialize(client:) ⇒ TextToSpeech

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of TextToSpeech.

Parameters:



62
63
64
# File 'lib/telnyx/resources/text_to_speech.rb', line 62

def initialize(client:)
  @client = client
end

Instance Method Details

#generate_speech(text:, voice:, request_options: {}) ⇒ StringIO

Some parameter documentations has been truncated, see Models::TextToSpeechGenerateSpeechParams for more details.

Converts the provided text to speech using the specified voice and returns audio data

Parameters:

  • text (String)

    The text to convert to speech

  • voice (String)

    The voice ID in the format Provider.ModelId.VoiceId.

  • request_options (Telnyx::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

  • (StringIO)

See Also:



23
24
25
26
27
28
29
30
31
32
33
# File 'lib/telnyx/resources/text_to_speech.rb', line 23

def generate_speech(params)
  parsed, options = Telnyx::TextToSpeechGenerateSpeechParams.dump_request(params)
  @client.request(
    method: :post,
    path: "text-to-speech/speech",
    headers: {"accept" => "audio/mpeg"},
    body: parsed,
    model: StringIO,
    options: options
  )
end

#list_voices(elevenlabs_api_key_ref: nil, provider: nil, request_options: {}) ⇒ Telnyx::Models::TextToSpeechListVoicesResponse

Returns a list of voices that can be used with the text to speech commands.

Parameters:

Returns:

See Also:



48
49
50
51
52
53
54
55
56
57
# File 'lib/telnyx/resources/text_to_speech.rb', line 48

def list_voices(params = {})
  parsed, options = Telnyx::TextToSpeechListVoicesParams.dump_request(params)
  @client.request(
    method: :get,
    path: "text-to-speech/voices",
    query: parsed,
    model: Telnyx::Models::TextToSpeechListVoicesResponse,
    options: options
  )
end