guile-clipboard-speaker

Accessibility tool that reads the contents of your clipboard buffer. Meant to be run with keybindings / shortcuts.
git clone https://kaka.farm/~git/guile-clipboard-speaker
Log | Files | Refs | README | LICENSE

commit 0f7111f5ce2a1e004d53d1aec4b365dc174d51ce
parent 2b28fcaea2d53f150c8cd94c8d97da9a8f4f954c
Author: Yuval Langer <yuval.langer@gmail.com>
Date:   Tue, 24 Dec 2024 01:43:09 +0200

Do some un-verticalising, rename stuff into a "input" or "output" port nomenclature, and use `write` instead of `display` for debug print.

Diffstat:
Mclipboard-speaker.scm | 54++++++++++++++++++++----------------------------------
1 file changed, 20 insertions(+), 34 deletions(-)

diff --git a/clipboard-speaker.scm b/clipboard-speaker.scm @@ -63,7 +63,7 @@ (define (dp x) ;; Debug print, but it's just like the identity procedure. - (display x) (newline) + (write x) (newline) x) (define (debug-notify-send x) @@ -232,28 +232,20 @@ (mkfifo fifo-file-path #o600)) - (let* ((fifo-port-write - (open-file fifo-file-path - "wl+")) - (fifo-port-read - (open-file fifo-file-path - "rl+")) - (flags (fcntl fifo-port-read - F_GETFL))) - (fcntl fifo-port-read - F_SETFL - (logior O_NONBLOCK - flags)) - (values fifo-port-read fifo-port-write))) - - (define (espeak-loop fifo-read-port words-per-minute) + (let* ((fifo-output-port (open-file fifo-file-path "wl+")) + (fifo-input-port (open-file fifo-file-path "rl+")) + (flags (fcntl fifo-input-port F_GETFL))) + (fcntl fifo-input-port F_SETFL (logior O_NONBLOCK flags)) + (values fifo-input-port fifo-output-port))) + + (define (espeak-loop fifo-input-port words-per-minute) (let-values (((from-espeak-ng to-espeak-ng pipeline-pids) (pipeline (list (list "espeak-ng" "-s" (number->string words-per-minute)))))) (set! *espeak-ng-pid* (match-let (((pid) pipeline-pids)) pid)) - (let loop ((text-to-speak (get-line fifo-read-port))) + (let loop ((text-to-speak (get-line fifo-input-port))) (format #t "Server received: ~A\n" text-to-speak) (put-string to-espeak-ng text-to-speak) @@ -266,7 +258,7 @@ ;; silent. Please someone explain this to me. (force-output to-espeak-ng) - (loop (get-line fifo-read-port))))) + (loop (get-line fifo-input-port))))) (define (make-pipes buffering-type) (let ((pipes (pipe))) @@ -277,8 +269,7 @@ (define (kill-server options) (cond - ((file-exists? (config:option-ref options - 'lock-file-path)) + ((file-exists? (config:option-ref options 'lock-file-path)) (let ([pid (get-pid-of-file-locking-process options)]) (cond ((number? pid) @@ -295,37 +286,32 @@ (define (main args) (let ((options (config:getopt-config-auto args config))) - (when (config:option-ref options - 'kill) + (when (config:option-ref options 'kill) (kill-server options)) ;; Make / open read and write fifo files. - (let-values (((fifo-r fifo-w) - (make-fifo-ports (config:option-ref options - 'fifo-file-path)))) + (let-values (((fifo-input-port fifo-output-port) + (make-fifo-ports (config:option-ref options 'fifo-file-path)))) (let ((clipboard-output - (read-clipboard (config:option-ref options - 'clipboard-type)))) + (read-clipboard (config:option-ref options 'clipboard-type)))) (format #t "Client sends: ~A~%" clipboard-output) ;; Write clipboard contents into the FIFO file for the TTS server to ;; read. - (put-string fifo-w - clipboard-output)) + (put-string fifo-output-port clipboard-output)) ;; XXX: These ports are line buffered. Always write to ports with ;; a newline at their end if you want the other side to read them ;; now. - (put-char fifo-w #\newline) + (put-char fifo-output-port #\newline) ;; XXX: We don't need to write to FIFO anymore. This will make sure ;; the message passes through. Please someone explain this to me. - (close-port fifo-w) + (close-port fifo-output-port) ;; Try to lock the lock file. (let ((lock-file-port - (open-file-locked (config:option-ref options - 'lock-file-path)))) + (open-file-locked (config:option-ref options 'lock-file-path)))) (when lock-file-port ;; If we have the lock, we're the speaker server. @@ -341,7 +327,7 @@ (kill *espeak-ng-pid* received-signal)) (exit EXIT_SUCCESS))) - (espeak-loop fifo-r + (espeak-loop fifo-input-port (config:option-ref options 'words-per-minute))) (exit EXIT_SUCCESS)))))))