Class: Wavix::SpeechAnalytics::Client
- Inherits:
-
Object
- Object
- Wavix::SpeechAnalytics::Client
- Defined in:
- lib/wavix/speech_analytics/client.rb
Instance Method Summary collapse
-
#create(request_options: {}, **params) ⇒ Wavix::SpeechAnalytics::Types::CreateSpeechAnalyticsResponse
Uploads an audio file for transcription.
- #file ⇒ Wavix::File::Client
-
#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. - #initialize(client:) ⇒ void constructor
-
#retranscribe(request_options: {}, **params) ⇒ Wavix::Types::SuccessResponse
Re-runs transcription on the file identified by
request_id, replacing the existing transcript.
Constructor Details
#initialize(client:) ⇒ void
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 ofcompleted(transcription succeeded) orfailed(transcription encountered an error).error: Error description, ornullwhen the transcription succeeded.
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: [:base_url], method: "POST", path: "v1/speech-analytics", body: body, 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 |
#file ⇒ 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.
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: [:base_url], method: "GET", path: "v1/speech-analytics/#{URI.encode_uri_component(params[:request_id].to_s)}", 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.
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: [:base_url], method: "PUT", path: "v1/speech-analytics/#{URI.encode_uri_component(params[:request_id].to_s)}", body: body, 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 |