Class: Deepgram::Listen::Client

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

Overview

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

Instance Method Summary collapse

Methods included from ResponseHandler

#handle_response

Constructor Details

#initializeClient

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



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

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

Instance Method Details

#transcribe_file(path:, audio_format: 'audio/wav', **kwargs) ⇒ Deepgram::Listen::Response

Transcribes audio content from a file.

Parameters:

  • path (String)

    The local file system path to the audio file to be transcribed.

  • audio_format (String) (defaults to: 'audio/wav')

    The MIME type of the audio file (defaults to ‘audio/wav’).

  • kwargs (Hash)

    Additional keyword arguments for the request.

Returns:



23
24
25
26
27
28
29
30
# File 'lib/deepgram/listen.rb', line 23

def transcribe_file(path:, audio_format: 'audio/wav', **kwargs)
  validate_file_path(path)

  request(:post, **kwargs) do |request|
    request.headers['Content-Type'] = audio_format
    request.body = File.binread(path)
  end
end

#transcribe_url(url:, **kwargs) ⇒ Deepgram::Listen::Response

Transcribes audio content from a URL.

Parameters:

  • url (String)

    The URL of the audio file to be transcribed.

  • kwargs (Hash)

    Additional keyword arguments for the request.

Returns:



37
38
39
40
41
42
43
# File 'lib/deepgram/listen.rb', line 37

def transcribe_url(url:, **kwargs)
  validate_url(url)

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