Bit-depth is not detected correctly by pydub
See original GitHub issueSteps to reproduce
def open_audio(file_path):
audio = pd.AudioSegment.from_file(file_path)
return audio
def get_bit_depth(file):
bit_depth = file.sample_width # 1-4. 1=8 2=16 3=24 4=32
if bit_depth is 1:
bit_depth = 8
elif bit_depth is 2:
bit_depth = 16
elif bit_depth is 3:
bit_depth = 24
elif bit_depth is 4:
bit_depth = 32
return bit_depth
file = pd.open_audio("PUT FILE PATH HERE")
bit_depth = pd.get_bit_depth(file)
print(bit_depth)
Expected behavior
Should print the actual bit-depth of the file (not the 1-4 value).
Actual behavior
I’ve tested 4 different files with 8 bit, 16 bit, 24 bit, and 32 bit depths.
Files were exported out of Ableton Live 10. Ableton does not support 8 bit exports, so I used an online converter to test that bit-depth instead.
8 bit is detected correctly, but whenever exported with PyDub, audio becomes garbled and in-comprehensive compared to the source file (‘8’). It should stay 1:1, especially if assigned a bit-depth higher than source. 16 bit is detected correctly 24 bit is detected as 32 bit file 32 bit file is detected correctly.
Your System configuration
- Python version: 3.7
- Pydub version: 0.23.1
- ffmpeg or avlib?: ffmpeg
- ffmpeg/avlib version: 4.1.3 win64 static (stable distro, not nightly)
Is there an audio file you can include to help us reproduce?
4 different samples, one of every bit-depth type. Test sample (kick drum).zip
Issue Analytics
- State:
- Created 4 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
How to detect a floating point audio file - python - Stack Overflow
You are looking for the bit depth of the audio file. ... from pydub.utils import mediainfo_json info = mediainfo_json('example.wav') ...
Read more >Working with wav files in Python using Pydub - GeeksforGeeks
pydub is a Python library to work with only .wav files. By using this library we can play, split, merge, edit our .wav...
Read more >ffmpeg-normalize - PyPI
Normalize audio via ffmpeg. ... After updating, this program does not work as expected anymore! ... v1.22.8 (2022-03-07). Properly detect -inf dB input....
Read more >Properly downmix 5.1 to stereo using ffmpeg - Super User
ffmpeg outputs an error such as "Can not mix named and numbered channels", which I found to mean c4 notation can't be used...
Read more >Optimize audio files for Speech-to-Text - Google Cloud
Codecs recognized by Speech-to-Text. Although Speech-to-Text recognizes a number of audio file formats, it might not read or analyze certain codecs properly ......
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Hi, thanks for writing 😃
Pydub uses Python’s stdlib
audioop
module for most operations, and unfortunately audioop does not have support for 24-bit audio (at least, in many versions of python, CPython added support for 24-bit audio in Python 3.4). So the decision was made to convert 24 bit audio to 32 bit to avoid losing quality.It may be time to revisit the decision perhaps in favor of an approach that uses 24-bit audio in environments that support it.
We could check for 24-bit support relatively easily I think:
@jiaaro
It’s been a few months since I made this thread. I wanted to see if an update has been added to support 24 bit conversion.
I’m using another library right now called PyAV which gives me some python bindings to FFmpeg’s framework. And although it supports 24 bit (only when using pcm_s24le encoder), the library still only has some limited support for other features I’d like to implement into my project.
Has there been any update on this?