feat: add stt support via whisper.cpp with new transcribe subcommand#2438
feat: add stt support via whisper.cpp with new transcribe subcommand#2438bittoby wants to merge 3 commits intocontainers:mainfrom
Conversation
Reviewer's GuideAdds a new whisper.cpp speech-to-text runtime and a File-Level Changes
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Summary of ChangesHello @bittoby, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request significantly enhances the application's capabilities by introducing robust Speech-to-Text (STT) support. It integrates the Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request introduces speech-to-text functionality by integrating whisper.cpp. It adds a new transcribe subcommand, a whisper.cpp runtime, and the necessary configuration and command-line arguments. The implementation is solid and follows existing patterns in the codebase. I've identified a couple of opportunities to improve maintainability by refactoring duplicated code for argument parsing and image resolution logic. Overall, this is a great addition to the project.
| run(host=args.host, port=int(args.port), model_store_path=args.store) | ||
|
|
||
|
|
||
| def transcribe_parser(subparsers): |
There was a problem hiding this comment.
The transcribe_parser function duplicates a significant number of argument definitions that are also present in other parser functions like runtime_options. This code duplication makes the CLI argument setup harder to maintain.
To improve maintainability, consider refactoring the common arguments into a separate helper function. For example, you could create a function add_common_runtime_options(parser) that adds arguments shared across different subcommands (e.g., --device, --env, --image, --name, --ngl, --oci-runtime, --privileged, --pull, --runtime-args, --selinux, --threads, --tls-verify).
This new function could then be called from transcribe_parser, and runtime_options could also be refactored to use it, centralizing the logic for these common options.
ramalama/common.py
Outdated
| if config.runtime == "whisper.cpp": | ||
| from ramalama.config import DEFAULT_WHISPER_IMAGE | ||
|
|
||
| image = config.images.get("WHISPER", DEFAULT_WHISPER_IMAGE) | ||
| # If the image from the config is specified by tag or digest, return it unmodified | ||
| return image if ":" in image else f"{image}:main" |
There was a problem hiding this comment.
The logic for determining the whisper.cpp container image is duplicated here and in ramalama/cli.py within the default_whisper_image function. This duplication can lead to maintenance issues and potential inconsistencies in the future.
To improve this, you could extract the common logic into a single helper function, for example in ramalama/config.py:
# In ramalama/config.py
def get_whisper_image(config: Config) -> str:
image = config.images.get("WHISPER", DEFAULT_WHISPER_IMAGE)
return image if ":" in image else f"{image}:main"Then, both accel_image in this file and default_whisper_image in cli.py can call this new function, ensuring a single source of truth for this logic.
There was a problem hiding this comment.
Hey - I've found 1 issue, and left some high level feedback:
- The logic for choosing the whisper.cpp image is split between
default_whisper_image()incli.pyand theconfig.runtime == "whisper.cpp"branch inaccel_image; consider centralizing this image selection in one place to avoid future divergence in tag/override behavior. - In
transcribe_cliyou unconditionally setargs.runtime = "whisper.cpp", which can silently override a user-specified--runtime; it may be clearer to either maketranscribereject non-whisper runtimes explicitly or prevent--runtimefrom being accepted for this subcommand.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The logic for choosing the whisper.cpp image is split between `default_whisper_image()` in `cli.py` and the `config.runtime == "whisper.cpp"` branch in `accel_image`; consider centralizing this image selection in one place to avoid future divergence in tag/override behavior.
- In `transcribe_cli` you unconditionally set `args.runtime = "whisper.cpp"`, which can silently override a user-specified `--runtime`; it may be clearer to either make `transcribe` reject non-whisper runtimes explicitly or prevent `--runtime` from being accepted for this subcommand.
## Individual Comments
### Comment 1
<location> `ramalama/common.py:36` </location>
<code_context>
MNT_MMPROJ_FILE = f"{MNT_DIR}/mmproj.file"
MNT_FILE_DRAFT = f"{MNT_DIR}/draft_model.file"
MNT_CHAT_TEMPLATE_FILE = f"{MNT_DIR}/chat_template.file"
+MNT_AUDIO_DIR = "/mnt/audio"
RAG_DIR = "/rag"
</code_context>
<issue_to_address>
**suggestion:** Whisper image resolution logic is now duplicated in multiple places and may diverge over time
Whisper image selection is now implemented in three places (`DEFAULT_WHISPER_IMAGE`, `default_whisper_image()` in `cli.py`, and the `config.runtime == "whisper.cpp"` branch in `accel_image()`), each using similar `if ':' in image` logic with slightly different defaults. Centralizing this into a single helper (or having `accel_image` delegate to `default_whisper_image` where applicable) would reduce the risk of config drift and inconsistent behavior between CLI defaults and runtime selection.
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
Signed-off-by: bittoby <brianwhitedev1996@gmail.com>
…er args, and add runtime validation Signed-off-by: bittoby <brianwhitedev1996@gmail.com>
Signed-off-by: bittoby <brianwhitedev1996@gmail.com>
7667571 to
14f1935
Compare
|
@rhatdan I'd appreciate your feedback |
|
Does this work with STDIN? Or Not sure if adding a new command is necessary or not. Would doing something like Make sense? Would Can I override the image with something else besides whisper? @olliewalsh @engelmi @ieaves @mikebonnet @jtligon @bmahabirbu WDYT? |
================== STDIN: Not supported right now. It needs an audio file path (the file is mounted into the container). We could add STDIN later by saving it to a temp file first. Why ramalama transcribe instead of ramalama run --transcribe: Transcribe is a one-shot “audio in, text out” command. run is for interactive chat, so keeping them separate avoids messy argument handling. I can change it if the team prefers run --transcribe. Using a running Whisper server: Not supported yet. It starts a new container each time. We could add a --server option later to send audio to an existing server. Custom image: Yes, --image works. |
|
@rhatdan Please let me know your option |
Add Speech-to-Text Support via whisper.cpp
Adds a new
transcribesubcommand andwhisper.cppruntime for speech-to-text transcription.Usage
Changes
transcribesubcommand usingwhisper-cliwhisper.cppruntime withserve(HTTP API) andtranscribe(batch)inference-spec/engines/whisper.cpp.yamlghcr.io/ggml-org/whisper.cpp:mainNotes
chmod o+r audio.wavramalama --runtime whisper.cpp serve MODELIssue: #2376
Summary by Sourcery
Add speech-to-text support using a new whisper.cpp runtime and transcribe subcommand integrated into the CLI and inference engine.
New Features:
Enhancements: