Skip to content

cli : Support "-" for stdout like stdin #3050

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

danielzgtg
Copy link

@danielzgtg danielzgtg commented Apr 15, 2025

This changes examples/cli/cli.cpp to be like examples/common-whisper.cpp. -of - can be specified (or this can be inferred from - as the input file) to output to stdout. This is useful for piping to other applications.

Also fixed output_score and output_wts not outputting some logging messages that output_json does.

Closes #3048

@danielzgtg danielzgtg force-pushed the feat/fd branch 4 times, most recently from 755ccbb to 03877f5 Compare April 15, 2025 19:18
@danielzgtg
Copy link
Author

It's strange that the unrelated examples/talk-llama/llama-mmap.h had an error in https://github.com/ggml-org/whisper.cpp/actions/runs/14477612749/job/41345196960?pr=3050 when I only touched examples/cli/cli.cpp.

@danbev
Copy link
Collaborator

danbev commented Apr 30, 2025

It's strange that the unrelated examples/talk-llama/llama-mmap.h had an error

This is unrelated to this PR, it was fixed by #3084.

Copy link
Collaborator

@danbev danbev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried this using json output format and stdout using the following command:

../build/bin/whisper-cli -m models/ggml-tiny.en.bin -f samples/jfk.wav -oj -of - -np 2> /dev/null | jq -c '.transcription[].text'
" And so my fellow Americans ask not what your country can do for you, ask what you can do for your country."

Without redirecting stderr the following will be printed as output to the console:

output_json: saving output to '/dev/stdout'
" And so my fellow Americans ask not what your country can do for you, ask what you can do for your country."

It might be nice to not have to specify the redirect of stderr when using stdout. This was not something that was introduced by this PR but I think it would nice to perhaps have a check and not output this log message in this case.

@danielzgtg danielzgtg marked this pull request as draft April 30, 2025 12:04
@danielzgtg danielzgtg marked this pull request as ready for review April 30, 2025 12:13
This changes examples/cli/cli.cpp to be like
examples/common-whisper.cpp. "-of -" can be specified (or this can be
inferred from "-" as the input file) to output to stdout. This is useful
for piping to other applications.

Log fname_out consistently when not stdout
- Terminals have stdout=stderr, so remove the message before
  successful output to ease copying
- Don't affect actual error messages
- Move opening the ofstream into the factory, fixing missing
  open and/or error messages in output_score/output_wts
- Fix struct naming convention

Closes ggml-org#3048
@danielzgtg
Copy link
Author

Squashed and rebased on top of latest master to see if that fixes CI

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Can't output to file descriptor
2 participants