Skip to content

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