Module: Cohere::Transcribe::Audio::FFmpegNative

Defined in:
lib/cohere/transcribe/audio/ffmpeg_native.rb

Overview

Lazy binding for the gem's subprocess-free libav decoder adapter. The adapter itself dynamically selects a compatible FFmpeg 4-8 runtime; Ruby never launches ffmpeg and does not retain a Python codec runtime.

Defined Under Namespace

Classes: Library

Constant Summary collapse

ERROR_CAPACITY =
1_024
CANCELLED_STATUS =
6

Class Method Summary collapse

Class Method Details

.available?Boolean

Returns:

  • (Boolean)


237
238
239
240
241
242
# File 'lib/cohere/transcribe/audio/ffmpeg_native.rb', line 237

def available?
  library
  true
rescue TranscriptionRuntimeError
  false
end

.cancel_active!Object

Pipeline cleanup must not load FFmpeg merely to discover that no native decode has ever started. If the adapter is already resident, this wakes every operation that captured an older cancellation generation while preserving later independent calls.



268
269
270
271
272
273
# File 'lib/cohere/transcribe/audio/ffmpeg_native.rb', line 268

def cancel_active!
  Library.loaded&.cancel_all!
  nil
rescue Fiddle::DLError, TranscriptionRuntimeError
  nil
end

.cancel_all!Object



258
259
260
261
262
# File 'lib/cohere/transcribe/audio/ffmpeg_native.rb', line 258

def cancel_all!
  library.cancel_all!
rescue TranscriptionRuntimeError
  nil
end

.decode(path, sample_rate:, max_decoded_bytes:) ⇒ Object



250
251
252
# File 'lib/cohere/transcribe/audio/ffmpeg_native.rb', line 250

def decode(path, sample_rate:, max_decoded_bytes:)
  library.decode(path, sample_rate: sample_rate, max_decoded_bytes: max_decoded_bytes)
end

.diagnosticObject



244
245
246
247
248
# File 'lib/cohere/transcribe/audio/ffmpeg_native.rb', line 244

def diagnostic
  library.diagnostic
rescue TranscriptionRuntimeError => e
  e.message
end

.duration(path) ⇒ Object



254
255
256
# File 'lib/cohere/transcribe/audio/ffmpeg_native.rb', line 254

def duration(path)
  library.duration(path)
end

.libraryObject



233
234
235
# File 'lib/cohere/transcribe/audio/ffmpeg_native.rb', line 233

def library
  Library.load
end