.wav file error : "AttributeError: 'bytes' object has no attribute 'seek'" in python

3.3k Views Asked by At

I am trying to loop through a large list of audio files and want to chop them up into 5 second pieces.

Relevant code for the problem is as below.

for file in os.listdir(directory):
    
    f = sf.SoundFile(file)
    
    audio_file = AudioSegment.from_file(file, "wav")

I am getting an error: "AttributeError: 'bytes' object has no attribute 'seek'"

I appreciate the file is in bytes format, but I have attempted to convert it to a string, etc with no luck as I get a permission denied error when I do that.

1

There are 1 best solutions below

1
On

If you are using pydub, you can use AudioSegment.from_wav(file) or AudioSegment.from_raw(file, sample_width, frame_rate)