-
Notifications
You must be signed in to change notification settings - Fork 108
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
Allow pipe read/write #68
Conversation
After opening a pipe in This is not done in libsndfile and it doesn't look like this will be fixed, see libsndfile/libsndfile#77. |
Against my expectations, the issue was just fixed. |
Sounds good |
If #94 gets merged, this should be mostly fixed. The only thing left is to set |
I added a commit that sets If I didn't make a mistake, this can be merged. |
I am trying to use this branch with
I still cannot get piping to work:
Passing files works fine:
Sending the data to
When reading from stdin it fails, too
|
WAV doesn't work for pipes, see the StackOverflow link in the issue description at the top of this page. And I think It still doesn't work, because what you are using aren't pipes as far as libsndfile is concerned. The "pipe mode" is only used when you pass an actual file name or a file descriptor. If you want to use file descriptors, you can do something like this: import argparse
import pysoundfile
parser = argparse.ArgumentParser()
parser.add_argument('input')
parser.add_argument('output')
args = parser.parse_args()
infile = 0 if args.input == "-" else args.input
outfile = 1 if args.output == "-" else args.output
data, rate = pysoundfile.read(infile)
pysoundfile.write(
data,
outfile,
rate,
format='AU',
) Note that file descriptors may be problematic on Windows. If you have suggestions how we can improve the error messages and/or the documentation, speak up! |
OK, sending data into stdout works when using AU, however piping into stdin is still broken. To fix this, the following patch can be used:
This sends a filename |
I don't like this, because it violates the principle of least surprise. When I pass a file object, I expect the "virtual IO" call to be used. If you want to pass BTW, is this behavior documented somewhere? This works for me (the import argparse
import pysoundfile
parser = argparse.ArgumentParser()
parser.add_argument('input')
parser.add_argument('output')
args = parser.parse_args()
data, rate = pysoundfile.read(args.input)
pysoundfile.write(
data,
args.output,
rate,
format='AU',
) Example usage:
Does this work for you, too? |
Yes, I expect leaving out the When setting the argument to be a file |
I still don't see what the advantages of using the
If you absolutely have to use the |
I would very much like to push this issue to after 0.6.0, since it is the last blocking issue. Would you be OK with that? |
It's not blocking. |
libsndfile can read from/write to a named pipe. We disabled this feature in #60 because we don't pass the file name directly to libsndfile anymore.
To make this possible again, we could check if a given file name is actually a pipe with
We'll probably have to catch an
OSError
if the file doesn't exist.To try this, you can create a named pipe for writing:
... and then use it:
... or a named pipe for reading:
... and read from it:
Someone on StackOverflow claimed that named pipes don't work with
sf_open()
, but I tried it and it seems to work.When using file descriptors, all this already works.