-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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
Piping to stdin is failing on Windows #2023
Comments
I've made the suggested changes locally and verified that Copilot's code does seem to fix the issue. I've tried longer wave files using I also tested I'll need to investigate more thoroughly before I submit a pull request. |
Without #2025, fread on windows stops reading stdin at 0x1a (EOF) $ xxd samples/jfk.wav | head
00000000: 5249 4646 465f 0500 5741 5645 666d 7420 RIFFF_..WAVEfmt
00000010: 1000 0000 0100 0100 803e 0000 007d 0000 .........>...}..
00000020: 0200 1000 4c49 5354 1a00 0000 494e 464f ....LIST....INFO
^^ Note: Even with the proposed change, powershell < 7.4 mangles piped data. |
I can't get
stdin
pipe to work correctly on windows.Trying
type timit1.wav | main -
does read the first3898
bytes, but then it ends unexpectedly:There are also errors with with
ffmpeg
(same command line and wave file works on Linux):I've also experienced the same problem when piping to stdin via Node.js process. I can see that the pipe is closed too early, after only a part of the data is written.
Does succeed when given a a 1 second silent wave file
Possibly related to having all zero samples (not sure).
Similar behavior seen when run from Node.js.
Possible cause
I've located this code that may be related:
In
common.cpp
->read_wav()
:Based on conversation with Microsoft Copilot chatbot, it suggested that it could be that on Windows, the pipe is interpreted as having a text mode by default. It suggests changing to binary mode.
Copilot's suggestion
Given the behavior you’re describing, it does seem like the issue could be related to the way stdin is being handled on Windows. The fact that whisper.cpp reads a certain amount of data and then stops without an error suggests that it might be interpreting a part of the binary data as an EOF marker due to Windows’ default text mode for stdin.
Switching stdin to binary mode is a common solution for this kind of problem on Windows because it prevents the system from misinterpreting binary data as control characters (like the Ctrl+Z EOF marker in text mode). Since you’ve confirmed that _setmode, O_BINARY, and fileno are not present in the codebase, adding the binary mode setting could potentially resolve the issue.
Here’s how you can modify the code to set stdin to binary mode:
This may not be the actual cause of the issue, but it's still a possibility worth checking.
The text was updated successfully, but these errors were encountered: