Reputation: 205
I'm trying to create an multichannel audio file with Pydub but I received an error. I know that each channels should be the exact same length, but also the frame count. I don't know how to verify if they are at the same frame count but they are at the same size.
from pydub import AudioSegment
from pydub.playback import play
from playsound import playsound
left_channel = AudioSegment.from_wav("scripts_OUN\Single Cricket Chirping Effect.wav")
right_channel = AudioSegment.from_wav("scripts_OUN\d.wav")
left_channel_v2 = left_channel + AudioSegment.silent(duration=152009)
left = left_channel_v2.set_channels(1)
right = right_channel.set_channels(1)
print(len(left_channel_v2))
print(len(right_channel))
print(len(left_channel_v2)==len(right_channel))
print(left_channel.set_frame_rate
)
mutli_channel = AudioSegment.from_mono_audiosegments(left,right)
mutli_channel.export("v3.wav", format="wav")
My errors messages :
<bound method AudioSegment.set_frame_rate of <pydub.audio_segment.AudioSegment object at 0x000002ACB8076A40>>
and :
ValueError: attempt to assign array of size 12324755 to extended slice of size 12324781
Upvotes: 0
Views: 716
Reputation: 34
<bound method AudioSegment.set_frame_rate of <pydub.audio_segment.AudioSegment object at 0x000002ACB8076A40>>
is not an error, it is reference to a method you are printing.
For ValueError: attempt to assign array of size 12324755 to extended slice of size 12324781
, this error depicts you using different slice sizes of audio for your left and right channel, hence the pydub library is not able to merge it together as multichannel audio. Use same size audio or extend the smaller audio by repeating the sound to make it equal to the size of bigger audio.
Upvotes: 0