class WhisperCpp < Formula desc "Port of OpenAI's Whisper model in C/C++" homepage "https://github.com/ggml-org/whisper.cpp" url "https://github.com/ggml-org/whisper.cpp/archive/refs/tags/v1.9.5.tar.gz" sha256 "ff1a9053feb509ff9d7729703355541ae9690073a6b1c40eb692c962e0dc1720" license "MIT" compatibility_version 1 head "https://github.com/ggml-org/whisper.cpp.git", branch: "master" livecheck do url :stable strategy :github_latest end bottle do sha256 cellar: :any, arm64_golden_gate: "4960b2068b6c9820ab0e686fc4fe58e2edeb19c58c9613751b417a4ea9ab7ec3" sha256 cellar: :any, arm64_tahoe: "8c72ed8b6624aab6d9058ae4de65e73190265fdaeb3a7cd3f7d96417dc67325b" sha256 cellar: :any, arm64_sequoia: "a6691f811f613d79d1e508a89c7523e69f5b13a58c10e26083e77f8909b6db1e" sha256 cellar: :any, arm64_linux: "da1155a46b4d2e8ede1d4bd9da94d17b3b5aeeff473701a4859d7de3ffb5c507" sha256 cellar: :any, x86_64_linux: "f4d28a5d683ad92571dc089d1e2ce0168ebd0dcfaef117311742714e61b2bd1b" end depends_on "cmake" => :build depends_on "pkgconf" => :test depends_on "ggml" # NOTE: reject all PRs that try to bundle ggml depends_on "llama.cpp" depends_on "sdl2-compat" deny_network_access! def install args = %W[ -DBUILD_SHARED_LIBS=ON -DCMAKE_INSTALL_RPATH=#{rpath} -DWHISPER_SDL2=ON -DWHISPER_BUILD_EXAMPLES=ON -DWHISPER_BUILD_TESTS=OFF -DWHISPER_BUILD_SERVER=OFF -DWHISPER_USE_SYSTEM_GGML=ON -DWHISPER_USE_SYSTEM_LLAMA=ON ] args << "-DWHISPER_BUILD_IS_DEV=OFF" if build.stable? system "cmake", "-S", ".", "-B", "build", *args, *std_cmake_args system "cmake", "--build", "build" system "cmake", "--install", "build" pkgshare.install "models/for-tests-ggml-tiny.bin", "samples/jfk.wav" end def caveats <<~EOS #{name} requires GGML model files to work. These are not downloaded by default. To obtain model files (.bin), visit one of these locations: https://huggingface.co/ggerganov/whisper.cpp/tree/main https://github.com/ggml-org/whisper.cpp/tree/master/models EOS end test do model = pkgshare/"for-tests-ggml-tiny.bin" output = shell_output("#{bin}/whisper-cli --model #{model} #{pkgshare}/jfk.wav 2>&1") assert_match "processing '#{pkgshare}/jfk.wav' (176000 samples, 11.0 sec)", output (testpath/"test.cpp").write <<~CPP #include #include int main() { ggml_backend_load_all(); struct whisper_context_params cparams = whisper_context_default_params(); struct whisper_context * ctx = whisper_init_from_file_with_params("#{model}", cparams); assert(ctx != nullptr); whisper_free(ctx); return 0; } CPP flags = shell_output("pkgconf --cflags --libs ggml whisper").chomp.split system ENV.cxx, "-std=c++11", "test.cpp", "-o", "test", *flags system "./test" end end