Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pitch_shift() takes 1 positional argument but 2 positional arguments (and 1 keyword-only argument) were given #31

Open
wei17hao10 opened this issue Aug 24, 2023 · 4 comments · May be fixed by #32

Comments

@wei17hao10
Copy link

(v3_8) PS C:\Users\WeiHao\PycharmProjects\pianoputer> pianoputer
pygame 2.5.1 (SDL 2.28.2, Python 3.8.17)
Hello from the pygame community. https://www.pygame.org/contribute.html
Generating samples for each key
Transposing note 1 out of 43 for Key.BACKQUOTE
Traceback (most recent call last):
File "C:\Users\WeiHao.conda\envs\v3_8\lib\runpy.py", line 194, in _run_module_as_main
return _run_code(code, main_globals, None,
File "C:\Users\WeiHao.conda\envs\v3_8\lib\runpy.py", line 87, in run_code
exec(code, run_globals)
File "C:\Users\WeiHao.conda\envs\v3_8\Scripts\pianoputer.exe_main
.py", line 7, in
File "C:\Users\WeiHao.conda\envs\v3_8\lib\site-packages\pianoputer\pianoputer.py", line 345, in play_pianoputer
key_sounds = get_or_create_key_sounds(
File "C:\Users\WeiHao.conda\envs\v3_8\lib\site-packages\pianoputer\pianoputer.py", line 102, in get_or_create_key_sounds
sound = librosa.effects.pitch_shift(y, sr, n_steps=tone)
TypeError: pitch_shift() takes 1 positional argument but 2 positional arguments (and 1 keyword-only argument) were given

@yoyoberenguer
Copy link
Contributor

yoyoberenguer commented Sep 14, 2023

Hello,
1 - Find where the files have been installed. The easiest way to find the project folder is currently to de-install pianoputer, without actually removing it (press no)

image

As shown in the image above the project folder will be displayed.
use a command prompt to go to that location
In this example it will be something like c:\users.....\appdata\roaming\python\python311\scripts
This folder will be different for each users and the location might also be in the window Program file folder depends if
you installed Python for all users or not.

So change the path accordingly

C:\>cd c:\users\yoyob\appdata\roaming\python\python311\scripts\

2 - type the following to get to the source file

cd ../site-packages/pianoputer

image

Once you are in the right folder and can see the file pianoputer.py
edit the file with Python or any other text editor and do the following changes
e.g:

notepad pianoputer.py

At line 103 and line 106 in file pianoputer.py
Change

            if channels == 1:
                sound = librosa.effects.pitch_shift(y, sr, n_steps=tone)
            else:
                new_channels = [
                    librosa.effects.pitch_shift(y[i], sr, n_steps=tone)
                    for i in range(channels)
                ]

to

             if channels == 1:
                print(y, len(y))
                sound = librosa.effects.pitch_shift(y=y, sr=sr, n_steps=tone)
            else:
                new_channels = [
                    librosa.effects.pitch_shift(y=y[i], sr=sr, n_steps=tone)
                    for i in range(channels)
                ]
  • Don't forget to save after changing the lines above (CTRL+S)

Then run the source code

python pianoputer.py 

Once this has been changed into the project source code and reloaded to PIP pianoputer will works without applying this fix

@zyugyzarc zyugyzarc linked a pull request Jan 17, 2024 that will close this issue
@KrishnaTeamzest
Copy link

def pitch(data, sampling_rate, pitch_factor=0.7):
return librosa.effects.pitch_shift(data, sampling_rate, pitch_factor=pitch_factor)

def get_features(path):
#set the duration and offset
#librosa.load takes audio file converts to array and returns array of audio file with its sampling rate
data, sample_rate = librosa.load(path, duration=2.5, offset=0.6)

#get audio features without augmentation
res1 = extract_features(data,sample_rate)
result = np.array(res1)

#get audio features with noise
noise_data = noise(data)
res2 = extract_features(noise_data,sample_rate)
result = np.vstack((result, res2))

#get audio features with stretching and pitching
#rate = 0.8
new_data = stretch(data)
data_stretch_pitch = pitch(new_data, sample_rate)
res3 = extract_features(data_stretch_pitch,sample_rate)
result = np.vstack((result, res3))

return result

when i call this function from get_features this gives the error "TypeError: pitch_shift() takes 1 positional argument but 2 were given"
Anyone plz help

@yoyoberenguer
Copy link
Contributor

hello, can you provide the method extract_features?
This method is missing from your code and I cannot reproduce without it
Also worse changing the method from

def pitch(data, sampling_rate, pitch_factor=0.7):
     return librosa.effects.pitch_shift(data, sampling_rate, pitch_factor=pitch_factor)

to

def pitch(data, sampling_rate, pitch_factor=0.7):
    return librosa.effects.pitch_shift(data, sampling_rate, n_steps=pitch_factor)

Kind Regards

@KrishnaTeamzest
Copy link

KrishnaTeamzest commented Jun 24, 2024 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants