question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

AudioSegment.split_to_mono should support arbitrary number of channels

See original GitHub issue

I 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:closed
  • Created 7 years ago
  • Comments:10 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
Qdrewcommented, Mar 3, 2017

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.

0reactions
jiaarocommented, Jun 1, 2019

A fix has been merged to master. This will be in the next release of pydub

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found