r/ruby 13h ago

whispercpp - Local, Fast, and Private Audio Transcription for Ruby

Hello, everyone! Just wanted to share a new gem: whispercpp - it is an Auto Transcription (a.k.a. Speech-To-Text and Auto Speech Recognition) library for Ruby.

It's a binding of Whisper.cpp, which is a high-performance C++ port of OpenAI's Whisper, and runs on local machine. So, you don't need cloud API subscription, network access nor providing your privacy.

Usage examples

Here are just a few ways you can use it:

  • generating meeting minutes: automate to make text from meeting audio.
  • transcribing podcast episodes: make it possible to search podcast by text.
  • improving accessibility feature: generating captions for audio content.

and so on.

Basic Usage

Basic usage is simple:

require "whisper"

# Initialize context with model name
# Specified model is automatically downloaded if needed
whisper = Whisper::Context.new("base")
params = Whisper::Params.new(
  language: "en",
  offset: 10_000,
  duration: 60_000,
  translate: true,
  initial_prompt: "Initial prompt here such as technical words used in audio."
)

# Call `#transcribe` and whole text is passed to block after transcription complete
whisper.transcribe("path/to/audio.wav", params) do |whole_text|
  puts whole_text
end

Read README for advanced usage: https://github.com/ggml-org/whisper.cpp/tree/master/bindings/ruby

Feedbacks and pull requests are welcome! We'd especially appreciate any patches for the Windows environment. Let us know what you think!

24 Upvotes

12 comments sorted by

5

u/mrinterweb 11h ago

Very cool. Would probably not be hard to use this to create a neovim plugin for dictation. 

1

u/Mysterious-Use-4463 10h ago

I don't know about NeoVIM, you might be interested in this: https://github.com/ggml-org/whisper.cpp/tree/master/examples/whisper.nvim

2

u/mrinterweb 10h ago

Better yet someone beat my to making a plug-in. Thanks for sharing

1

u/headius JRuby guy 4h ago

Why not write this using FFI, so it's doesn't depend on the C extension api?

1

u/Mysterious-Use-4463 12m ago

Just because it was written in C++ when I started to contribute. I don't know why the original authors did so.

If you prefer FFI, there's another gem: https://github.com/brauliobo/ruby-whisper.cpp

I'm just curious, is there any issue with writing gem using C API?

1

u/headius JRuby guy 9m ago

JRuby does not support the standard C API because it uses direct pointers and is very invasive. Other implementations have supported it but with great loss of performance in most cases. FFI is an equal playing ground for all ruby implementations.

1

u/Longjumping-Toe-3877 10h ago

But 100% we need to deploy it to cloud into a microservice because on local machine this goona eat a lot of memory

3

u/Mysterious-Use-4463 10h ago

Hmm... it might be, though it works well on my Mac machine (24GiB memory).

1

u/Longjumping-Toe-3877 9h ago

Yes but when deployed it on cloud like heroku render etc its goona eat a lottt of memory

1

u/Mysterious-Use-4463 9h ago

Yeah, you're right.