0

I have one big wav file:

from pydub import AudioSegment

big_aduio_file= "movie.wav"
audio = AudioSegment.from_wav(big_aduio_file)

And from it, I make a slice:

start = 6800
end = 10000
audio_chunk=audio[start:end]

Then, After I done a lot of things to the audio_chunk without changing its length I want to put it back to the original audio

#audio_chunk = do_stuff(audio_chunk)
audio[start:end] = audio_chunk

Then, I see the following error:

TypeError: 'AudioSegment' object does not support item assignment

What is the proper way of doing this?

TheGainadl
  • 523
  • 1
  • 6
  • 14
  • Bassically, I just want to do a voice alteration, I always slice from the big wav a part where somebody speaks, by "a lot of things" I mean that there is a lot of machine learning code which is not relevant to my error. I just create a new wav of the same size that I want to replace the old wav in the big audio chunk. do_stuff(audio_chunks) returns somehing of the exact same type and length. – TheGainadl May 23 '22 at 10:00
  • 1
    ok so i understood what's happening, you are treating audio as array but they both are pydub.audio_segment.AudioSegment ,that's why it's not able to assign as such. So one solution would be to convert them into numpy array and then convert it back to pydub.audio_segment.AudioSegment. Here are the links that might help you : https://stackoverflow.com/questions/51408458/pydub-slice-audio-segment-by-sample , https://stackoverflow.com/questions/35735497/how-to-create-a-pydub-audiosegment-using-an-numpy-array – DontDownvote May 23 '22 at 11:48
  • Thx, in the end I created a bunch of wavs out of the big wav, I changed the ones that I wanted to change, then I concatenated all the wavs together in another big wav. It's not optimal but it does the job. It should be a better way of doing this. – TheGainadl May 23 '22 at 14:54

0 Answers0