Created
March 14, 2022 10:20
-
-
Save batica81/cf0b8e4f2d3804ea0b95c7d2d2434fd7 to your computer and use it in GitHub Desktop.
Plays a tone when some of specified keys are pressed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# App plays a tone when some of specified keys are pressed. It works in the background as well. | |
# Best used with two sound cards (for Morse practice Zoom sessions for example). | |
# TODO: Add cosine shaping and remove clicking noise. | |
# Requirements: | |
# pip3 install pynput | |
# pip3 install pysinewave | |
from time import sleep | |
from pynput import keyboard | |
from pysinewave import SineWave | |
sinewave = SineWave(pitch = 17, decibels = -30) # Set to 692 Hz. Play with these two parameters for different tone. | |
def on_press(key): | |
if (str(key) in ["Key.ctrl_r", "Key.space", "Key.right"]): | |
sinewave.play() | |
def on_release(key): | |
sinewave.stop() | |
if key == keyboard.Key.esc: | |
# Stop listener | |
return False | |
# Collect events until released | |
with keyboard.Listener( | |
on_press=on_press, | |
on_release=on_release) as listener: | |
listener.join() | |
sleep(0.01) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment