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
winsound.PlaySound() with SND_MEMORY should accept bytes instead of strings #55829
Comments
PlaySound supposedly lets you play a .WAV file whose contents are stored in a string, by passing the string and flags including winsound.SND_MEMORY. I'm trying to use BytesIO object and the wave module to make a file in-memory, and pass this to winsound. It's a TypeError if I pass the resultant bytes object directly, and if I pass a string object, I get TypeError: must be str without null character or None, not str Since wav files can contain zeros, for the feature to work at all, the C code would need to detect the SND_MEMORY flag and interpret the first argument as a bytes object, instead of a null-terminated string, in that case. |
This patch should both correct the incorrect acceptance of strings and the incorrect rejection of buffer objects when using SND_MEMORY. |
I ran into this today. Can't we just change the "Z" to "z#" in the format string (or "z*")? Other than that, Tim's patch makes sense. |
Ran into this today when trying to provide a fallback sound output on windows when the user hasn't got pyaudio installed. |
Irmen, you're probably correct that this was overlooked at the time of 3.0. The patch is well out of date as well, winsound was Clinicized around the 3.4 timeframe. |
Here's an updated patch. I'm a little wary of applying this on 3.5, because it is backward-incompatible: a str is no longer accepted with SND_MEMORY. On the other hand, it's pretty much a fluke if that works at all currently. |
New changeset 8fa615a2a896 by Zachary Ware in branch 'default': |
Thanks for the original patch, Tim! After discussion with Steve, we figured it's best to keep this to 3.6. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: