Skip to content
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

Fix the problem that pydub.playback() can't play 32bit audios with pyaudio correctly #781

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

Conversation

hikali8
Copy link

@hikali8 hikali8 commented Mar 5, 2024

pydub.playback() can't play 32bit audios with pyaudio correctly because p.get_format_from_width(seg.sample_width) returns "paFloat32" when seg.sample_width is 4, but chunk._data is actually a bunch of 32bit ints, which contradicts the "paFloat32" which means that floats should be given. therefore we will get a series of electronic noises instead of correct music sounds.

so, I fixed the problem by simply adding a judgment of seg.sample_width. if it's not 4, then use the original method; If it is 4, then use "pyaudio._portaudio.paInt32" to output 32bit ints.

pydub.playback() can't play 32bit audios with pyaudio correctly because p.get_format_from_width(seg.sample_width) returns "paFloat32" when seg.sample_width is 4, but chunk._data is actually a bunch of 32bit ints, which contradicts the "paFloat32" that means that floats should be given.

So, I fixed the problem by simply adding a judgment of seg.sample_width. If it's not 4, then use the original 
method; If it is 4, then use "pyaudio._portaudio.paInt32" to output 32bit ints.
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.

1 participant