Class: Deepgram::Speak::Client

Inherits:
Base
  • Object
show all
Defined in:
lib/deepgram/speak.rb

Overview

The Client class within the Speak module extends the Base class to handle operations specific to the Deepgram ‘Speak’ API endpoint.

Instance Method Summary collapse

Methods included from ResponseHandler

#handle_response

Constructor Details

#initializeClient

Initializes the Client object for the Deepgram ‘Speak’ service, setting up the necessary API endpoint and request headers for JSON.



10
11
12
13
14
# File 'lib/deepgram/speak.rb', line 10

def initialize
  super
  @connection.path_prefix = 'v1/speak'
  @connection.headers['Content-Type'] = 'application/json'
end

Instance Method Details

#speak(text:, **kwargs) ⇒ Deepgram::Speak::Response

Sends a synchronous request to convert text to speech.

Parameters:

  • text (String)

    The text to be converted to speech.

  • kwargs (Hash)

    Additional keyword arguments for the request.

Returns:



21
22
23
24
25
# File 'lib/deepgram/speak.rb', line 21

def speak(text:, **kwargs)
  request(:post, **kwargs) do |request|
    request.body = JSON.generate(text: text)
  end
end

#speak_async(text:, callback_url:, **kwargs) ⇒ Deepgram::Speak::Response

Sends an asynchronous request to convert text to speech, with the results sent to a specified callback URL.

Parameters:

  • text (String)

    The text to be converted to speech.

  • callback_url (String)

    The URL to which the response will be sent upon completion.

  • kwargs (Hash)

    Additional keyword arguments for the request.

Returns:



34
35
36
37
38
# File 'lib/deepgram/speak.rb', line 34

def speak_async(text:, callback_url:, **kwargs)
  request(:post, callback_url: callback_url, **kwargs) do |request|
    request.body = JSON.generate(text: text)
  end
end