Class: RunApi::OpenaiTranscription::Resources::SpeechToText
- Inherits:
-
Object
- Object
- RunApi::OpenaiTranscription::Resources::SpeechToText
- Includes:
- Core::ResourceHelpers
- Defined in:
- lib/runapi/openai_transcription/resources/speech_to_text.rb
Constant Summary collapse
- ENDPOINT =
"/v1/audio/transcriptions"
Instance Method Summary collapse
-
#initialize(http) ⇒ SpeechToText
constructor
A new instance of SpeechToText.
- #run(file:, options: nil, **params) ⇒ Object
Constructor Details
#initialize(http) ⇒ SpeechToText
Returns a new instance of SpeechToText.
11 12 13 |
# File 'lib/runapi/openai_transcription/resources/speech_to_text.rb', line 11 def initialize(http) @http = http end |
Instance Method Details
#run(file:, options: nil, **params) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/runapi/openai_transcription/resources/speech_to_text.rb', line 15 def run(file:, options: nil, **params) params = compact_params({file:, model: params.delete(:model) || "whisper-1", **params}) validate_contract!(CONTRACT["speech-to-text"], params) fields = params.except(:file, :languages, :keywords, :timestamp_granularities) [:languages, :keywords, :timestamp_granularities].each do |key| fields["#{key}[]"] = params[key] if params.key?(key) end body = RunApi::Core::MultipartBody.new( fields:, files: {file: RunApi::Core::MultipartFile.new(path: file, filename: File.basename(file), content_type: content_type(file))} ) response = @http.request(:post, ENDPOINT, body:, **( ? {options:} : {})) response.is_a?(RunApi::Core::Response) ? response.body : response end |