Quantcast
Channel: Recent Questions - Stack Overflow
Viewing all articles
Browse latest Browse all 15970

Python: ValueError: object too deep for desired array. How do I fix this?

$
0
0

VScode show an error on line 12 and 22. Here is the code.

from scipy.io import wavfileimport numpy as npdef change_pitch(input_file, output_file, semitones, nsemitones):    # Read the .wav file    sample_rate, data = wavfile.read(input_file)    # Define the pitch shift factor    pitch_factor = 2 ** (semitones / nsemitones)    # Apply pitch shift    shifted_data = np.interp( np.arange(0, len(data), pitch_factor),np.arange(0, len(data)),data).astype(data.dtype)    # Write the modified data to a new .wav file    wavfile.write(output_file, sample_rate, shifted_data)#Test usageinput_file = "rhodes.wav"output_file = "output.wav"semitones_to_change = 10  # Change this value according to your requirementnsemitones = 12change_pitch(input_file, output_file, semitones_to_change, nsemitones)

here are the errors:

 File "C:\Users\hp\OneDrive\Bureau\useless fucking MIDi\python.py", line 12, in change_pitch    shifted_data = np.interp( np.arange(0, len(data), pitch_factor),np.arange(0, len(data)),data).astype(data.dtype)                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^line 22, in <module>    change_pitch(input_file, output_file, semitones_to_change, nsemitones)ValueError: object too deep for desired array

I want to change the frequency of 'rhodes.wav' into a c4 instead of a d3


Viewing all articles
Browse latest Browse all 15970

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>