Class: OpenApiOpenAIClient::AudioApi

Inherits:
Object
  • Object
show all
Defined in:
lib/openapi_openai/api/audio_api.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(api_client = ApiClient.default) ⇒ AudioApi

Returns a new instance of AudioApi.



19
20
21
# File 'lib/openapi_openai/api/audio_api.rb', line 19

def initialize(api_client = ApiClient.default)
  @api_client = api_client
end

Instance Attribute Details

#api_clientObject

Returns the value of attribute api_client.



17
18
19
# File 'lib/openapi_openai/api/audio_api.rb', line 17

def api_client
  @api_client
end

Instance Method Details

#create_speech(create_speech_request, opts = {}) ⇒ File

Generates audio from the input text.

Parameters:

  • create_speech_request (CreateSpeechRequest)
  • opts (Hash) (defaults to: {})

    the optional parameters

Returns:

  • (File)


26
27
28
29
# File 'lib/openapi_openai/api/audio_api.rb', line 26

def create_speech(create_speech_request, opts = {})
  data, _status_code, _headers = create_speech_with_http_info(create_speech_request, opts)
  data
end

#create_speech_with_http_info(create_speech_request, opts = {}) ⇒ Array<(File, Integer, Hash)>

Generates audio from the input text.

Parameters:

  • create_speech_request (CreateSpeechRequest)
  • opts (Hash) (defaults to: {})

    the optional parameters

Returns:

  • (Array<(File, Integer, Hash)>)

    File data, response status code and response headers



35
36
37
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
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/openapi_openai/api/audio_api.rb', line 35

def create_speech_with_http_info(create_speech_request, opts = {})
  if @api_client.config.debugging
    @api_client.config.logger.debug 'Calling API: AudioApi.create_speech ...'
  end
  # verify the required parameter 'create_speech_request' is set
  if @api_client.config.client_side_validation && create_speech_request.nil?
    fail ArgumentError, "Missing the required parameter 'create_speech_request' when calling AudioApi.create_speech"
  end
  # resource path
  local_var_path = '/audio/speech'

  # query parameters
  query_params = opts[:query_params] || {}

  # header parameters
  header_params = opts[:header_params] || {}
  # HTTP header 'Accept' (if needed)
  header_params['Accept'] = @api_client.select_header_accept(['application/octet-stream'])
  # HTTP header 'Content-Type'
  content_type = @api_client.select_header_content_type(['application/json'])
  if !content_type.nil?
      header_params['Content-Type'] = content_type
  end

  # form parameters
  form_params = opts[:form_params] || {}

  # http body (model)
  post_body = opts[:debug_body] || @api_client.object_to_http_body(create_speech_request)

  # return_type
  return_type = opts[:debug_return_type] || 'File'

  # auth_names
  auth_names = opts[:debug_auth_names] || ['ApiKeyAuth']

  new_options = opts.merge(
    :operation => :"AudioApi.create_speech",
    :header_params => header_params,
    :query_params => query_params,
    :form_params => form_params,
    :body => post_body,
    :auth_names => auth_names,
    :return_type => return_type
  )

  data, status_code, headers = @api_client.call_api(:POST, local_var_path, new_options)
  if @api_client.config.debugging
    @api_client.config.logger.debug "API called: AudioApi#create_speech\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
  end
  return data, status_code, headers
end

#create_transcription(file, model, opts = {}) ⇒ CreateTranscription200Response

Transcribes audio into the input language.

Parameters:

  • file (File)

    The audio file object (not file name) to transcribe, in one of these formats: flac, mp3, mp4, mpeg, mpga, m4a, ogg, wav, or webm.

  • model (CreateTranscriptionRequestModel)
  • opts (Hash) (defaults to: {})

    the optional parameters

Options Hash (opts):

  • :language (String)

    The language of the input audio. Supplying the input language in [ISO-639-1](en.wikipedia.org/wiki/List_of_ISO_639-1_codes) format will improve accuracy and latency.

  • :prompt (String)

    An optional text to guide the model&#39;s style or continue a previous audio segment. The [prompt](/docs/guides/speech-to-text/prompting) should match the audio language.

  • :response_format (String)

    The format of the transcript output, in one of these options: &#x60;json&#x60;, &#x60;text&#x60;, &#x60;srt&#x60;, &#x60;verbose_json&#x60;, or &#x60;vtt&#x60;. (default to ‘json’)

  • :temperature (Float)

    The sampling temperature, between 0 and 1. Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and deterministic. If set to 0, the model will use [log probability](en.wikipedia.org/wiki/Log_probability) to automatically increase the temperature until certain thresholds are hit. (default to 0)

  • :timestamp_granularities (Array<String>)

    The timestamp granularities to populate for this transcription. &#x60;response_format&#x60; must be set &#x60;verbose_json&#x60; to use timestamp granularities. Either or both of these options are supported: &#x60;word&#x60;, or &#x60;segment&#x60;. Note: There is no additional latency for segment timestamps, but generating word timestamps incurs additional latency.

Returns:



98
99
100
101
# File 'lib/openapi_openai/api/audio_api.rb', line 98

def create_transcription(file, model, opts = {})
  data, _status_code, _headers = create_transcription_with_http_info(file, model, opts)
  data
end

#create_transcription_with_http_info(file, model, opts = {}) ⇒ Array<(CreateTranscription200Response, Integer, Hash)>

Transcribes audio into the input language.

Parameters:

  • file (File)

    The audio file object (not file name) to transcribe, in one of these formats: flac, mp3, mp4, mpeg, mpga, m4a, ogg, wav, or webm.

  • model (CreateTranscriptionRequestModel)
  • opts (Hash) (defaults to: {})

    the optional parameters

Options Hash (opts):

  • :language (String)

    The language of the input audio. Supplying the input language in [ISO-639-1](en.wikipedia.org/wiki/List_of_ISO_639-1_codes) format will improve accuracy and latency.

  • :prompt (String)

    An optional text to guide the model&#39;s style or continue a previous audio segment. The [prompt](/docs/guides/speech-to-text/prompting) should match the audio language.

  • :response_format (String)

    The format of the transcript output, in one of these options: &#x60;json&#x60;, &#x60;text&#x60;, &#x60;srt&#x60;, &#x60;verbose_json&#x60;, or &#x60;vtt&#x60;. (default to ‘json’)

  • :temperature (Float)

    The sampling temperature, between 0 and 1. Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and deterministic. If set to 0, the model will use [log probability](en.wikipedia.org/wiki/Log_probability) to automatically increase the temperature until certain thresholds are hit. (default to 0)

  • :timestamp_granularities (Array<String>)

    The timestamp granularities to populate for this transcription. &#x60;response_format&#x60; must be set &#x60;verbose_json&#x60; to use timestamp granularities. Either or both of these options are supported: &#x60;word&#x60;, or &#x60;segment&#x60;. Note: There is no additional latency for segment timestamps, but generating word timestamps incurs additional latency.

Returns:



113
114
115
116
117
118
119
120
121
122
123
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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
# File 'lib/openapi_openai/api/audio_api.rb', line 113

def create_transcription_with_http_info(file, model, opts = {})
  if @api_client.config.debugging
    @api_client.config.logger.debug 'Calling API: AudioApi.create_transcription ...'
  end
  # verify the required parameter 'file' is set
  if @api_client.config.client_side_validation && file.nil?
    fail ArgumentError, "Missing the required parameter 'file' when calling AudioApi.create_transcription"
  end
  # verify the required parameter 'model' is set
  if @api_client.config.client_side_validation && model.nil?
    fail ArgumentError, "Missing the required parameter 'model' when calling AudioApi.create_transcription"
  end
  allowable_values = ["json", "text", "srt", "verbose_json", "vtt"]
  if @api_client.config.client_side_validation && opts[:'response_format'] && !allowable_values.include?(opts[:'response_format'])
    fail ArgumentError, "invalid value for \"response_format\", must be one of #{allowable_values}"
  end
  allowable_values = ["word", "segment"]
  if @api_client.config.client_side_validation && opts[:'timestamp_granularities'] && !opts[:'timestamp_granularities'].all? { |item| allowable_values.include?(item) }
    fail ArgumentError, "invalid value for \"timestamp_granularities\", must include one of #{allowable_values}"
  end
  # resource path
  local_var_path = '/audio/transcriptions'

  # query parameters
  query_params = opts[:query_params] || {}

  # header parameters
  header_params = opts[:header_params] || {}
  # HTTP header 'Accept' (if needed)
  header_params['Accept'] = @api_client.select_header_accept(['application/json'])
  # HTTP header 'Content-Type'
  content_type = @api_client.select_header_content_type(['multipart/form-data'])
  if !content_type.nil?
      header_params['Content-Type'] = content_type
  end

  # form parameters
  form_params = opts[:form_params] || {}
  form_params['file'] = file
  form_params['model'] = model
  form_params['language'] = opts[:'language'] if !opts[:'language'].nil?
  form_params['prompt'] = opts[:'prompt'] if !opts[:'prompt'].nil?
  form_params['response_format'] = opts[:'response_format'] if !opts[:'response_format'].nil?
  form_params['temperature'] = opts[:'temperature'] if !opts[:'temperature'].nil?
  form_params['timestamp_granularities[]'] = @api_client.build_collection_param(opts[:'timestamp_granularities'], :csv) if !opts[:'timestamp_granularities'].nil?

  # http body (model)
  post_body = opts[:debug_body]

  # return_type
  return_type = opts[:debug_return_type] || 'CreateTranscription200Response'

  # auth_names
  auth_names = opts[:debug_auth_names] || ['ApiKeyAuth']

  new_options = opts.merge(
    :operation => :"AudioApi.create_transcription",
    :header_params => header_params,
    :query_params => query_params,
    :form_params => form_params,
    :body => post_body,
    :auth_names => auth_names,
    :return_type => return_type
  )

  data, status_code, headers = @api_client.call_api(:POST, local_var_path, new_options)
  if @api_client.config.debugging
    @api_client.config.logger.debug "API called: AudioApi#create_transcription\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
  end
  return data, status_code, headers
end

#create_translation(file, model, opts = {}) ⇒ CreateTranslation200Response

Translates audio into English.

Parameters:

  • file (File)

    The audio file object (not file name) translate, in one of these formats: flac, mp3, mp4, mpeg, mpga, m4a, ogg, wav, or webm.

  • model (CreateTranscriptionRequestModel)
  • opts (Hash) (defaults to: {})

    the optional parameters

Options Hash (opts):

  • :prompt (String)

    An optional text to guide the model&#39;s style or continue a previous audio segment. The [prompt](/docs/guides/speech-to-text/prompting) should be in English.

  • :response_format (String)

    The format of the transcript output, in one of these options: &#x60;json&#x60;, &#x60;text&#x60;, &#x60;srt&#x60;, &#x60;verbose_json&#x60;, or &#x60;vtt&#x60;. (default to ‘json’)

  • :temperature (Float)

    The sampling temperature, between 0 and 1. Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and deterministic. If set to 0, the model will use [log probability](en.wikipedia.org/wiki/Log_probability) to automatically increase the temperature until certain thresholds are hit. (default to 0)

Returns:



193
194
195
196
# File 'lib/openapi_openai/api/audio_api.rb', line 193

def create_translation(file, model, opts = {})
  data, _status_code, _headers = create_translation_with_http_info(file, model, opts)
  data
end

#create_translation_with_http_info(file, model, opts = {}) ⇒ Array<(CreateTranslation200Response, Integer, Hash)>

Translates audio into English.

Parameters:

  • file (File)

    The audio file object (not file name) translate, in one of these formats: flac, mp3, mp4, mpeg, mpga, m4a, ogg, wav, or webm.

  • model (CreateTranscriptionRequestModel)
  • opts (Hash) (defaults to: {})

    the optional parameters

Options Hash (opts):

  • :prompt (String)

    An optional text to guide the model&#39;s style or continue a previous audio segment. The [prompt](/docs/guides/speech-to-text/prompting) should be in English.

  • :response_format (String)

    The format of the transcript output, in one of these options: &#x60;json&#x60;, &#x60;text&#x60;, &#x60;srt&#x60;, &#x60;verbose_json&#x60;, or &#x60;vtt&#x60;. (default to ‘json’)

  • :temperature (Float)

    The sampling temperature, between 0 and 1. Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and deterministic. If set to 0, the model will use [log probability](en.wikipedia.org/wiki/Log_probability) to automatically increase the temperature until certain thresholds are hit. (default to 0)

Returns:



206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
# File 'lib/openapi_openai/api/audio_api.rb', line 206

def create_translation_with_http_info(file, model, opts = {})
  if @api_client.config.debugging
    @api_client.config.logger.debug 'Calling API: AudioApi.create_translation ...'
  end
  # verify the required parameter 'file' is set
  if @api_client.config.client_side_validation && file.nil?
    fail ArgumentError, "Missing the required parameter 'file' when calling AudioApi.create_translation"
  end
  # verify the required parameter 'model' is set
  if @api_client.config.client_side_validation && model.nil?
    fail ArgumentError, "Missing the required parameter 'model' when calling AudioApi.create_translation"
  end
  # resource path
  local_var_path = '/audio/translations'

  # query parameters
  query_params = opts[:query_params] || {}

  # header parameters
  header_params = opts[:header_params] || {}
  # HTTP header 'Accept' (if needed)
  header_params['Accept'] = @api_client.select_header_accept(['application/json'])
  # HTTP header 'Content-Type'
  content_type = @api_client.select_header_content_type(['multipart/form-data'])
  if !content_type.nil?
      header_params['Content-Type'] = content_type
  end

  # form parameters
  form_params = opts[:form_params] || {}
  form_params['file'] = file
  form_params['model'] = model
  form_params['prompt'] = opts[:'prompt'] if !opts[:'prompt'].nil?
  form_params['response_format'] = opts[:'response_format'] if !opts[:'response_format'].nil?
  form_params['temperature'] = opts[:'temperature'] if !opts[:'temperature'].nil?

  # http body (model)
  post_body = opts[:debug_body]

  # return_type
  return_type = opts[:debug_return_type] || 'CreateTranslation200Response'

  # auth_names
  auth_names = opts[:debug_auth_names] || ['ApiKeyAuth']

  new_options = opts.merge(
    :operation => :"AudioApi.create_translation",
    :header_params => header_params,
    :query_params => query_params,
    :form_params => form_params,
    :body => post_body,
    :auth_names => auth_names,
    :return_type => return_type
  )

  data, status_code, headers = @api_client.call_api(:POST, local_var_path, new_options)
  if @api_client.config.debugging
    @api_client.config.logger.debug "API called: AudioApi#create_translation\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
  end
  return data, status_code, headers
end