Skip to content
New issue

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

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

Already on GitHub? # to your account

Stream.read blocks until audio is playing #20

Open
jangxx opened this issue Sep 11, 2019 · 8 comments
Open

Stream.read blocks until audio is playing #20

jangxx opened this issue Sep 11, 2019 · 8 comments

Comments

@jangxx
Copy link

jangxx commented Sep 11, 2019

When creating a stream with as_loopback=True, the read method on the created stream will block until audio is being played. I'm not sure if this is the desired behavior, but it's certainly unexpected for me. I would suggest the read method to instead just return silence, instead of blocking until data is available.

This blog post mentions this problem, with the solution of running an application which just outputs silence, but I don't think this is a particularly useful solution for a library.

@intxcc
Copy link
Owner

intxcc commented Sep 11, 2019

Thank you for that suggestion!
Did not think much about that as it was never a problem for me.

I will see if I can implement the first solution you suggested.

Best,
Marvin

@Nufflee
Copy link

Nufflee commented Sep 28, 2019

This would be very useful. Hopefully it's implemented soon. +1

@intxcc
Copy link
Owner

intxcc commented Oct 4, 2019

The silence isn't perfect yet, but there you go.
Moved this in an extra branch, as long as it has some issues.
PyAudio-0.2.11.win-amd64-py3.7.msi.zip

@intxcc
Copy link
Owner

intxcc commented Oct 4, 2019

Usage

stream = p.open(format = pyaudio.paInt16,
                channels = channelcount,
                rate = int(device_info["defaultSampleRate"]),
                input = True,
                frames_per_buffer = defaultframes,
                input_device_index = device_info["index"],
                as_loopback = useloopback,
                wasapi_fill_silence = True)

@intxcc
Copy link
Owner

intxcc commented Oct 5, 2019

Or instead of silence I could return NULL when the loopback output stream has no frames available.
One would then be able to handle this case oneself in the python code, as the operation will then be non-blocking.

@jangxx
Copy link
Author

jangxx commented Oct 9, 2019

Sounds like a great idea, but this would make the loopback streams a special edge case, which don't always return audio like all the other streams. Considering the loopback streams are special anyway however, I think both ways would be fine from a design perspective and having an specific return value for when no audio is available could be useful I guess.

@tavin-inc
Copy link

I downloaded this version with wasapi_fill_silence but it's giving me an error in init(), saying that this parameter doesn't exist

@mikhailTochilin
Copy link

Could you please drop the .wheel package of this version with wasapi?

# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
None yet
Development

No branches or pull requests

5 participants