Closed CreativeLucence closed 3 years ago
I think I fixed the issue by using np.dot(), but in doing so I have found that this code is really not suited for newer versions of numpy/python. This sort of thing comes up multiple times.
I am also getting this error, s1 = np.fft.fft(hanning_window * a1) ValueError: operands could not be broadcast together with shapes (8192,) (8192,2)
This error is due to the fact that you are trying to broadcast and array shape (8192, 2) into a smaller array length 8192.
This scripts is coded for single track (mono sound track) sound and using a stereo sound track will raised
the below error message:
ValueError: operands could not be broadcast together with shapes (8192,) (8192,2)
To avoid this error, you will have to transform your sound into a mono track. I would strongly recommend to use Audacity to load your sound file and export it as mono soundtrack . (Audacity) : In the menu go to Tracks -> Mix -> Mix stereo Sound to Mono
When done, export your new sound as a WAV format and use it instead of Bowl.wav sound.
Keep in mind that the mixer has to be init accordingly e.g for mono sound : pygame.mixer.init(frequency, -16, 1, 2048) for stereo sound : pygame.mixer.init(frequency, -16, 2, 2048)
Kind Regards
@spacether Good day to you, The above answer provide the explanation of this issue. The ValueError is raised when numpy is trying to broadcast two arrays with different sizes/dimensions. This happen when a user is loading a stereo sound with the mono version of pianoputer.
If the user is loading a mono track sound then it will works fine for both versions of pianoputer (single & stereo mode). The stereo version has a method that can check for the sound model (mono or stereo) and process the sound accordingly.
A permanent fix would be to implement a method that check the sound model and throw and explicit error message when user is loading a stereo sound and using the mono version of pianoputer.
Best wishes,
Thank you for that explanation. This issue should be fixed in the next version of pianoputer which handles mono and stereo in the same python file. That update is in a PR right now.
The above pitchshift code no longer exists in master branch so this issue should be resolved. Testing with the included mono and stereo wav files verifies that this is resolved.
I have tried running this on windows 10, python 3.8.2, but I got this error: line 125, in
main()
line 89, in main
transposed_sounds = [pitchshift(sound, n) for n in tones]
line 89, in
transposed_sounds = [pitchshift(sound, n) for n in tones]
line 48, in pitchshift
stretched = stretch(snd_array, 1.0/factor, window_size, h)
line 29, in stretch
s1 = np.fft.fft(hanning_window * a1)
ValueError: operands could not be broadcast together with shapes (8192,) (8192,2)
I am relatively new to Python, and completely new to pygame, scipy, and numpy, so some assistance would be nice.