Class: Wavix::SpeechAnalytics::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/wavix/speech_analytics/client.rb

Instance Method Summary collapse

Constructor Details

#initialize(client:) ⇒ void

Parameters:



9
10
11
# File 'lib/wavix/speech_analytics/client.rb', line 9

def initialize(client:)
  @client = client
end

Instance Method Details

#create(request_options: {}, **params) ⇒ Wavix::SpeechAnalytics::Types::CreateSpeechAnalyticsResponse

Uploads an audio file for transcription. Transcription is asynchronous; Wavix sends a POST callback to callback_url when it completes, including the request_id returned by this request.

Callback body:

   {
        "request_id": "e865ea07-25af-4fdd-876e-04b0d41d5ebd",
        "status": "completed",
        "error": null
   }
  • request_id: ID of the transcription request.
  • status: One of completed (transcription succeeded) or failed (transcription encountered an error).
  • error: Error description, or null when the transcription succeeded.

Parameters:

  • request_options (Hash) (defaults to: {})
  • params (void)

Options Hash (request_options:):

  • :base_url (String)
  • :additional_headers (Hash{String => Object})
  • :additional_query_parameters (Hash{String => Object})
  • :additional_body_parameters (Hash{String => Object})
  • :timeout_in_seconds (Integer)

Returns:



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/wavix/speech_analytics/client.rb', line 38

def create(request_options: {}, **params)
  params = Wavix::Internal::Types::Utils.normalize_keys(params)
  body = Internal::Multipart::FormData.new

  body.add_part(params[:file].to_form_data_part(name: "file")) if params[:file]
  if params[:callback_url]
    body.add(
      name: "callback_url",
      value: params[:callback_url]
    )
  end
  if params[:insights]
    body.add(
      name: "insights",
      value: params[:insights]
    )
  end

  request = Wavix::Internal::Multipart::Request.new(
    base_url: request_options[:base_url],
    method: "POST",
    path: "v1/speech-analytics",
    body: body,
    request_options: request_options
  )
  begin
    response = @client.send(request)
  rescue Net::HTTPRequestTimeout
    raise Wavix::Errors::TimeoutError
  end
  code = response.code.to_i
  if code.between?(200, 299)
    Wavix::SpeechAnalytics::Types::CreateSpeechAnalyticsResponse.load(response.body)
  else
    error_class = Wavix::Errors::ResponseError.subclass_for_code(code)
    raise error_class.new(response.body, code: code)
  end
end

#fileWavix::File::Client

Returns:

  • (Wavix::File::Client)


152
153
154
# File 'lib/wavix/speech_analytics/client.rb', line 152

def file
  @file ||= Wavix::SpeechAnalytics::File::Client.new(client: @client)
end

#get(request_options: {}, **params) ⇒ Wavix::SpeechAnalytics::Types::GetSpeechAnalyticsResponse

Returns the transcription for the request identified by request_id, including transcript, speaker turns, and insights when available.

Parameters:

  • request_options (Hash) (defaults to: {})
  • params (Hash)

Options Hash (request_options:):

  • :base_url (String)
  • :additional_headers (Hash{String => Object})
  • :additional_query_parameters (Hash{String => Object})
  • :additional_body_parameters (Hash{String => Object})
  • :timeout_in_seconds (Integer)

Options Hash (**params):

  • :request_id (String)

Returns:



90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# File 'lib/wavix/speech_analytics/client.rb', line 90

def get(request_options: {}, **params)
  params = Wavix::Internal::Types::Utils.normalize_keys(params)
  request = Wavix::Internal::JSON::Request.new(
    base_url: request_options[:base_url],
    method: "GET",
    path: "v1/speech-analytics/#{URI.encode_uri_component(params[:request_id].to_s)}",
    request_options: request_options
  )
  begin
    response = @client.send(request)
  rescue Net::HTTPRequestTimeout
    raise Wavix::Errors::TimeoutError
  end
  code = response.code.to_i
  if code.between?(200, 299)
    Wavix::SpeechAnalytics::Types::GetSpeechAnalyticsResponse.load(response.body)
  else
    error_class = Wavix::Errors::ResponseError.subclass_for_code(code)
    raise error_class.new(response.body, code: code)
  end
end

#retranscribe(request_options: {}, **params) ⇒ Wavix::Types::SuccessResponse

Re-runs transcription on the file identified by request_id, replacing the existing transcript.

Parameters:

Options Hash (request_options:):

  • :base_url (String)
  • :additional_headers (Hash{String => Object})
  • :additional_query_parameters (Hash{String => Object})
  • :additional_body_parameters (Hash{String => Object})
  • :timeout_in_seconds (Integer)

Options Hash (**params):

  • :request_id (String)

Returns:



124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
# File 'lib/wavix/speech_analytics/client.rb', line 124

def retranscribe(request_options: {}, **params)
  params = Wavix::Internal::Types::Utils.normalize_keys(params)
  request_data = Wavix::SpeechAnalytics::Types::SpeechAnalyticsRetranscribeRequest.new(params).to_h
  non_body_param_names = %w[request_id]
  body = request_data.except(*non_body_param_names)

  request = Wavix::Internal::JSON::Request.new(
    base_url: request_options[:base_url],
    method: "PUT",
    path: "v1/speech-analytics/#{URI.encode_uri_component(params[:request_id].to_s)}",
    body: body,
    request_options: request_options
  )
  begin
    response = @client.send(request)
  rescue Net::HTTPRequestTimeout
    raise Wavix::Errors::TimeoutError
  end
  code = response.code.to_i
  if code.between?(200, 299)
    Wavix::Types::SuccessResponse.load(response.body)
  else
    error_class = Wavix::Errors::ResponseError.subclass_for_code(code)
    raise error_class.new(response.body, code: code)
  end
end