PyMusic Instrument
1.0.0
مكتبة Python التي يمكن أن تولد الأصوات التي تلعبها الآلات بشكل رئيسي الجيتار والبيانو. ويستخدم Pyaudio كما تبعية.
تحتاج فقط إلى معرفة بناء جملة Python الأساسي لاستخدام هذه المكتبة.
إذا كنت في جهازك في السابق لم تقم بتثبيت Pyaudio أبدًا ، فقم بذلك:
sudo apt-get install libasound-dev portaudio19-dev libportaudio2 libportaudiocpp0
قم بتنزيل الثنائيات من هنا
الآن افعل هذا
pip install PyAudio‑0.2.11‑cp39‑cp39m‑win_amd64.whl
ثم
python3 -m pip install PyMusic-Instrument
لعب الملاحظات البيانو.
from Instrument import Instrument
piano = Instrument ( bit_rate = 44100 )
piano . record_key ( 52 , duration = 0.3 ) # C5
piano . record_chord ([( 52 , 56 , 61 )], duration = 0.3 ) # C5 E5 A5
piano . play ()
piano . close () # Terminates PyAudioالعزف على سلاسل الغيتار.
guitar = Instrument ( 44100 )
guitar . record_key ( 25 , duration = 0.5 ) # A
guitar . play ()
guitar . clear_sample () # clears the sample
guitar . close ()يمكنك إلقاء نظرة هنا على الأرقام الرئيسية للتردد المقابل.
بدلاً من ذلك ، يمكنك أيضًا رسم الرسم البياني
import matplotlib . pyplot as plt
key_colors = { 40 : [ "red" , 1 ], 42 : [ "blue" , 1 ], 44 : [ "green" , 1 ], 45 : [ "gray" , 1 ],
47 : [ "orange" , 1 ], 35 : [ "purple" , 1 ], (( 51 , 56 , 61 ),): [ 'black' , 1 ]}
# piano.graphing sample contains key, time take as an array, wave equation as an array.
for key , time , wave in piano . graphing_sample :
if key_colors [ key ][ 1 ]:
plt . plot ( time , wave , label = key , color = key_colors [ key ][ 0 ])
key_colors [ key ][ 1 ] = 0
else :
plt . plot ( time , wave , color = key_colors [ key ][ 0 ])
plt . show ()أو الرماية
import librosa . display
amplitude = librosa . stft ( piano . sample )
db = librosa . amplitude_to_db ( abs ( amplitude ))
plt . figure ( figsize = ( 14 , 5 ))
librosa . display . specshow ( db , sr = 44100 , x_axis = 'time' , y_axis = 'hz' )
plt . colorbar ()
plt . show ()https://pymusic-instrument.readthedocs.io/en/latest/