Coder Social home page Coder Social logo

zulko / pianoputer Goto Github PK

View Code? Open in Web Editor NEW
320.0 320.0 92.0 2.75 MB

Use your computer keyboard as a "piano".

Home Page: http://zulko.github.io/blog/2014/03/29/soundstretching-and-pitch-shifting-in-python/

License: Other

Python 96.72% Makefile 3.28%

pianoputer's People

Contributors

jo-m avatar jtyr avatar schneiderfelipe avatar spacether avatar xpika avatar yoyoberenguer avatar zulko avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pianoputer's Issues

PYGAME 2 , SDL2: fix mixer errors, mixer.init(..., allowchanges=0) #861

When starting the program with PYGAME 2.00 version, I had the following exception:

Traceback (most recent call last):
File "C:\Users\yoann\AppData\Local\Programs\Python\Python36\lib\site-packages\pygame\sndarray.py", line 94, in make_sound
return numpysnd.make_sound(array)
AttributeError: 'NoneType' object has no attribute 'make_sound'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "pianoputer.py", line 129, in
main()
File "pianoputer.py", line 103, in main
key_sound = dict(zip(keys, sounds))
File "C:\Users\yoann\AppData\Local\Programs\Python\Python36\lib\site-packages\pygame\sndarray.py", line 97, in make_sound
return numpysnd.make_sound(array)
File "C:\Users\yoann\AppData\Local\Programs\Python\Python36\lib\site-packages\pygame_numpysndarray.py", line 74, in make_sound
return mixer.Sound(array=array)
ValueError: Array must be 2-dimensional for stereo mixer

This issue is related to PYGAME case : SDL2: fix mixer errors, mixer.init(..., allowchanges=0) #861

Suggestion to solve this issue (for both version of the program)


for single track sound


if int(pygame.version.ver[0]) >= 2:
    pygame.mixer.init(fps, -16, 1, 2048, allowedchanges=0)
else:
  pygame.mixer.init(fps, -16, 1, 2048)

for stereo sound


if int(pygame.version.ver[0]) >= 2:
    pygame.mixer.init(fps, -16, 2, 2048, allowedchanges=0)
else:
    pygame.mixer.init(fps, -16, 2, 2048)

video effect when playing pianoputer

@Zulko @spacether I made a version of pianoputer with an animated fire processed in real time.
This is not essential, but with the graphic version, the window look a bit more appealing.
The fire effect is base on a CYTHON algorithm that provide C performance to PYGAME and the animation will run on most computer over 100 fps (I am achieving a 200 FPS on mine).
The only downside would be the compilation of the CYTHON code for every version of python interpreter and CYTHON would be required in PYPI packages and added as a requirement in the project.
In the mean time, the easiest solution would be to build an executable file that will install pianoputer on window.

Just a suggestion, but if you are interested please check into https://github.com/yoyoberenguer/pianoputer
Download the latest version ver 1.0.1 (exe) and watch a cosy fire

Kind Regards

Can't save KB file

revision e974a49

Traceback (most recent call last):
  File "make_kb_file.py", line 20, in <module>
    print ("Done. you have a new keyboard configuration file: %s"%skb_file)
NameError: name 'skb_file' is not defined

AttributeError: 'Event' object has no attribute 'key'

I've found this error and I did fix it.
I put the lines 293-296 key = keyboard.get ... in before the line 291 elif event.key ...
the error is that you called the function before you defined it. Hope that helped.

Idea: Try mapping the keys to a stenography machine layout.

Sounds weird but I think there'd be a better reception to this -- especially if you knew how one worked. the idea is to be able to press all the buttons on the machine at once. So, you could arguably get better playing power from the layout.

Harpsichord more than a PianoForte??

Hi
Very interesting project! But looking at your project, isn't it more of an Harpsichord than a piano that we are creating?
I mean, it doesn't seem to record the speed with which we are typing each key (which determine the loudness on a normal piano).
Would it be possible to take into account this type of information thanks to your program?

Nothing happens?

I tried opening both .py files and it opens for a split second, then closes. I have python 2.7.15 installed.. should I have 3.7? What am I doing wrong?
EDIT: Nevermind, I didn't have the requirements

Can i install this with python 3.11?

Can i install this with python 3.11? im not very skilled with computers, the only way is with python 3.6-3.7 higher? is there a way to run this or install this with python 3.11?

Cannot build/run from source

Good day to you,

Where do you find the package keyboardlayout (no included in the source code)

I tried pip install keyboardlayout but cannot find it anywhere (is it on Pypi?)

import keyboardlayout as kl
ModuleNotFoundError: No module named 'keyboardlayout'

Kind Regards

Running in background

Hi, thank you for this app, it is extremely useful, I like it very much!
I would like to use it in "background" so I can create/use sounds(my piano) also when I'm typing in other windows (i.e. when pygame window is not focused...)
Do you have idea if this is possible maybe?
I'm really not much into python, that's why I ask. Thanks for any reply!
BR, Milan

Publishing to pypi

@Zulko do you want to do it or do you want me to?
We have:

make testpypi
make pypi

in our Makefile to allow for easy publishing and the README.md will be used as the package description in pypi.

Unable to Transpond Sound File

Tried running this on macOS 10.12.3, python 2.7.13, scipy 0.18.1, numpy 1.12.0, pygame 1.9.3

Got the following error:

$ python pianoputer.py 
Transponding sound file... Traceback (most recent call last):
  File "pianoputer.py", line 126, in <module>
    main()
  File "pianoputer.py", line 90, in main
    transposed_sounds = [pitchshift(sound, n) for n in tones]
  File "pianoputer.py", line 49, in pitchshift
    stretched = stretch(snd_array, 1.0/factor, window_size, h)
  File "pianoputer.py", line 22, in stretch
    result = np.zeros(len(snd_array) / factor + window_size)
TypeError: 'float' object cannot be interpreted as an index

请教您键盘布局图是怎么绘制的?(Ask you how to draw the keyboard layout)

我用的键盘布局略有不同,想尝试绘制相合的键盘布局图且不影响程序的正常运行,另外,想尝试按键动作与用户界面上的键盘图互动,最好能够支持触控动作,方便在触控屏幕上运行,而且,可以尝试通过触控点的面积大小控制音量强弱,通过触摸动作控制音高等表现形式

value error

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.

License

Is it possible to change license to some open source one? For example, gnu, apache2, mit?

Another sound file cannot be used

This sound file, although having about the same length and similar structure, cannot be opened. I'm not sure what's the reason. (Audacity doesn't support other bitrates, if that's the matter.)
https://dl.dropboxusercontent.com/u/6721960/2014/throat.wav.zip

Traceback (most recent call last):
  File "pianoputer.py", line 47, in <module>
    transposed_sounds = [pitchshift(bowl_sound, n) for n in tones]
  File "pianoputer.py", line 39, in pitchshift
    stretched = stretch(snd_array, 1.0/factor, window_size, h) 
  File "pianoputer.py", line 22, in stretch
    s1 =  np.fft.fft(hanning_window * a1)
ValueError: operands could not be broadcast together with shapes (8192) (8192,2) 

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

(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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.