Class: OmniAI::Google::Transcribe::Gemini
- Inherits:
-
Object
- Object
- OmniAI::Google::Transcribe::Gemini
- Includes:
- OmniAI::Google::TranscribeHelpers
- Defined in:
- lib/omniai/google/transcribe/gemini.rb
Overview
Transcribes with a Gemini transcribe model (e.g. gemini-3.5-transcribe). Unlike Chirp (Cloud Speech-to-Text),
these are served by Vertex generateContent with the audio as the only part.
Usage:
client.transcribe("interview.wav", model: "gemini-3.5-transcribe", diarization: true)
Constant Summary collapse
- INLINE_LIMIT =
bytes; larger audio goes through GCS
10_000_000- SIGNATURES =
Leading bytes of the audio containers Gemini accepts.
generateContentrequires a mimeType. { "RIFF" => "audio/wav", "ID3" => "audio/mpeg", "\xFF\xFB".b => "audio/mpeg", "\xFF\xF3".b => "audio/mpeg", "\xFF\xF2".b => "audio/mpeg", "fLaC" => "audio/flac", "OggS" => "audio/ogg", "\x1A\x45\xDF\xA3".b => "audio/webm", "FORM" => "audio/aiff", }.freeze
- EXTENSIONS =
{ ".wav" => "audio/wav", ".mp3" => "audio/mpeg", ".flac" => "audio/flac", ".ogg" => "audio/ogg", ".opus" => "audio/ogg", ".webm" => "audio/webm", ".m4a" => "audio/mp4", ".mp4" => "audio/mp4", ".aac" => "audio/aac", ".aif" => "audio/aiff", ".aiff" => "audio/aiff", }.freeze
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(io, client:, model:, language: nil, format: nil, diarization: false, word_timestamps: false, vocabulary: nil) ⇒ Gemini
constructor
A new instance of Gemini.
- #process! ⇒ OmniAI::Transcribe::Transcription
Constructor Details
#initialize(io, client:, model:, language: nil, format: nil, diarization: false, word_timestamps: false, vocabulary: nil) ⇒ Gemini
Returns a new instance of Gemini.
54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/omniai/google/transcribe/gemini.rb', line 54 def initialize(io, client:, model:, language: nil, format: nil, diarization: false, word_timestamps: false, vocabulary: nil) @io = io @client = client.for_model(model) @model = model @language = language @format = format || OmniAI::Transcribe::Format::JSON @diarization = diarization @word_timestamps = @vocabulary = vocabulary end |
Class Method Details
.model?(model) ⇒ Boolean
38 39 40 |
# File 'lib/omniai/google/transcribe/gemini.rb', line 38 def self.model?(model) String(model).start_with?("gemini-") end |
.process! ⇒ Object
42 43 44 |
# File 'lib/omniai/google/transcribe/gemini.rb', line 42 def self.process!(...) new(...).process! end |
Instance Method Details
#process! ⇒ OmniAI::Transcribe::Transcription
69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/omniai/google/transcribe/gemini.rb', line 69 def process! raise ArgumentError, "#{@model} requires Vertex credentials" unless @client.credentials? response = request! raise HTTPError, response unless response.status.ok? OmniAI::Transcribe::Transcription.parse(model: @model, format: @format, data: parse(response.parse)) ensure cleanup_gcs_file(@uploaded_gcs_uri) if @uploaded_gcs_uri @uploaded_gcs_uri = nil end |