pi_pico_lab/siwatlib/sound.py

28 lines
785 B
Python
Raw Normal View History

2022-04-08 18:10:31 +00:00
from pysine import pysine
import winsound
import threading
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()