jiaaro / pydub

Manipulate audio with a simple and easy high level interface
http://pydub.com
MIT License
8.94k stars 1.05k forks source link

How to turn a 2 channel audio file into a 4 channel one? #622

Open Fear-MK opened 3 years ago

Fear-MK commented 3 years ago

This isn't much so an issue, but rather a question. How can I make a 4 channel (and above (6, 8 channels)) music file without the 3rd and 4th channel being blank?

def speed_change(speed): for file in filename_tracks: audio_input = filename_tracks[file]+"_amp.wav" audio_output = filename_tracks[file]+"_f.wav" sound = AudioSegment.from_file(audio_input) sound_with_altered_frame_rate = sound._spawn(sound.raw_data, overrides={ "frame_rate": int(sound.frame_rate * speed) }) speed_up = sound_with_altered_frame_rate.set_frame_rate(sound.frame_rate) if "STRM" in filename_tracks[file]: speed_up.export(audio_output, format="wav", parameters=["-ac", "4"]) else: speed_up.export(audio_output, format="wav")

This is the code being included at the moment, and currently it leaves channels 3 and 4 blank.

anubhav-narayan commented 3 years ago

So far, I have never seen multichannel audio being used in PyDub. In fact, my very crude and basic eq function relies on the fact that all files processed are Stereo or Mono and not multichannel. If multichannel audio is supported, I would have to change the design and pattern of that function a little.

Can anyone please confirm this? @jiaaro @ross @cghawthorne @shadchin @emyller

Fear-MK commented 3 years ago

I knew you could mix down to 2 channels (from reading the readme), which gave me the impression you could somehow do the opposite, thought I may be wrong. If there was another library that made multichannel files that would be great too, but my lack of googling skills means I haven't found anything thus far.

mjlabe commented 2 years ago

Could you load them all as mono and combine from there?

# load individual channels... mutli_channel = AudioSegment.from_mono_audiosegments(channel1, channel2, ..., channel_n)

https://stackoverflow.com/questions/44920182/how-to-write-multi-channel-wav-file-in-python