pi_pico_lab/siwatlib/sound.py

42 lines
1.2 KiB
Python

from pysine import pysine
import winsound
import threading
from playsound import playsound
import os
MODE = 'pysine'
global __beeper__
def __beeper_therad__(frequency: float, duration: float):
if MODE == 'winsound':
winsound.Beep(frequency=int(frequency), duration=int(duration*1000))
elif MODE == 'pysine':
pysine.sine(frequency=frequency,duration=duration)
__beeper__ = threading.Thread(target=__beeper_therad__,
kwargs={'frequency': 0, 'duration': 0}
)
def beep(frequency: float, duration: float):
global __beeper__
if not __beeper__.is_alive():
__beeper__ = threading.Thread(target=__beeper_therad__,
kwargs={'frequency': frequency, 'duration': duration}
)
__beeper__.start()
#TODO Tune the piano
def __piano_key_thread__(note: str):
note = format(note,'02')
soundfile = os.path.dirname(__file__)+'\\piano_sample\\key'+note+'.mp3'
print(soundfile)
playsound(soundfile)
def piano_key(note: str):
threading.Thread(target=__piano_key_thread__,
kwargs={'note': note}
).start()