cohere-transcribe 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/CHANGELOG.md +21 -0
- data/LICENSE.txt +201 -0
- data/NOTICE +5 -0
- data/README.md +265 -0
- data/THIRD_PARTY_NOTICES.md +67 -0
- data/exe/cohere-transcribe +8 -0
- data/exe/cohere-transcribe-doctor +8 -0
- data/ext/cohere_transcribe_native/CMakeLists.txt +262 -0
- data/ext/cohere_transcribe_native/README.md +26 -0
- data/ext/cohere_transcribe_native/audio_abi.cpp +1416 -0
- data/ext/cohere_transcribe_native/audio_exports.macos +5 -0
- data/ext/cohere_transcribe_native/audio_exports.map +10 -0
- data/ext/cohere_transcribe_native/cohere_abi.cpp +1209 -0
- data/ext/cohere_transcribe_native/exports.macos +40 -0
- data/ext/cohere_transcribe_native/exports.map +45 -0
- data/ext/cohere_transcribe_native/extconf.rb +89 -0
- data/ext/cohere_transcribe_native/test/abi_smoke.rb +232 -0
- data/ext/cohere_transcribe_native/test/audio_matrix_smoke.cpp +121 -0
- data/ext/cohere_transcribe_native/test/audio_reliability_smoke.cpp +198 -0
- data/ext/cohere_transcribe_native/test/native_abi_reliability_smoke.cpp +186 -0
- data/ext/cohere_transcribe_native/test/native_batch_projection_probe.rb +81 -0
- data/ext/cohere_transcribe_native/test/native_cancellation_smoke.cpp +194 -0
- data/lib/cohere/transcribe/alignment/ATTRIBUTION.md +23 -0
- data/lib/cohere/transcribe/alignment/LICENSE.ctc-forced-aligner +407 -0
- data/lib/cohere/transcribe/alignment/LICENSE.torchaudio +25 -0
- data/lib/cohere/transcribe/alignment/LICENSE.uroman +26 -0
- data/lib/cohere/transcribe/alignment/aligner.rb +476 -0
- data/lib/cohere/transcribe/alignment/ctc.rb +224 -0
- data/lib/cohere/transcribe/alignment/text.rb +237 -0
- data/lib/cohere/transcribe/alignment/uroman_data.rb +4950 -0
- data/lib/cohere/transcribe/api.rb +173 -0
- data/lib/cohere/transcribe/asr/batching.rb +472 -0
- data/lib/cohere/transcribe/asr/failure_policy.rb +112 -0
- data/lib/cohere/transcribe/asr/native.rb +676 -0
- data/lib/cohere/transcribe/audio/ATTRIBUTION.md +8 -0
- data/lib/cohere/transcribe/audio/LICENSE.auditok +21 -0
- data/lib/cohere/transcribe/audio/decoder.rb +315 -0
- data/lib/cohere/transcribe/audio/ffmpeg_native.rb +248 -0
- data/lib/cohere/transcribe/audio/segmentation.rb +260 -0
- data/lib/cohere/transcribe/cli.rb +727 -0
- data/lib/cohere/transcribe/configuration.rb +282 -0
- data/lib/cohere/transcribe/constants.rb +14 -0
- data/lib/cohere/transcribe/dense_converter.rb +548 -0
- data/lib/cohere/transcribe/doctor.rb +576 -0
- data/lib/cohere/transcribe/errors.rb +57 -0
- data/lib/cohere/transcribe/gguf_writer.rb +268 -0
- data/lib/cohere/transcribe/hub.rb +436 -0
- data/lib/cohere/transcribe/input.rb +110 -0
- data/lib/cohere/transcribe/licenses/crispasr.txt +21 -0
- data/lib/cohere/transcribe/loader.rb +128 -0
- data/lib/cohere/transcribe/model_identity.rb +440 -0
- data/lib/cohere/transcribe/output/publication.rb +1118 -0
- data/lib/cohere/transcribe/output/rendering.rb +105 -0
- data/lib/cohere/transcribe/output/timing.rb +86 -0
- data/lib/cohere/transcribe/python_text.rb +70 -0
- data/lib/cohere/transcribe/pytorch_checkpoint.rb +1180 -0
- data/lib/cohere/transcribe/runtime/engine.rb +1676 -0
- data/lib/cohere/transcribe/runtime/model_provider.rb +390 -0
- data/lib/cohere/transcribe/runtime/precision.rb +57 -0
- data/lib/cohere/transcribe/runtime/preparation.rb +215 -0
- data/lib/cohere/transcribe/runtime/resources.rb +165 -0
- data/lib/cohere/transcribe/runtime/word_pipeline.rb +364 -0
- data/lib/cohere/transcribe/safetensors.rb +579 -0
- data/lib/cohere/transcribe/state/checkpoint.rb +224 -0
- data/lib/cohere/transcribe/state/contracts.rb +141 -0
- data/lib/cohere/transcribe/state/io.rb +727 -0
- data/lib/cohere/transcribe/state/locking.rb +211 -0
- data/lib/cohere/transcribe/state/manifest.rb +155 -0
- data/lib/cohere/transcribe/state.rb +7 -0
- data/lib/cohere/transcribe/types.rb +535 -0
- data/lib/cohere/transcribe/vad/ATTRIBUTION.md +14 -0
- data/lib/cohere/transcribe/vad/LICENSE.faster-whisper +21 -0
- data/lib/cohere/transcribe/vad/LICENSE.silero-vad +21 -0
- data/lib/cohere/transcribe/vad/silero.rb +344 -0
- data/lib/cohere/transcribe/vad/silero_vad_v6.onnx +0 -0
- data/lib/cohere/transcribe/vad/timestamps.rb +219 -0
- data/lib/cohere/transcribe/version.rb +7 -0
- data/lib/cohere/transcribe.rb +26 -0
- data/sig/cohere/transcribe.rbs +250 -0
- data/vendor/crispasr/AUTHORS +510 -0
- data/vendor/crispasr/LICENSE +21 -0
- data/vendor/crispasr/UPSTREAM.md +9 -0
- data/vendor/crispasr/VERSION +1 -0
- data/vendor/crispasr/ggml/AUTHORS +335 -0
- data/vendor/crispasr/ggml/CMakeLists.txt +512 -0
- data/vendor/crispasr/ggml/LICENSE +21 -0
- data/vendor/crispasr/ggml/README.md +49 -0
- data/vendor/crispasr/ggml/cmake/FindNCCL.cmake +36 -0
- data/vendor/crispasr/ggml/cmake/GitVars.cmake +22 -0
- data/vendor/crispasr/ggml/cmake/common.cmake +50 -0
- data/vendor/crispasr/ggml/cmake/ggml-config.cmake.in +191 -0
- data/vendor/crispasr/ggml/ggml.pc.in +10 -0
- data/vendor/crispasr/ggml/include/ggml-alloc.h +85 -0
- data/vendor/crispasr/ggml/include/ggml-backend.h +431 -0
- data/vendor/crispasr/ggml/include/ggml-blas.h +25 -0
- data/vendor/crispasr/ggml/include/ggml-cann.h +123 -0
- data/vendor/crispasr/ggml/include/ggml-cpp.h +39 -0
- data/vendor/crispasr/ggml/include/ggml-cpu.h +151 -0
- data/vendor/crispasr/ggml/include/ggml-cuda.h +50 -0
- data/vendor/crispasr/ggml/include/ggml-hexagon.h +19 -0
- data/vendor/crispasr/ggml/include/ggml-metal.h +61 -0
- data/vendor/crispasr/ggml/include/ggml-opencl.h +26 -0
- data/vendor/crispasr/ggml/include/ggml-openvino.h +37 -0
- data/vendor/crispasr/ggml/include/ggml-opt.h +256 -0
- data/vendor/crispasr/ggml/include/ggml-rpc.h +35 -0
- data/vendor/crispasr/ggml/include/ggml-sycl.h +49 -0
- data/vendor/crispasr/ggml/include/ggml-virtgpu.h +14 -0
- data/vendor/crispasr/ggml/include/ggml-vulkan.h +29 -0
- data/vendor/crispasr/ggml/include/ggml-webgpu.h +19 -0
- data/vendor/crispasr/ggml/include/ggml-zdnn.h +17 -0
- data/vendor/crispasr/ggml/include/ggml-zendnn.h +22 -0
- data/vendor/crispasr/ggml/include/ggml.h +2887 -0
- data/vendor/crispasr/ggml/include/gguf.h +204 -0
- data/vendor/crispasr/ggml/src/CMakeLists.txt +493 -0
- data/vendor/crispasr/ggml/src/ggml-alloc.c +1323 -0
- data/vendor/crispasr/ggml/src/ggml-backend-dl.cpp +48 -0
- data/vendor/crispasr/ggml/src/ggml-backend-dl.h +44 -0
- data/vendor/crispasr/ggml/src/ggml-backend-impl.h +275 -0
- data/vendor/crispasr/ggml/src/ggml-backend-meta.cpp +2145 -0
- data/vendor/crispasr/ggml/src/ggml-backend-reg.cpp +586 -0
- data/vendor/crispasr/ggml/src/ggml-backend.cpp +2437 -0
- data/vendor/crispasr/ggml/src/ggml-common.h +1900 -0
- data/vendor/crispasr/ggml/src/ggml-cpu/CMakeLists.txt +718 -0
- data/vendor/crispasr/ggml/src/ggml-cpu/amx/amx.cpp +249 -0
- data/vendor/crispasr/ggml/src/ggml-cpu/amx/amx.h +8 -0
- data/vendor/crispasr/ggml/src/ggml-cpu/amx/common.h +115 -0
- data/vendor/crispasr/ggml/src/ggml-cpu/amx/mmq.cpp +2512 -0
- data/vendor/crispasr/ggml/src/ggml-cpu/amx/mmq.h +10 -0
- data/vendor/crispasr/ggml/src/ggml-cpu/arch/arm/cpu-feats.cpp +98 -0
- data/vendor/crispasr/ggml/src/ggml-cpu/arch/arm/quants.c +4244 -0
- data/vendor/crispasr/ggml/src/ggml-cpu/arch/arm/repack.cpp +5156 -0
- data/vendor/crispasr/ggml/src/ggml-cpu/arch/loongarch/quants.c +2158 -0
- data/vendor/crispasr/ggml/src/ggml-cpu/arch/powerpc/cpu-feats.cpp +82 -0
- data/vendor/crispasr/ggml/src/ggml-cpu/arch/powerpc/quants.c +2304 -0
- data/vendor/crispasr/ggml/src/ggml-cpu/arch/riscv/cpu-feats.cpp +38 -0
- data/vendor/crispasr/ggml/src/ggml-cpu/arch/riscv/quants.c +4455 -0
- data/vendor/crispasr/ggml/src/ggml-cpu/arch/riscv/repack.cpp +1703 -0
- data/vendor/crispasr/ggml/src/ggml-cpu/arch/s390/cpu-feats.cpp +50 -0
- data/vendor/crispasr/ggml/src/ggml-cpu/arch/s390/quants.c +1465 -0
- data/vendor/crispasr/ggml/src/ggml-cpu/arch/wasm/quants.c +1220 -0
- data/vendor/crispasr/ggml/src/ggml-cpu/arch/x86/cpu-feats.cpp +327 -0
- data/vendor/crispasr/ggml/src/ggml-cpu/arch/x86/quants.c +3970 -0
- data/vendor/crispasr/ggml/src/ggml-cpu/arch/x86/repack.cpp +6407 -0
- data/vendor/crispasr/ggml/src/ggml-cpu/arch-fallback.h +349 -0
- data/vendor/crispasr/ggml/src/ggml-cpu/binary-ops.cpp +154 -0
- data/vendor/crispasr/ggml/src/ggml-cpu/binary-ops.h +16 -0
- data/vendor/crispasr/ggml/src/ggml-cpu/cmake/FindSIMD.cmake +100 -0
- data/vendor/crispasr/ggml/src/ggml-cpu/common.h +95 -0
- data/vendor/crispasr/ggml/src/ggml-cpu/ggml-cpu-impl.h +539 -0
- data/vendor/crispasr/ggml/src/ggml-cpu/ggml-cpu.c +3791 -0
- data/vendor/crispasr/ggml/src/ggml-cpu/ggml-cpu.cpp +703 -0
- data/vendor/crispasr/ggml/src/ggml-cpu/hbm.cpp +55 -0
- data/vendor/crispasr/ggml/src/ggml-cpu/hbm.h +8 -0
- data/vendor/crispasr/ggml/src/ggml-cpu/kleidiai/kernels.cpp +939 -0
- data/vendor/crispasr/ggml/src/ggml-cpu/kleidiai/kernels.h +90 -0
- data/vendor/crispasr/ggml/src/ggml-cpu/kleidiai/kleidiai.cpp +1513 -0
- data/vendor/crispasr/ggml/src/ggml-cpu/kleidiai/kleidiai.h +17 -0
- data/vendor/crispasr/ggml/src/ggml-cpu/llamafile/sgemm.cpp +4051 -0
- data/vendor/crispasr/ggml/src/ggml-cpu/llamafile/sgemm.h +25 -0
- data/vendor/crispasr/ggml/src/ggml-cpu/ops.cpp +11662 -0
- data/vendor/crispasr/ggml/src/ggml-cpu/ops.h +121 -0
- data/vendor/crispasr/ggml/src/ggml-cpu/quants.c +1288 -0
- data/vendor/crispasr/ggml/src/ggml-cpu/quants.h +103 -0
- data/vendor/crispasr/ggml/src/ggml-cpu/repack.cpp +4836 -0
- data/vendor/crispasr/ggml/src/ggml-cpu/repack.h +245 -0
- data/vendor/crispasr/ggml/src/ggml-cpu/simd-gemm.h +226 -0
- data/vendor/crispasr/ggml/src/ggml-cpu/simd-mappings.h +1329 -0
- data/vendor/crispasr/ggml/src/ggml-cpu/spacemit/ime.cpp +1025 -0
- data/vendor/crispasr/ggml/src/ggml-cpu/spacemit/ime.h +13 -0
- data/vendor/crispasr/ggml/src/ggml-cpu/spacemit/ime1_kernels.cpp +3196 -0
- data/vendor/crispasr/ggml/src/ggml-cpu/spacemit/ime_kernels.h +26 -0
- data/vendor/crispasr/ggml/src/ggml-cpu/traits.cpp +36 -0
- data/vendor/crispasr/ggml/src/ggml-cpu/traits.h +38 -0
- data/vendor/crispasr/ggml/src/ggml-cpu/unary-ops.cpp +336 -0
- data/vendor/crispasr/ggml/src/ggml-cpu/unary-ops.h +35 -0
- data/vendor/crispasr/ggml/src/ggml-cpu/vec.cpp +681 -0
- data/vendor/crispasr/ggml/src/ggml-cpu/vec.h +1606 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/CMakeLists.txt +272 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/acc.cu +61 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/acc.cuh +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/add-id.cu +58 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/add-id.cuh +3 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/arange.cu +34 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/arange.cuh +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/argmax.cu +91 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/argmax.cuh +3 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/argsort.cu +265 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/argsort.cuh +19 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/binbcast.cu +534 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/binbcast.cuh +12 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/clamp.cu +45 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/clamp.cuh +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/col2im-1d.cu +81 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/col2im-1d.cuh +3 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/common.cuh +1489 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/concat.cu +204 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/concat.cuh +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/conv-transpose-1d.cu +97 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/conv-transpose-1d.cuh +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/conv2d-dw.cu +161 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/conv2d-dw.cuh +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/conv2d-transpose.cu +115 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/conv2d-transpose.cuh +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/conv2d.cu +166 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/conv2d.cuh +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/convert.cu +892 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/convert.cuh +66 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/count-equal.cu +64 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/count-equal.cuh +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/cp-async.cuh +57 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/cpy-utils.cuh +217 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/cpy.cu +581 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/cpy.cuh +7 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/cross-entropy-loss.cu +177 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/cross-entropy-loss.cuh +7 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/cumsum.cu +307 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/cumsum.cuh +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/dequantize.cuh +99 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/diag.cu +77 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/diag.cuh +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/diagmask.cu +40 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/diagmask.cuh +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/fattn-common.cuh +1212 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/fattn-mma-f16.cuh +1860 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/fattn-tile.cu +57 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/fattn-tile.cuh +1309 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/fattn-vec.cuh +600 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/fattn-wmma-f16.cu +696 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/fattn-wmma-f16.cuh +51 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/fattn.cu +620 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/fattn.cuh +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/fill.cu +37 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/fill.cuh +3 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/gated_delta_net.cu +273 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/gated_delta_net.cuh +4 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/getrows.cu +332 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/getrows.cuh +15 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/ggml-cuda.cu +5580 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/gla.cu +93 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/gla.cuh +3 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/im2col.cu +274 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/im2col.cuh +6 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/mean.cu +75 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/mean.cuh +3 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/mma.cuh +1333 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/mmf.cu +191 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/mmf.cuh +908 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/mmid.cu +164 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/mmid.cuh +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/mmq.cu +372 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/mmq.cuh +4175 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/mmvf.cu +862 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/mmvf.cuh +14 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/mmvq.cu +1161 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/mmvq.cuh +16 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/norm.cu +756 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/norm.cuh +20 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/opt-step-adamw.cu +78 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/opt-step-adamw.cuh +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/opt-step-sgd.cu +49 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/opt-step-sgd.cuh +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/out-prod.cu +68 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/out-prod.cuh +3 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/pad.cu +106 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/pad.cuh +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/pad_reflect_1d.cu +91 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/pad_reflect_1d.cuh +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/pool2d.cu +94 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/pool2d.cuh +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/quantize.cu +443 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/quantize.cuh +41 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/reduce_rows.cuh +39 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/roll.cu +67 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/roll.cuh +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/rope.cu +665 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/rope.cuh +9 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/scale.cu +34 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/scale.cuh +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/set-rows.cu +330 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/set-rows.cuh +7 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/set.cu +39 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/set.cuh +7 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/softcap.cu +34 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/softcap.cuh +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/softmax.cu +472 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/softmax.cuh +7 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/solve_tri.cu +275 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/solve_tri.cuh +3 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/ssm-conv.cu +197 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/ssm-conv.cuh +3 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/ssm-scan.cu +342 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/ssm-scan.cuh +3 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/sum.cu +41 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/sum.cuh +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/sumrows.cu +43 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/sumrows.cuh +4 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-mma-f16-instance-ncols1_1-ncols2_16.cu +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-mma-f16-instance-ncols1_1-ncols2_32.cu +6 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-mma-f16-instance-ncols1_1-ncols2_8.cu +11 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-mma-f16-instance-ncols1_16-ncols2_1.cu +10 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-mma-f16-instance-ncols1_16-ncols2_2.cu +10 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-mma-f16-instance-ncols1_16-ncols2_4.cu +12 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-mma-f16-instance-ncols1_2-ncols2_16.cu +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-mma-f16-instance-ncols1_2-ncols2_32.cu +6 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-mma-f16-instance-ncols1_2-ncols2_4.cu +12 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-mma-f16-instance-ncols1_2-ncols2_8.cu +11 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-mma-f16-instance-ncols1_32-ncols2_1.cu +10 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-mma-f16-instance-ncols1_32-ncols2_2.cu +10 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-mma-f16-instance-ncols1_4-ncols2_16.cu +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-mma-f16-instance-ncols1_4-ncols2_2.cu +10 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-mma-f16-instance-ncols1_4-ncols2_4.cu +12 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-mma-f16-instance-ncols1_4-ncols2_8.cu +11 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-mma-f16-instance-ncols1_64-ncols2_1.cu +10 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-mma-f16-instance-ncols1_8-ncols2_1.cu +10 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-mma-f16-instance-ncols1_8-ncols2_2.cu +10 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-mma-f16-instance-ncols1_8-ncols2_4.cu +12 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-mma-f16-instance-ncols1_8-ncols2_8.cu +11 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-tile-instance-dkq112-dv112.cu +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-tile-instance-dkq128-dv128.cu +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-tile-instance-dkq256-dv256.cu +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-tile-instance-dkq320-dv256.cu +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-tile-instance-dkq40-dv40.cu +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-tile-instance-dkq512-dv512.cu +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-tile-instance-dkq576-dv512.cu +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-tile-instance-dkq64-dv64.cu +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-tile-instance-dkq72-dv72.cu +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-tile-instance-dkq80-dv80.cu +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-tile-instance-dkq96-dv96.cu +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-bf16-bf16.cu +7 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-bf16-f16.cu +7 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-bf16-q4_0.cu +7 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-bf16-q4_1.cu +7 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-bf16-q5_0.cu +7 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-bf16-q5_1.cu +7 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-bf16-q8_0.cu +7 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-f16-bf16.cu +7 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-f16-f16.cu +7 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-f16-q4_0.cu +7 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-f16-q4_1.cu +7 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-f16-q5_0.cu +7 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-f16-q5_1.cu +7 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-f16-q8_0.cu +7 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q4_0-bf16.cu +7 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q4_0-f16.cu +7 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q4_0-q4_0.cu +7 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q4_0-q4_1.cu +7 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q4_0-q5_0.cu +7 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q4_0-q5_1.cu +7 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q4_0-q8_0.cu +7 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q4_1-bf16.cu +7 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q4_1-f16.cu +7 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q4_1-q4_0.cu +7 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q4_1-q4_1.cu +7 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q4_1-q5_0.cu +7 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q4_1-q5_1.cu +7 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q4_1-q8_0.cu +7 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q5_0-bf16.cu +7 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q5_0-f16.cu +7 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q5_0-q4_0.cu +7 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q5_0-q4_1.cu +7 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q5_0-q5_0.cu +7 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q5_0-q5_1.cu +7 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q5_0-q8_0.cu +7 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q5_1-bf16.cu +7 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q5_1-f16.cu +7 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q5_1-q4_0.cu +7 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q5_1-q4_1.cu +7 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q5_1-q5_0.cu +7 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q5_1-q5_1.cu +7 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q5_1-q8_0.cu +7 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q8_0-bf16.cu +7 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q8_0-f16.cu +7 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q8_0-q4_0.cu +7 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q8_0-q4_1.cu +7 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q8_0-q5_0.cu +7 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q8_0-q5_1.cu +7 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q8_0-q8_0.cu +7 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/mmf-instance-ncols_1.cu +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/mmf-instance-ncols_10.cu +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/mmf-instance-ncols_11.cu +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/mmf-instance-ncols_12.cu +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/mmf-instance-ncols_13.cu +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/mmf-instance-ncols_14.cu +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/mmf-instance-ncols_15.cu +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/mmf-instance-ncols_16.cu +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/mmf-instance-ncols_2.cu +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/mmf-instance-ncols_3.cu +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/mmf-instance-ncols_4.cu +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/mmf-instance-ncols_5.cu +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/mmf-instance-ncols_6.cu +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/mmf-instance-ncols_7.cu +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/mmf-instance-ncols_8.cu +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/mmf-instance-ncols_9.cu +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/mmq-instance-iq1_s.cu +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/mmq-instance-iq2_s.cu +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/mmq-instance-iq2_xs.cu +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/mmq-instance-iq2_xxs.cu +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/mmq-instance-iq3_s.cu +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/mmq-instance-iq3_xxs.cu +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/mmq-instance-iq4_nl.cu +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/mmq-instance-iq4_xs.cu +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/mmq-instance-mxfp4.cu +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/mmq-instance-nvfp4.cu +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/mmq-instance-q1_0.cu +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/mmq-instance-q2_k.cu +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/mmq-instance-q3_k.cu +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/mmq-instance-q4_0.cu +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/mmq-instance-q4_1.cu +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/mmq-instance-q4_k.cu +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/mmq-instance-q5_0.cu +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/mmq-instance-q5_1.cu +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/mmq-instance-q5_k.cu +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/mmq-instance-q6_k.cu +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/mmq-instance-q8_0.cu +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/top-k.cu +95 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/top-k.cuh +3 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/topk-moe.cu +415 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/topk-moe.cuh +27 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/tri.cu +136 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/tri.cuh +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/tsembd.cu +47 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/tsembd.cuh +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/unary.cu +644 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/unary.cuh +116 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/upscale.cu +293 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/upscale.cuh +5 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/vecdotq.cuh +1317 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/vendors/cuda.h +28 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/vendors/hip.h +306 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/vendors/musa.h +148 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/wkv.cu +199 -0
- data/vendor/crispasr/ggml/src/ggml-cuda/wkv.cuh +7 -0
- data/vendor/crispasr/ggml/src/ggml-impl.h +783 -0
- data/vendor/crispasr/ggml/src/ggml-metal/CMakeLists.txt +124 -0
- data/vendor/crispasr/ggml/src/ggml-metal/ggml-metal-common.cpp +457 -0
- data/vendor/crispasr/ggml/src/ggml-metal/ggml-metal-common.h +52 -0
- data/vendor/crispasr/ggml/src/ggml-metal/ggml-metal-context.h +41 -0
- data/vendor/crispasr/ggml/src/ggml-metal/ggml-metal-context.m +778 -0
- data/vendor/crispasr/ggml/src/ggml-metal/ggml-metal-device.cpp +2117 -0
- data/vendor/crispasr/ggml/src/ggml-metal/ggml-metal-device.h +299 -0
- data/vendor/crispasr/ggml/src/ggml-metal/ggml-metal-device.m +2093 -0
- data/vendor/crispasr/ggml/src/ggml-metal/ggml-metal-impl.h +1267 -0
- data/vendor/crispasr/ggml/src/ggml-metal/ggml-metal-ops.cpp +5023 -0
- data/vendor/crispasr/ggml/src/ggml-metal/ggml-metal-ops.h +111 -0
- data/vendor/crispasr/ggml/src/ggml-metal/ggml-metal.cpp +954 -0
- data/vendor/crispasr/ggml/src/ggml-metal/ggml-metal.metal +11756 -0
- data/vendor/crispasr/ggml/src/ggml-opt.cpp +1094 -0
- data/vendor/crispasr/ggml/src/ggml-quants.c +5491 -0
- data/vendor/crispasr/ggml/src/ggml-quants.h +112 -0
- data/vendor/crispasr/ggml/src/ggml-threading.cpp +12 -0
- data/vendor/crispasr/ggml/src/ggml-threading.h +14 -0
- data/vendor/crispasr/ggml/src/ggml.c +7925 -0
- data/vendor/crispasr/ggml/src/ggml.cpp +26 -0
- data/vendor/crispasr/ggml/src/gguf.cpp +1556 -0
- data/vendor/crispasr/src/cohere-arch.h +137 -0
- data/vendor/crispasr/src/cohere.cpp +5642 -0
- data/vendor/crispasr/src/cohere.h +327 -0
- data/vendor/crispasr/src/cohere_batch_planner.h +82 -0
- data/vendor/crispasr/src/cohere_chunking.h +64 -0
- data/vendor/crispasr/src/cohere_decoder_batch_layout.h +60 -0
- data/vendor/crispasr/src/cohere_encoder_padded_layout.h +27 -0
- data/vendor/crispasr/src/cohere_frontend.cpp +189 -0
- data/vendor/crispasr/src/cohere_frontend.h +31 -0
- data/vendor/crispasr/src/cohere_ragged_controller.h +149 -0
- data/vendor/crispasr/src/cohere_token_renderer.h +181 -0
- data/vendor/crispasr/src/core/attention.h +924 -0
- data/vendor/crispasr/src/core/audio_chunking.h +97 -0
- data/vendor/crispasr/src/core/beam_decode.h +486 -0
- data/vendor/crispasr/src/core/cpu_ops.h +135 -0
- data/vendor/crispasr/src/core/gguf_loader.cpp +1021 -0
- data/vendor/crispasr/src/core/gguf_loader.h +216 -0
- data/vendor/crispasr/src/core/gpu_backend_pref.h +119 -0
- data/vendor/crispasr/src/core/mel.cpp +519 -0
- data/vendor/crispasr/src/core/mel.h +265 -0
- data/vendor/crispasr/src/core/ngram_loop_fix.h +173 -0
- data/vendor/crispasr/src/core/repetition_loop_guard.h +54 -0
- data/vendor/crispasr/src/crispasr_imatrix.cpp +255 -0
- data/vendor/crispasr/src/crispasr_imatrix.h +38 -0
- metadata +596 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2015-2026 Mohamed El Amine SEHILI
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,315 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "fiddle/import"
|
|
4
|
+
require "rbconfig"
|
|
5
|
+
|
|
6
|
+
require_relative "../constants"
|
|
7
|
+
require_relative "../errors"
|
|
8
|
+
require_relative "ffmpeg_native"
|
|
9
|
+
|
|
10
|
+
module Cohere
|
|
11
|
+
module Transcribe
|
|
12
|
+
module Audio
|
|
13
|
+
Decoded = Data.define(:samples, :sample_rate, :backend, :fallback_reason)
|
|
14
|
+
|
|
15
|
+
module SharedLibraryCandidates
|
|
16
|
+
module_function
|
|
17
|
+
|
|
18
|
+
def build(environment_key, names, formula:, host_os: RbConfig::CONFIG.fetch("host_os"))
|
|
19
|
+
candidates = [ENV.fetch(environment_key, nil), *names].compact
|
|
20
|
+
return candidates.uniq unless host_os.match?(/darwin/)
|
|
21
|
+
|
|
22
|
+
directories = []
|
|
23
|
+
homebrew_prefix = ENV.fetch("HOMEBREW_PREFIX", nil)
|
|
24
|
+
directories << File.join(homebrew_prefix, "opt", formula, "lib") if homebrew_prefix && !homebrew_prefix.empty?
|
|
25
|
+
directories.push(
|
|
26
|
+
"/opt/homebrew/opt/#{formula}/lib",
|
|
27
|
+
"/usr/local/opt/#{formula}/lib",
|
|
28
|
+
"/opt/homebrew/lib",
|
|
29
|
+
"/usr/local/lib",
|
|
30
|
+
"/opt/local/lib"
|
|
31
|
+
)
|
|
32
|
+
candidates.concat(directories.product(names).map { |directory, name| File.join(directory, name) })
|
|
33
|
+
candidates.uniq
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
private_constant :SharedLibraryCandidates
|
|
37
|
+
|
|
38
|
+
module SoundFileABI
|
|
39
|
+
extend Fiddle::Importer
|
|
40
|
+
|
|
41
|
+
begin
|
|
42
|
+
candidates = SharedLibraryCandidates.build(
|
|
43
|
+
"COHERE_TRANSCRIBE_SNDFILE_LIBRARY",
|
|
44
|
+
%w[libsndfile.so.1 libsndfile.so libsndfile.1.dylib libsndfile.dylib],
|
|
45
|
+
formula: "libsndfile"
|
|
46
|
+
)
|
|
47
|
+
library = candidates.find do |candidate|
|
|
48
|
+
Fiddle.dlopen(candidate)
|
|
49
|
+
true
|
|
50
|
+
rescue Fiddle::DLError
|
|
51
|
+
false
|
|
52
|
+
end
|
|
53
|
+
raise Fiddle::DLError, "libsndfile was not found" unless library
|
|
54
|
+
|
|
55
|
+
dlload library
|
|
56
|
+
SFInfo = struct([
|
|
57
|
+
"long long frames",
|
|
58
|
+
"int samplerate",
|
|
59
|
+
"int channels",
|
|
60
|
+
"int format",
|
|
61
|
+
"int sections",
|
|
62
|
+
"int seekable"
|
|
63
|
+
])
|
|
64
|
+
extern "void* sf_open(const char*, int, void*)"
|
|
65
|
+
extern "long long sf_readf_float(void*, void*, long long)"
|
|
66
|
+
extern "int sf_close(void*)"
|
|
67
|
+
extern "const char* sf_strerror(void*)"
|
|
68
|
+
AVAILABLE = true
|
|
69
|
+
rescue Fiddle::DLError => e
|
|
70
|
+
LOAD_ERROR = e
|
|
71
|
+
AVAILABLE = false
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
private_constant :SoundFileABI
|
|
75
|
+
|
|
76
|
+
module SampleRateABI
|
|
77
|
+
extend Fiddle::Importer
|
|
78
|
+
|
|
79
|
+
begin
|
|
80
|
+
candidates = SharedLibraryCandidates.build(
|
|
81
|
+
"COHERE_TRANSCRIBE_SAMPLERATE_LIBRARY",
|
|
82
|
+
%w[libsamplerate.so.0 libsamplerate.so libsamplerate.0.dylib libsamplerate.dylib],
|
|
83
|
+
formula: "libsamplerate"
|
|
84
|
+
)
|
|
85
|
+
library = candidates.find do |candidate|
|
|
86
|
+
Fiddle.dlopen(candidate)
|
|
87
|
+
true
|
|
88
|
+
rescue Fiddle::DLError
|
|
89
|
+
false
|
|
90
|
+
end
|
|
91
|
+
raise Fiddle::DLError, "libsamplerate was not found" unless library
|
|
92
|
+
|
|
93
|
+
dlload library
|
|
94
|
+
SRCData = struct([
|
|
95
|
+
"void* data_in",
|
|
96
|
+
"void* data_out",
|
|
97
|
+
"long input_frames",
|
|
98
|
+
"long output_frames",
|
|
99
|
+
"long input_frames_used",
|
|
100
|
+
"long output_frames_gen",
|
|
101
|
+
"int end_of_input",
|
|
102
|
+
"double src_ratio"
|
|
103
|
+
])
|
|
104
|
+
extern "int src_simple(void*, int, int)"
|
|
105
|
+
extern "const char* src_strerror(int)"
|
|
106
|
+
AVAILABLE = true
|
|
107
|
+
rescue Fiddle::DLError => e
|
|
108
|
+
LOAD_ERROR = e
|
|
109
|
+
AVAILABLE = false
|
|
110
|
+
end
|
|
111
|
+
end
|
|
112
|
+
private_constant :SampleRateABI
|
|
113
|
+
|
|
114
|
+
module Decoder
|
|
115
|
+
module_function
|
|
116
|
+
|
|
117
|
+
SFM_READ = 0x10
|
|
118
|
+
SRC_SINC_FASTEST = 2
|
|
119
|
+
BACKENDS = %w[auto ffmpeg torchcodec librosa libsndfile].freeze
|
|
120
|
+
|
|
121
|
+
# Best-effort metadata probe used for public skipped-result parity. It
|
|
122
|
+
# may inspect container headers and demuxer probe packets but never
|
|
123
|
+
# launches ffprobe or materializes decoded PCM in Ruby.
|
|
124
|
+
def probe_duration(path)
|
|
125
|
+
source = Pathname(path).expand_path
|
|
126
|
+
return nil unless source.file?
|
|
127
|
+
|
|
128
|
+
if FFmpegNative.available?
|
|
129
|
+
duration = FFmpegNative.duration(source)
|
|
130
|
+
return duration if duration
|
|
131
|
+
end
|
|
132
|
+
return nil unless SoundFileABI::AVAILABLE
|
|
133
|
+
|
|
134
|
+
info = SoundFileABI::SFInfo.malloc
|
|
135
|
+
handle = SoundFileABI.sf_open(source.to_s, SFM_READ, info.to_ptr)
|
|
136
|
+
return nil if handle.null?
|
|
137
|
+
|
|
138
|
+
frames = Integer(info.frames)
|
|
139
|
+
sample_rate = Integer(info.samplerate)
|
|
140
|
+
return nil unless frames >= 0 && sample_rate.positive?
|
|
141
|
+
|
|
142
|
+
seconds = frames.fdiv(sample_rate)
|
|
143
|
+
seconds if seconds.finite? && seconds >= 0.0
|
|
144
|
+
rescue Fiddle::DLError, SystemCallError, TranscriptionRuntimeError
|
|
145
|
+
nil
|
|
146
|
+
ensure
|
|
147
|
+
SoundFileABI.sf_close(handle) if defined?(handle) && handle && !handle.null?
|
|
148
|
+
end
|
|
149
|
+
|
|
150
|
+
def decode(path, backend: "auto", sample_rate: SAMPLE_RATE, max_decoded_bytes: 4 * (1024**3))
|
|
151
|
+
requested = backend
|
|
152
|
+
unless requested.is_a?(String) && BACKENDS.include?(requested)
|
|
153
|
+
raise ArgumentError, "Unsupported audio backend: #{backend.inspect}"
|
|
154
|
+
end
|
|
155
|
+
raise ArgumentError, "sample_rate must be a positive integer" unless sample_rate.is_a?(Integer) && sample_rate.positive?
|
|
156
|
+
unless max_decoded_bytes.nil? || (max_decoded_bytes.is_a?(Integer) && max_decoded_bytes.positive?)
|
|
157
|
+
raise ArgumentError, "max_decoded_bytes must be a positive integer or nil"
|
|
158
|
+
end
|
|
159
|
+
|
|
160
|
+
source = Pathname(path).expand_path
|
|
161
|
+
raise TranscriptionInputError, "Input does not exist: #{source}" unless source.exist?
|
|
162
|
+
raise TranscriptionInputError, "Input is not a regular file: #{source}" unless source.file?
|
|
163
|
+
|
|
164
|
+
native_ffmpeg_available = %w[auto librosa].include?(requested) && FFmpegNative.available?
|
|
165
|
+
use_ffmpeg = requested == "ffmpeg" || requested == "torchcodec" ||
|
|
166
|
+
(%w[auto librosa].include?(requested) && native_ffmpeg_available)
|
|
167
|
+
if use_ffmpeg
|
|
168
|
+
samples = FFmpegNative.decode(
|
|
169
|
+
source,
|
|
170
|
+
sample_rate: sample_rate,
|
|
171
|
+
max_decoded_bytes: max_decoded_bytes
|
|
172
|
+
)
|
|
173
|
+
validate_finite!(samples)
|
|
174
|
+
return Decoded.new(
|
|
175
|
+
samples: samples.freeze,
|
|
176
|
+
sample_rate: sample_rate,
|
|
177
|
+
backend: "ffmpeg",
|
|
178
|
+
fallback_reason: if %w[torchcodec librosa].include?(requested)
|
|
179
|
+
"Ruby #{requested} compatibility mode uses FFmpeg through the native C ABI"
|
|
180
|
+
end
|
|
181
|
+
)
|
|
182
|
+
end
|
|
183
|
+
|
|
184
|
+
unless SoundFileABI::AVAILABLE
|
|
185
|
+
sound_file_error = if SoundFileABI.const_defined?(:LOAD_ERROR, false)
|
|
186
|
+
SoundFileABI::LOAD_ERROR.message
|
|
187
|
+
else
|
|
188
|
+
"not found"
|
|
189
|
+
end
|
|
190
|
+
if requested == "auto"
|
|
191
|
+
raise TranscriptionRuntimeError,
|
|
192
|
+
"Automatic audio decoding requires the native FFmpeg adapter or libsndfile " \
|
|
193
|
+
"(FFmpeg: #{FFmpegNative.diagnostic}; libsndfile: #{sound_file_error})"
|
|
194
|
+
end
|
|
195
|
+
raise TranscriptionRuntimeError, "libsndfile is required for native audio decoding: #{sound_file_error}"
|
|
196
|
+
end
|
|
197
|
+
|
|
198
|
+
info = SoundFileABI::SFInfo.malloc
|
|
199
|
+
handle = SoundFileABI.sf_open(source.to_s, SFM_READ, info.to_ptr)
|
|
200
|
+
raise TranscriptionRuntimeError, "Cannot decode #{source}: #{SoundFileABI.sf_strerror(handle)}" if handle.null?
|
|
201
|
+
|
|
202
|
+
begin
|
|
203
|
+
frames = Integer(info.frames)
|
|
204
|
+
channels = Integer(info.channels)
|
|
205
|
+
source_rate = Integer(info.samplerate)
|
|
206
|
+
unless frames >= 0 && channels.positive? && source_rate.positive?
|
|
207
|
+
raise TranscriptionRuntimeError, "Decoder returned invalid audio metadata for #{source}"
|
|
208
|
+
end
|
|
209
|
+
|
|
210
|
+
input_bytes = frames * channels * Fiddle::SIZEOF_FLOAT
|
|
211
|
+
output_frames = (frames * sample_rate.fdiv(source_rate)).ceil + 64
|
|
212
|
+
projected_bytes = [input_bytes, output_frames * Fiddle::SIZEOF_FLOAT].max
|
|
213
|
+
if max_decoded_bytes && projected_bytes > max_decoded_bytes
|
|
214
|
+
raise TranscriptionRuntimeError,
|
|
215
|
+
"Decoded audio exceeds the configured memory limit for #{source} " \
|
|
216
|
+
"(#{projected_bytes} > #{max_decoded_bytes} bytes)"
|
|
217
|
+
end
|
|
218
|
+
|
|
219
|
+
raw = Fiddle::Pointer.malloc([input_bytes, 1].max, Fiddle::RUBY_FREE)
|
|
220
|
+
read_frames = SoundFileABI.sf_readf_float(handle, raw, frames)
|
|
221
|
+
raise TranscriptionRuntimeError, "Cannot decode #{source}: #{SoundFileABI.sf_strerror(handle)}" if read_frames.negative?
|
|
222
|
+
raise TranscriptionRuntimeError, "Decoder returned more frames than allocated for #{source}" if read_frames > frames
|
|
223
|
+
|
|
224
|
+
frames = read_frames
|
|
225
|
+
begin
|
|
226
|
+
require "numo/narray"
|
|
227
|
+
rescue LoadError => e
|
|
228
|
+
raise TranscriptionRuntimeError, "numo-narray is required for decoded audio: #{e.message}"
|
|
229
|
+
end
|
|
230
|
+
interleaved = if frames.zero?
|
|
231
|
+
nil
|
|
232
|
+
else
|
|
233
|
+
Numo::SFloat.from_binary(raw[0, frames * channels * Fiddle::SIZEOF_FLOAT])
|
|
234
|
+
end
|
|
235
|
+
mono = if frames.zero?
|
|
236
|
+
Numo::SFloat.zeros(0)
|
|
237
|
+
elsif channels == 1
|
|
238
|
+
interleaved
|
|
239
|
+
else
|
|
240
|
+
interleaved.reshape(frames, channels).mean(1).cast_to(Numo::SFloat)
|
|
241
|
+
end
|
|
242
|
+
samples = source_rate == sample_rate ? mono : resample(mono, source_rate, sample_rate, max_decoded_bytes)
|
|
243
|
+
validate_finite!(samples)
|
|
244
|
+
Decoded.new(
|
|
245
|
+
samples: samples.freeze,
|
|
246
|
+
sample_rate: sample_rate,
|
|
247
|
+
backend: "libsndfile",
|
|
248
|
+
fallback_reason: if %w[auto libsndfile].include?(requested)
|
|
249
|
+
nil
|
|
250
|
+
else
|
|
251
|
+
"Ruby #{requested} compatibility mode uses the native libsndfile ABI"
|
|
252
|
+
end
|
|
253
|
+
)
|
|
254
|
+
ensure
|
|
255
|
+
SoundFileABI.sf_close(handle)
|
|
256
|
+
end
|
|
257
|
+
end
|
|
258
|
+
|
|
259
|
+
def resample(samples, source_rate, target_rate, max_decoded_bytes)
|
|
260
|
+
unless source_rate.is_a?(Integer) && source_rate.positive? &&
|
|
261
|
+
target_rate.is_a?(Integer) && target_rate.positive?
|
|
262
|
+
raise ArgumentError, "source_rate and target_rate must be positive integers"
|
|
263
|
+
end
|
|
264
|
+
return Numo::SFloat.zeros(0) if samples.empty?
|
|
265
|
+
|
|
266
|
+
unless SampleRateABI::AVAILABLE
|
|
267
|
+
error = SampleRateABI.const_defined?(:LOAD_ERROR, false) ? SampleRateABI::LOAD_ERROR.message : "not found"
|
|
268
|
+
raise TranscriptionRuntimeError, "libsamplerate is required to resample audio: #{error}"
|
|
269
|
+
end
|
|
270
|
+
ratio = target_rate.fdiv(source_rate)
|
|
271
|
+
output_capacity = (samples.length * ratio).ceil + 64
|
|
272
|
+
bytes = output_capacity * Fiddle::SIZEOF_FLOAT
|
|
273
|
+
if max_decoded_bytes && bytes > max_decoded_bytes
|
|
274
|
+
raise TranscriptionRuntimeError, "Resampled audio exceeds the configured memory limit"
|
|
275
|
+
end
|
|
276
|
+
|
|
277
|
+
input_string = samples.to_binary
|
|
278
|
+
input_pointer = Fiddle::Pointer[input_string]
|
|
279
|
+
output_pointer = Fiddle::Pointer.malloc([bytes, 1].max, Fiddle::RUBY_FREE)
|
|
280
|
+
data = SampleRateABI::SRCData.malloc
|
|
281
|
+
data.data_in = input_pointer
|
|
282
|
+
data.data_out = output_pointer
|
|
283
|
+
data.input_frames = samples.length
|
|
284
|
+
data.output_frames = output_capacity
|
|
285
|
+
data.input_frames_used = 0
|
|
286
|
+
data.output_frames_gen = 0
|
|
287
|
+
data.end_of_input = 1
|
|
288
|
+
data.src_ratio = ratio
|
|
289
|
+
error_code = SampleRateABI.src_simple(data.to_ptr, SRC_SINC_FASTEST, 1)
|
|
290
|
+
raise TranscriptionRuntimeError, "Audio resampling failed: #{SampleRateABI.src_strerror(error_code)}" unless error_code.zero?
|
|
291
|
+
|
|
292
|
+
generated = Integer(data.output_frames_gen)
|
|
293
|
+
consumed = Integer(data.input_frames_used)
|
|
294
|
+
unless consumed == samples.length && generated.between?(0, output_capacity)
|
|
295
|
+
raise TranscriptionRuntimeError,
|
|
296
|
+
"Audio resampling returned invalid frame counts " \
|
|
297
|
+
"(consumed #{consumed}/#{samples.length}, generated #{generated}/#{output_capacity})"
|
|
298
|
+
end
|
|
299
|
+
Numo::SFloat.from_binary(output_pointer[0, generated * Fiddle::SIZEOF_FLOAT])
|
|
300
|
+
end
|
|
301
|
+
|
|
302
|
+
def validate_finite!(samples)
|
|
303
|
+
return samples if samples.empty?
|
|
304
|
+
|
|
305
|
+
(0...samples.length).step(1_048_576) do |offset|
|
|
306
|
+
finish = [offset + 1_048_576, samples.length].min
|
|
307
|
+
raise TranscriptionRuntimeError, "Decoded audio contains NaN or infinite samples" unless samples[offset...finish].isfinite.all?
|
|
308
|
+
end
|
|
309
|
+
samples
|
|
310
|
+
end
|
|
311
|
+
private_class_method :validate_finite!
|
|
312
|
+
end
|
|
313
|
+
end
|
|
314
|
+
end
|
|
315
|
+
end
|
|
@@ -0,0 +1,248 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "fiddle"
|
|
4
|
+
require "rbconfig"
|
|
5
|
+
|
|
6
|
+
require_relative "../errors"
|
|
7
|
+
|
|
8
|
+
module Cohere
|
|
9
|
+
module Transcribe
|
|
10
|
+
module Audio
|
|
11
|
+
# Lazy binding for the gem's subprocess-free libav decoder adapter. The
|
|
12
|
+
# adapter itself dynamically selects a compatible FFmpeg 4-8 runtime;
|
|
13
|
+
# Ruby never launches ffmpeg and does not retain a Python codec runtime.
|
|
14
|
+
module FFmpegNative
|
|
15
|
+
ERROR_CAPACITY = 1_024
|
|
16
|
+
CANCELLED_STATUS = 6
|
|
17
|
+
|
|
18
|
+
class Library
|
|
19
|
+
FUNCTIONS = {
|
|
20
|
+
probe: [%i[voidp size_t], :int],
|
|
21
|
+
decode: [%i[voidp int uint64 voidp voidp voidp size_t], :int],
|
|
22
|
+
duration: [%i[voidp voidp voidp size_t], :int],
|
|
23
|
+
cancel: [[], :void],
|
|
24
|
+
free: [[:voidp], :void]
|
|
25
|
+
}.freeze
|
|
26
|
+
|
|
27
|
+
TYPE_MAP = {
|
|
28
|
+
void: Fiddle::TYPE_VOID,
|
|
29
|
+
voidp: Fiddle::TYPE_VOIDP,
|
|
30
|
+
int: Fiddle::TYPE_INT,
|
|
31
|
+
size_t: Fiddle::TYPE_SIZE_T,
|
|
32
|
+
uint64: Fiddle::TYPE_UINT64_T
|
|
33
|
+
}.freeze
|
|
34
|
+
|
|
35
|
+
class << self
|
|
36
|
+
def load
|
|
37
|
+
@mutex ||= Mutex.new
|
|
38
|
+
@mutex.synchronize { @instance ||= load_uncached }
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def loaded
|
|
42
|
+
mutex = @mutex
|
|
43
|
+
mutex&.synchronize { @instance }
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def candidate_paths
|
|
47
|
+
explicit = ENV.fetch("COHERE_TRANSCRIBE_AUDIO_LIBRARY", nil)
|
|
48
|
+
return [explicit] if explicit && !explicit.empty?
|
|
49
|
+
|
|
50
|
+
packaged = File.expand_path("../native", __dir__)
|
|
51
|
+
patterns = case RbConfig::CONFIG.fetch("host_os")
|
|
52
|
+
when /darwin/ then ["libcohere_audio*.dylib"]
|
|
53
|
+
when /mswin|mingw|cygwin/ then ["cohere_audio*.dll", "libcohere_audio*.dll"]
|
|
54
|
+
else ["libcohere_audio.so", "libcohere_audio.so.*"]
|
|
55
|
+
end
|
|
56
|
+
paths = patterns.flat_map { |pattern| Dir.glob(File.join(packaged, pattern)) }.sort
|
|
57
|
+
paths.concat(system_library_names)
|
|
58
|
+
paths.uniq
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
private
|
|
62
|
+
|
|
63
|
+
def load_uncached
|
|
64
|
+
failures = []
|
|
65
|
+
candidate_paths.each do |candidate|
|
|
66
|
+
library = new(candidate)
|
|
67
|
+
library.probe!
|
|
68
|
+
return library
|
|
69
|
+
rescue Fiddle::DLError, LoadError, TranscriptionRuntimeError => e
|
|
70
|
+
failures << "#{candidate}: #{e.message}"
|
|
71
|
+
end
|
|
72
|
+
detail = failures.empty? ? "no candidate adapter libraries were found" : failures.join("; ")
|
|
73
|
+
raise TranscriptionRuntimeError,
|
|
74
|
+
"The native FFmpeg audio adapter could not be loaded (#{detail}). " \
|
|
75
|
+
"Set COHERE_TRANSCRIBE_AUDIO_LIBRARY to libcohere_audio."
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
def system_library_names
|
|
79
|
+
case RbConfig::CONFIG.fetch("host_os")
|
|
80
|
+
when /darwin/ then ["libcohere_audio.1.dylib", "libcohere_audio.dylib"]
|
|
81
|
+
when /mswin|mingw|cygwin/ then ["cohere_audio.dll", "libcohere_audio.dll"]
|
|
82
|
+
else ["libcohere_audio.so.1", "libcohere_audio.so"]
|
|
83
|
+
end
|
|
84
|
+
end
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
attr_reader :path, :diagnostic
|
|
88
|
+
|
|
89
|
+
def initialize(path)
|
|
90
|
+
@path = path
|
|
91
|
+
@handle = Fiddle::Handle.new(path, Fiddle::RTLD_NOW)
|
|
92
|
+
@functions = FUNCTIONS.to_h do |name, (arguments, result)|
|
|
93
|
+
address = @handle["cohere_audio_ffmpeg_#{name}"]
|
|
94
|
+
function = Fiddle::Function.new(
|
|
95
|
+
address,
|
|
96
|
+
arguments.map { |type| TYPE_MAP.fetch(type) },
|
|
97
|
+
TYPE_MAP.fetch(result)
|
|
98
|
+
)
|
|
99
|
+
[name, function]
|
|
100
|
+
end.freeze
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
def probe!
|
|
104
|
+
message = Fiddle::Pointer.malloc(ERROR_CAPACITY, Fiddle::RUBY_FREE)
|
|
105
|
+
message[0, ERROR_CAPACITY] = "\0" * ERROR_CAPACITY
|
|
106
|
+
status = @functions.fetch(:probe).call(message, ERROR_CAPACITY)
|
|
107
|
+
@diagnostic = message.to_s.force_encoding(Encoding::UTF_8).scrub.freeze
|
|
108
|
+
return self if status.zero?
|
|
109
|
+
|
|
110
|
+
raise TranscriptionRuntimeError, "Native FFmpeg libraries are unavailable: #{@diagnostic}"
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
def decode(path, sample_rate:, max_decoded_bytes:)
|
|
114
|
+
output_slot = Fiddle::Pointer.malloc(Fiddle::SIZEOF_VOIDP, Fiddle::RUBY_FREE)
|
|
115
|
+
output_slot[0, Fiddle::SIZEOF_VOIDP] = [0].pack("J")
|
|
116
|
+
count_slot = Fiddle::Pointer.malloc(Fiddle::SIZEOF_INT64_T, Fiddle::RUBY_FREE)
|
|
117
|
+
count_slot[0, Fiddle::SIZEOF_INT64_T] = [0].pack("q")
|
|
118
|
+
message = Fiddle::Pointer.malloc(ERROR_CAPACITY, Fiddle::RUBY_FREE)
|
|
119
|
+
message[0, ERROR_CAPACITY] = "\0" * ERROR_CAPACITY
|
|
120
|
+
maximum = max_decoded_bytes || 0
|
|
121
|
+
|
|
122
|
+
status = @functions.fetch(:decode).call(
|
|
123
|
+
c_string(path.to_s),
|
|
124
|
+
sample_rate,
|
|
125
|
+
maximum,
|
|
126
|
+
output_slot,
|
|
127
|
+
count_slot,
|
|
128
|
+
message,
|
|
129
|
+
ERROR_CAPACITY
|
|
130
|
+
)
|
|
131
|
+
address = output_slot[0, Fiddle::SIZEOF_VOIDP].unpack1("J")
|
|
132
|
+
count = count_slot[0, Fiddle::SIZEOF_INT64_T].unpack1("q")
|
|
133
|
+
detail = message.to_s.force_encoding(Encoding::UTF_8).scrub
|
|
134
|
+
unless status.zero?
|
|
135
|
+
@functions.fetch(:free).call(address) unless address.zero?
|
|
136
|
+
raise Interrupt, "Native FFmpeg decode was cancelled for #{path}: #{detail}" if status == CANCELLED_STATUS
|
|
137
|
+
|
|
138
|
+
raise TranscriptionRuntimeError, "Cannot decode #{path} through native FFmpeg: #{detail}"
|
|
139
|
+
end
|
|
140
|
+
if count.negative? || (count.positive? && address.zero?)
|
|
141
|
+
@functions.fetch(:free).call(address) unless address.zero?
|
|
142
|
+
raise TranscriptionRuntimeError, "Native FFmpeg returned invalid output metadata for #{path}"
|
|
143
|
+
end
|
|
144
|
+
bytes = count * Fiddle::SIZEOF_FLOAT
|
|
145
|
+
if max_decoded_bytes && bytes > max_decoded_bytes
|
|
146
|
+
@functions.fetch(:free).call(address) unless address.zero?
|
|
147
|
+
raise TranscriptionRuntimeError,
|
|
148
|
+
"Native FFmpeg exceeded the configured decoded-audio memory limit for #{path}"
|
|
149
|
+
end
|
|
150
|
+
|
|
151
|
+
begin
|
|
152
|
+
require "numo/narray"
|
|
153
|
+
if count.zero?
|
|
154
|
+
Numo::SFloat.zeros(0)
|
|
155
|
+
else
|
|
156
|
+
Numo::SFloat.from_binary(Fiddle::Pointer.new(address)[0, bytes])
|
|
157
|
+
end
|
|
158
|
+
rescue LoadError => e
|
|
159
|
+
raise TranscriptionRuntimeError, "numo-narray is required for decoded audio: #{e.message}"
|
|
160
|
+
ensure
|
|
161
|
+
@functions.fetch(:free).call(address) unless address.zero?
|
|
162
|
+
end
|
|
163
|
+
end
|
|
164
|
+
|
|
165
|
+
def duration(path)
|
|
166
|
+
duration_slot = Fiddle::Pointer.malloc(Fiddle::SIZEOF_DOUBLE, Fiddle::RUBY_FREE)
|
|
167
|
+
duration_slot[0, Fiddle::SIZEOF_DOUBLE] = [-1.0].pack("d")
|
|
168
|
+
message = Fiddle::Pointer.malloc(ERROR_CAPACITY, Fiddle::RUBY_FREE)
|
|
169
|
+
message[0, ERROR_CAPACITY] = "\0" * ERROR_CAPACITY
|
|
170
|
+
status = @functions.fetch(:duration).call(
|
|
171
|
+
c_string(path.to_s),
|
|
172
|
+
duration_slot,
|
|
173
|
+
message,
|
|
174
|
+
ERROR_CAPACITY
|
|
175
|
+
)
|
|
176
|
+
detail = message.to_s.force_encoding(Encoding::UTF_8).scrub
|
|
177
|
+
unless status.zero?
|
|
178
|
+
raise Interrupt, "Native FFmpeg duration probe was cancelled for #{path}: #{detail}" if status == CANCELLED_STATUS
|
|
179
|
+
|
|
180
|
+
raise TranscriptionRuntimeError,
|
|
181
|
+
"Cannot inspect #{path} through native FFmpeg: #{detail}"
|
|
182
|
+
end
|
|
183
|
+
|
|
184
|
+
seconds = duration_slot[0, Fiddle::SIZEOF_DOUBLE].unpack1("d")
|
|
185
|
+
return nil unless seconds.finite? && seconds >= 0.0
|
|
186
|
+
|
|
187
|
+
seconds
|
|
188
|
+
end
|
|
189
|
+
|
|
190
|
+
def cancel_all!
|
|
191
|
+
@functions.fetch(:cancel).call
|
|
192
|
+
nil
|
|
193
|
+
end
|
|
194
|
+
|
|
195
|
+
private
|
|
196
|
+
|
|
197
|
+
def c_string(value)
|
|
198
|
+
Fiddle::Pointer["#{value}\0"]
|
|
199
|
+
end
|
|
200
|
+
end
|
|
201
|
+
|
|
202
|
+
module_function
|
|
203
|
+
|
|
204
|
+
def library
|
|
205
|
+
Library.load
|
|
206
|
+
end
|
|
207
|
+
|
|
208
|
+
def available?
|
|
209
|
+
library
|
|
210
|
+
true
|
|
211
|
+
rescue TranscriptionRuntimeError
|
|
212
|
+
false
|
|
213
|
+
end
|
|
214
|
+
|
|
215
|
+
def diagnostic
|
|
216
|
+
library.diagnostic
|
|
217
|
+
rescue TranscriptionRuntimeError => e
|
|
218
|
+
e.message
|
|
219
|
+
end
|
|
220
|
+
|
|
221
|
+
def decode(path, sample_rate:, max_decoded_bytes:)
|
|
222
|
+
library.decode(path, sample_rate: sample_rate, max_decoded_bytes: max_decoded_bytes)
|
|
223
|
+
end
|
|
224
|
+
|
|
225
|
+
def duration(path)
|
|
226
|
+
library.duration(path)
|
|
227
|
+
end
|
|
228
|
+
|
|
229
|
+
def cancel_all!
|
|
230
|
+
library.cancel_all!
|
|
231
|
+
rescue TranscriptionRuntimeError
|
|
232
|
+
nil
|
|
233
|
+
end
|
|
234
|
+
|
|
235
|
+
# Pipeline cleanup must not load FFmpeg merely to discover that no
|
|
236
|
+
# native decode has ever started. If the adapter is already resident,
|
|
237
|
+
# this wakes every operation that captured an older cancellation
|
|
238
|
+
# generation while preserving later independent calls.
|
|
239
|
+
def cancel_active!
|
|
240
|
+
Library.loaded&.cancel_all!
|
|
241
|
+
nil
|
|
242
|
+
rescue Fiddle::DLError, TranscriptionRuntimeError
|
|
243
|
+
nil
|
|
244
|
+
end
|
|
245
|
+
end
|
|
246
|
+
end
|
|
247
|
+
end
|
|
248
|
+
end
|