commit 38687fed6c4c87ebe4b7827d8f65083104104058
parent 9aea55f20ec25642c88307764f49fa2db2b2cd39
Author: Yuval Langer <yuvallangerontheroad@gmail.com>
Date: Thu, 25 Nov 2021 23:10:12 +0200
Add the Python script and changelog.
Diffstat:
3 files changed, 53 insertions(+), 3 deletions(-)
diff --git a/CHANGELOG.md b/CHANGELOG.md
@@ -0,0 +1,10 @@
+## 2021-11-25
+
+Trying to remove the daemonize dependency, but I don't know how to kill the
+speak-ng child process of the shell script.
+
+Also trying to write a clipboard-speaker Python script.
+
+## 2021-11-24
+
+Shell scripts using daemonize, xsel, and speak-ng.
diff --git a/README.md b/README.md
@@ -11,8 +11,15 @@ Not a fancy curiosity but an accessibility tool for people with reading disabili
2. Press the keybinding to start `clipboard-reader`. Your computer is now speaking the stuff in the selection.
3. (optional) Press the other keybinding to start `clipboard-reader-kill` and make computer stop speaking.
+## Changelog:
+
+Have a look at the <a href="CHANGELOG.md">CHANGELOG.md</a> file.
+
## Installation:
-1. Install the infrastructure: `apt install daemonize espeak-ng xsel`
-2. Copy the two executable scripts into your home bin directory: `cp clipboard-speaker clipboard-speaker-kill ~/bin/`
-3. Add the key bindings in `Gnome Settings → Keyboard Shortcuts → All the way down and press the + button`
+1. Install the infrastructure:
+ `apt install daemonize espeak-ng xsel`
+2. Copy the two executable scripts into your home bin directory:
+ `cp clipboard-speaker clipboard-speaker-kill ~/bin/`
+3. Add the key bindings in:
+ `Gnome Settings → Keyboard Shortcuts → All the way down and press the + button`
diff --git a/clipboard-speaker.py b/clipboard-speaker.py
@@ -0,0 +1,33 @@
+#!/usr/bin/env python3
+
+import signal
+import os
+from pathlib import Path
+from subprocess import Popen, PIPE
+
+CLIPBOARD_SPEAKER_PATH = Path.home() / ".clipboard-speaker"
+FIFO_FILE_PATH = CLIPBOARD_SPEAKER_PATH / "fifo"
+PID_FILE_PATH = CLIPBOARD_SPEAKER_PATH / "pid"
+LOCK_FILE_PATH = CLIPBOARD_SPEAKER_PATH / "lock"
+
+if __name__ == "__main__":
+ clipboard_speaker_pid = os.getpid()
+ with open(PID_FILE_PATH, 'w') as pid_file:
+ pid_file.write(str(clipboard_speaker_pid))
+ #with open(FIFO_FILE_PATH, "w") as fifo:
+ # xsel_process = Popen(["xsel", "-p"], stdout=fifo)
+ xsel_process = Popen(["xsel", "-p"], stdout=PIPE)
+ speak_ng_process = Popen(
+ [
+ "speak-ng",
+ '--stdin'
+ ],
+ stdin=xsel_process.stdout,
+ stdout=PIPE ,
+ )
+ def kill(*a):
+ print('kill:', a)
+ speak_ng_process.terminate()
+ signal.signal(signal.SIGHUP, kill)
+ signal.signal(signal.SIGTERM, kill)
+ speak_ng_process.wait()