Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions bindings/ruby/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ ext/ggml/
ext/include/
ext/scripts/
ext/src/
test/fixtures/
19 changes: 17 additions & 2 deletions bindings/ruby/Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,28 @@ CLEAN.include LIB_FILE

Rake::TestTask.new

TEST_FIXTURE_AUDIO = "test/fixtures/jfk.wav"
TEST_FIXTURE_AUDIO_SRC = File.expand_path(File.join(__dir__, "..", "..", "samples", "jfk.wav"))
TEST_FIXTURE_AUDIO_DIR = TEST_FIXTURE_AUDIO.pathmap("%d")
directory TEST_FIXTURE_AUDIO_DIR
if File.exist? TEST_FIXTURE_AUDIO_SRC
file TEST_FIXTURE_AUDIO => [TEST_FIXTURE_AUDIO_SRC, TEST_FIXTURE_AUDIO_DIR] do |t|
symlink t.source, t.name
end
else
require "open-uri"
file TEST_FIXTURE_AUDIO => TEST_FIXTURE_AUDIO_DIR do |t|
File.write t.name, URI("https://github.com/ggml-org/whisper.cpp/raw/refs/heads/master/samples/jfk.wav").read
end
end

TEST_MEMORY_VIEW = "test/jfk_reader/jfk_reader.#{RbConfig::CONFIG['DLEXT']}"
file TEST_MEMORY_VIEW => "test/jfk_reader/jfk_reader.c" do |t|
chdir "test/jfk_reader" do
ruby "extconf.rb"
sh "make"
end
end
CLEAN.include "test/jfk_reader/jfk_reader.{o,#{RbConfig::CONFIG['DLEXT']}}"
CLEAN.include TEST_MEMORY_VIEW

task test: [LIB_FILE, TEST_MEMORY_VIEW]
task test: [LIB_FILE, TEST_MEMORY_VIEW, TEST_FIXTURE_AUDIO]
33 changes: 27 additions & 6 deletions bindings/ruby/ext/options.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,19 +43,40 @@ def configure
@options[name] = [type, value]
end

configure_accelerate
configure_metal
configure_coreml
end

# See ggml/src/ggml-cpu/CMakeLists.txt
def configure_accelerate
if RUBY_PLATFORM.match?(/darwin/) && enabled?("GGML_ACCELERATE")
$LDFLAGS << " -framework Accelerate"
end
end

# See ggml/src/ggml-metal/CMakeLists.txt
def configure_metal
$LDFLAGS << " -framework Foundation -framework Metal -framework MetalKit" if enabled?("GGML_METAL")
end

# See src/CmakeLists.txt
def configure_coreml
use_coreml = if @options["WHISPER_COREML"][1].nil?
cmake_options["WHISPER_COREML"][1]
else
@options["WHISPER_COREML"][1]
end
$CPPFLAGS << " -DRUBY_WHISPER_USE_COREML" if use_coreml
if enabled?("WHISPER_COREML")
$LDFLAGS << " -framework Foundation -framework CoreML"
$CPPFLAGS << " -DRUBY_WHISPER_USE_COREML"
end
end

def option_name(name)
name.downcase.gsub("_", "-")
end

def enabled?(option)
if @options[option][1].nil?
cmake_options[option][1]
else
@options[option][1]
end
end
end
4 changes: 2 additions & 2 deletions bindings/ruby/lib/whisper/model/uri.rb
Original file line number Diff line number Diff line change
Expand Up @@ -132,13 +132,13 @@ def format_bytesize(bytesize)

class ZipURI < URI
def cache
zip_path = Pathname(super)
zip_path = super
dest = unzipped_path
return if dest.exist? && dest.mtime >= zip_path.mtime
escaping dest do
system "unzip", "-q", "-d", zip_path.dirname.to_path, zip_path.to_path, exception: true
end
zip_path.to_path
zip_path
end

def clear_cache
Expand Down
2 changes: 1 addition & 1 deletion bindings/ruby/sig/whisper.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ module Whisper
end

class ZipURI < URI
def cache: () -> String
def cache: () -> Pathname
def clear_cache: () -> void
end
end
Expand Down
2 changes: 1 addition & 1 deletion bindings/ruby/test/helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
require_relative "jfk_reader/jfk_reader"

class TestBase < Test::Unit::TestCase
AUDIO = File.join(__dir__, "..", "..", "..", "samples", "jfk.wav")
AUDIO = File.join(__dir__, "fixtures", "jfk.wav")

class << self
def whisper
Expand Down
1 change: 0 additions & 1 deletion bindings/ruby/whispercpp.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ Gem::Specification.new do |s|
s.name = "whispercpp"
s.authors = ["Georgi Gerganov", "Todd A. Fisher"]
s.version = '1.3.3'
s.date = '2025-06-10'
s.description = %q{High-performance inference of OpenAI's Whisper automatic speech recognition (ASR) model via Ruby}
s.email = '[email protected]'
s.extra_rdoc_files = ['LICENSE', 'README.md']
Expand Down
Loading