Merge d8061f0c57
into 72af0f5697
commit
1892595b4f
@ -0,0 +1,104 @@
|
|||||||
|
require 'erb'
|
||||||
|
require 'open3'
|
||||||
|
require 'rake/clean'
|
||||||
|
require 'rake/testtask'
|
||||||
|
require 'rubygems/package'
|
||||||
|
|
||||||
|
CLEAN.include '**/*.o'
|
||||||
|
CLEAN.include "**/*.#{(defined?(RbConfig) ? RbConfig : Config)::MAKEFILE_CONFIG['DLEXT']}"
|
||||||
|
CLOBBER.include 'doc'
|
||||||
|
CLOBBER.include '**/*.log'
|
||||||
|
CLOBBER.include '**/Makefile'
|
||||||
|
CLOBBER.include '**/extconf.h'
|
||||||
|
CLOBBER.include '**/extconf.h'
|
||||||
|
CLOBBER.include '**/whisper.*'
|
||||||
|
CLOBBER.include '**/ggml.*'
|
||||||
|
CLOBBER.include '**/dr_wav.h'
|
||||||
|
|
||||||
|
BUILD_VERSION=2
|
||||||
|
# Determine the current version of the software
|
||||||
|
if File.read('../../CMakeLists.txt') =~ /project.*\s*VERSION\s*(\d.+)\)/
|
||||||
|
CURRENT_VERSION = "#{$1}.#{BUILD_VERSION}"
|
||||||
|
else
|
||||||
|
CURRENT_VERSION = "0.0.0.#{BUILD_VERSION}"
|
||||||
|
end
|
||||||
|
|
||||||
|
def shell(args, opts = {})
|
||||||
|
puts "> #{args.join(' ')}"
|
||||||
|
cmd, live_stream, cwd = args, opts[:live_stdout], opts[:cwd]
|
||||||
|
Dir.chdir(cwd) {
|
||||||
|
wait_thr = nil
|
||||||
|
|
||||||
|
Open3.popen3(*cmd) do |stdin, stdout, stderr, thr|
|
||||||
|
stdin.close
|
||||||
|
wait_thr = thr # Ruby 1.8 will not yield thr, this will be nil
|
||||||
|
|
||||||
|
while line = stdout.gets do
|
||||||
|
live_stream.puts(line) if live_stream
|
||||||
|
end
|
||||||
|
|
||||||
|
while line = stderr.gets do
|
||||||
|
puts line
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
# prefer process handle directly from popen3, but if not available
|
||||||
|
# fallback to global.
|
||||||
|
p_status = wait_thr ? wait_thr.value : $?
|
||||||
|
exit_code = p_status.exitstatus
|
||||||
|
error = (exit_code != 0)
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
make_program = (/mswin/ =~ RUBY_PLATFORM) ? 'nmake' : 'make'
|
||||||
|
MAKECMD = ENV['MAKE_CMD'] || make_program
|
||||||
|
MAKEOPTS = ENV['MAKE_OPTS'] || ''
|
||||||
|
WHISPER_SO = "ext/whisper.#{(defined?(RbConfig) ? RbConfig : Config)::MAKEFILE_CONFIG['DLEXT']}"
|
||||||
|
|
||||||
|
file 'ext/Makefile' => 'ext/extconf.rb' do
|
||||||
|
shell(['ruby', 'extconf.rb', ENV['EXTCONF_OPTS'].to_s],
|
||||||
|
{ live_stdout: STDOUT, cwd: "#{Dir.pwd}/ext" }
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
|
def make(target = '')
|
||||||
|
shell(["#{MAKECMD}", "#{MAKEOPTS}", "#{target}"].reject(&:empty?),
|
||||||
|
{ live_stdout: STDOUT, cwd: "#{Dir.pwd}/ext" }
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
|
# Let make handle dependencies between c/o/so - we'll just run it.
|
||||||
|
file WHISPER_SO => (['ext/Makefile'] + Dir['ext/*.cpp'] + Dir['ext/*.c'] + Dir['ext/*.h']) do
|
||||||
|
make
|
||||||
|
end
|
||||||
|
|
||||||
|
desc "Compile the shared object"
|
||||||
|
task :compile => [WHISPER_SO]
|
||||||
|
|
||||||
|
desc "Default Task (Test project)"
|
||||||
|
task :default => :test
|
||||||
|
|
||||||
|
Rake::TestTask.new(:test) do |t|
|
||||||
|
t.test_files = FileList['tests/test_*.rb']
|
||||||
|
t.verbose = false
|
||||||
|
end
|
||||||
|
|
||||||
|
desc 'Generate gem specification'
|
||||||
|
task :gemspec do
|
||||||
|
system("cp ../../LICENSE .")
|
||||||
|
system("cp ../../README.md .")
|
||||||
|
tspec = ERB.new(File.read(File.join(File.dirname(__FILE__),'lib','whispercpp.gemspec.erb')))
|
||||||
|
File.open(File.join(File.dirname(__FILE__),'whispercpp.gemspec'),'wb') do|f|
|
||||||
|
f << tspec.result
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
desc 'Build gem'
|
||||||
|
task :package => :gemspec do
|
||||||
|
spec_source = File.read File.join(File.dirname(__FILE__),'whispercpp.gemspec')
|
||||||
|
spec = nil
|
||||||
|
# see: http://gist.github.com/16215
|
||||||
|
Thread.new { spec = eval("#{spec_source}") }.join
|
||||||
|
spec.validate
|
||||||
|
Gem::Package.build(spec)
|
||||||
|
end
|
@ -0,0 +1,13 @@
|
|||||||
|
# Ruby Guide
|
||||||
|
|
||||||
|
We expose Whisper::Context and Whisper::Params. The Context object can be used to transcribe.
|
||||||
|
Parameters can be set on the Params object to customize how the transcription is generated.
|
||||||
|
|
||||||
|
```
|
||||||
|
require 'whisper'
|
||||||
|
whisper = Whisper::Context.new('ggml-base.en.bin')
|
||||||
|
params = Whisper::Params.new
|
||||||
|
whisper.transcribe('jfk.wav', params) {|text|
|
||||||
|
assert_match /ask not what your country can do for you, ask what you can do for your country/, text
|
||||||
|
}
|
||||||
|
```
|
@ -0,0 +1,40 @@
|
|||||||
|
Gem::Specification.new do |s|
|
||||||
|
s.name = "whispercpp"
|
||||||
|
s.authors = ["Georgi Gerganov", "Todd A. Fisher"]
|
||||||
|
s.version = '<%= CURRENT_VERSION %>'
|
||||||
|
s.date = '<%= Time.now.strftime("%Y-%m-%d") %>'
|
||||||
|
s.description = %q{High-performance inference of OpenAI's Whisper automatic speech recognition (ASR) model via Ruby}
|
||||||
|
s.email = 'todd.fisher@gmail.com'
|
||||||
|
s.extra_rdoc_files = ['LICENSE', 'README.md']
|
||||||
|
<%
|
||||||
|
files = %w(LICENSE README.md Rakefile ext/extconf.rb) +
|
||||||
|
Dir["lib/**/**.rb"] +
|
||||||
|
Dir["ext/**/**.c"] +
|
||||||
|
Dir["ext/**/**.cpp"] +
|
||||||
|
Dir["ext/**/**.h"]
|
||||||
|
|
||||||
|
if ENV['BINARY_PACKAGE'] # TODO: we could build binary packages
|
||||||
|
files += Dir['ext/**/*.{o,so,bundle}']
|
||||||
|
end
|
||||||
|
%>
|
||||||
|
s.files = <%= files.inspect %>
|
||||||
|
|
||||||
|
#### Load-time details
|
||||||
|
s.require_paths = ['lib','ext']
|
||||||
|
s.summary = %q{Ruby whisper.cpp bindings}
|
||||||
|
s.test_files = <%= Dir['tests/**/**.rb'].inspect %>
|
||||||
|
<% unless ENV['BINARY_PACKAGE'] %>
|
||||||
|
s.extensions << 'ext/extconf.rb'
|
||||||
|
<% end %>
|
||||||
|
|
||||||
|
#### Documentation and testing.
|
||||||
|
s.homepage = 'https://github.com/ggerganov/whisper.cpp'
|
||||||
|
s.rdoc_options = ['--main', '../../README.md']
|
||||||
|
|
||||||
|
<% if ENV['BINARY_PACKAGE'] %>
|
||||||
|
s.platform = Gem::Platform::CURRENT
|
||||||
|
<% else %>
|
||||||
|
s.platform = Gem::Platform::RUBY
|
||||||
|
<% end %>
|
||||||
|
s.licenses = ['MIT']
|
||||||
|
end
|
Loading…
Reference in new issue