user3537932
user3537932

Reputation: 163

PyDub: Combining audio size error?

I'm a novice programmer currently working on some code, where segments of audio are overlaid and joined together. The joining works perfectly fine as of now, but there appears to be an error regarding the overlaying.

I actually followed the following code from another stackoverflow question:

from pydub import AudioSegment

sound1 = AudioSegment.from_file("/path/to/my_sound.wav")
sound2 = AudioSegment.from_file("/path/to/another_sound.wav")

combined = sound1.overlay(sound2)

combined.export("/path/to/combined.wav", format='wav')

and received the following error (Unimportant portions excised):

    combined = sound1.overlay(sound2)
  File "C:\Python27\pydub\audio_segment.py", line 565, in overlay
    sample_width))
audioop.error: Size should be 1, 2 or 4
[Finished in 13.0s with exit code 1]

The audio files are both of .wav format, 24-bit (I.E. not stereo), 44100 Hz, and are both the same length (2 seconds long), so I'm not sure what's going on. I checked everywhere (that I would usually think of) for mentions of a size, but I couldn't find any. With that being said, can someone give me some clue as to what's happening with the error message?

Much thanks in advance.

Upvotes: 4

Views: 2832

Answers (1)

Jiaaro
Jiaaro

Reputation: 76958

Pydub uses the wave module from the Python StdLib - which doesn't support 24 bit wave unfortunately.

You need to pass in 8, 16, or 32 bit wave files :/

When the error message says, "Size should be 1, 2, or 4," it is referring to the number of bytes each sample should be (1 byte == 8 bits). 24 bit is 3 bytes

Upvotes: 4

Related Questions