ArdenButterfield / stammer

Recreate any audio track by rearranging the frames of another video
MIT License
434 stars 29 forks source link

Program fails to run on certain kinds of files (.mp3s) #75

Open tyryry1107 opened 1 year ago

tyryry1107 commented 1 year ago

I was trying to run STAMMER on some mp3 files, but instead got this error:

Calculating video length
reading audio
analyzing audio
Traceback (most recent call last):
  File "C:\Users\tyryry\Desktop\STAMMER\stammer.py", line 307, in <module>
    main()
  File "C:\Users\tyryry\Desktop\STAMMER\stammer.py", line 303, in main
    process(**vars(args))
  File "C:\Users\tyryry\Desktop\STAMMER\stammer.py", line 246, in process
    matcher = BasicAudioMatcher(carrier_audio, modulator_audio, INTERNAL_SAMPLERATE, frame_length)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\tyryry\Desktop\STAMMER\audio_matching.py", line 19, in __init__
    self.make_best_matches()
  File "C:\Users\tyryry\Desktop\STAMMER\audio_matching.py", line 66, in make_best_matches
    self.modulator_bands = self.make_normalized_bands(self.modulator_frames)
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\tyryry\Desktop\STAMMER\audio_matching.py", line 40, in make_normalized_bands
    spectra = abs(transforms[:,1:len(transforms[0])//2])
                                     ~~~~~~~~~~^^^
IndexError: index 0 is out of bounds for axis 0 with size 0

It seems to happen everytime I'm using an mp3 file as the carrier track. However, I found out that if I were to delete the first few milliseconds of silence at the start of the mp3 track (as mp3 files are) the program worked as expected.

Based on the error IndexError: index 0 is out of bounds for axis 0 with size 0 I think the error might be because of the silence (which have empty frames in them), and the empty frames cause issues when trying to create an array (hence out of bounds for an empty array of 0). I tried creating a file with ONLY silence to test this, but STAMMER seemed to work just fine with the silent file, even when it was a .mp3.

I think when I tried this with .oggs the program also worked just fine.