AudioSegment.split_to_mono should support arbitrary number of channels
See original GitHub issueI have a setup that generates a 4-channel wav file. I would like to split this wav file into 4 separate mono tracks. The following will only generate two mono tracks:
myWav = AudioSegment.from_file('test.wav', format='wav')
print myWav.channels // 4
print len(myWav.split_to_mono()) // 2
It appears that this is due to left/right being hard-coded into split_to_mono
and audioop.tomono
. I took a look at adding the capability myself, but the values for fac1
, fac2
passed to audioop.tomono
are a bit cryptic and I’m not quite sure what needs to happen to iterate over each channel and return a variable length list of AudioSegment
objects.
Issue Analytics
- State:
- Created 7 years ago
- Comments:10 (4 by maintainers)
Top Results From Across the Web
How can I convert a WAV from stereo to mono in Python?
I maintain an open source library, pydub, which make this pretty simple from pydub import AudioSegment sound = AudioSegment.from_wav("/path/to/file.wav") ...
Read more >audiosegment module
Returns: An AudioSegment instance from the file. Creates a multi-channel AudioSegment out of multiple mono AudioSegments (two or more). Each mono AudioSegment ......
Read more >pydub noise reduction | The AI Search Engine You Control
I have recorded two people speaking on two different channels. However, they are close enough that you can hear both people on both...
Read more >Audio Analysis using Python | Speech Analytics | PyDub
Your browser can 't play this video. ... Python (PyDub library) If you have any questions about this video, let me know in...
Read more >Introduction to PyDub - Amazon S3
wav_file = AudioSegment.from_file(file="wav_file.wav", format="wav") ... Check number of channels ... phone_call_channels = phone_call.split_to_mono().
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
That’s excellent - thank you so much, thechriskelley!
I had tried frame_width: myWav.frame_width but wasn’t getting the right result. Not entirely sure why we use sample_width, but I’m new to all this. All working well with your suggestion anyway.
Hopefully jiaaro can update the split_to_mono routine to use this approach for >2 channel audio.
A fix has been merged to master. This will be in the next release of pydub