johnath / beep

beep is a command line tool for linux that beeps the PC speaker
http://www.johnath.com/beep/
GNU General Public License v2.0
185 stars 49 forks source link

Option for typewriter effect when typing within terminal? #18

Open rogerxx opened 3 years ago

rogerxx commented 3 years ago

I've seen quite a few extravagant typewriting sound emulators using ALSA/Pulse for output, but seemingly bloated in my opinion with high resource usage, rather than using simple PC speaker beep. (eg. bucklespring program, but useless for vision impaired as the sounds are emitted upon press and release, more of a cosmetic feature rather than useful feature.)

Is there any method of providing the beep command the option for emulating a typewriter while typing within terminals?

If I'm not mistaken, the process is relatively simple, detect a keyscan press, play beep. I'm pretty sure the code is almost there using "beep -c -f 750 -D 20 -l 5", just needs to detect a keyscan press.

rogerxx commented 3 years ago

Just realized, could pipe /dev/tty for input to beep, without having beep pull in additional libraries.

$ beep -c -f 750 -D 30 -l 30 < /dev/tty

However, beep is only activated on carriage return or '\n', end of line return, instead of after each key press.

Matt-Deacalion commented 5 months ago

You could try this in Bash:

$ while read -n1 -r; do beep -f 750 -D 30 -l 30; done

or zsh:

% while read -k; do beep -f 750 -D 30 -l 30; done
ndim commented 5 months ago

Just realized, could pipe /dev/tty for input to beep, without having beep pull in additional libraries.

$ beep -c -f 750 -D 30 -l 30 < /dev/tty

However, beep is only activated on carriage return or '\n', end of line return, instead of after each key press.

Perhaps beep would need to

if (isatty(STDIN_FILENO)) {
  ...put STDIN_FILENO from cooked mode to raw mode...
}

and then reverse that before the beep program terminates in any way.

ndim commented 5 months ago

Probably a better way to implement key press noises would be in the keystroke processing software stack: Either inside the kernel or as a user space evdev input device driver for keyboard type devices.

A lot of care would need to be taken in that software, as that is also where you would implement a keylogger.