python-clipboard-speaker

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

commit 790a58e36e3bebd4eb9450fe9cc29db1ed3d7157
parent ef4ab2d3396004ad0b7467a138b52fd9a95aaab8
Author: Yuval Langer <yuvallangerontheroad@gmail.com>
Date:   Fri, 26 Nov 2021 16:10:19 +0200

Remove PID file at the end and add a configuration file for words-per-minute.

Diffstat:
Mclipboard-speaker.py | 23++++++++++++++++++++++-
1 file changed, 22 insertions(+), 1 deletion(-)

diff --git a/clipboard-speaker.py b/clipboard-speaker.py @@ -4,15 +4,34 @@ import os from pathlib import Path from subprocess import Popen, PIPE +DEFAULT_WORDS_PER_MINUTE = "175" + CLIPBOARD_SPEAKER_PATH = Path.home() / ".clipboard-speaker" PID_FILE_PATH = CLIPBOARD_SPEAKER_PATH / "pid" +WORDS_PER_MINUTE_PATH = CLIPBOARD_SPEAKER_PATH / "words-per-minute" + + +def get_words_per_minute() -> str: + if not WORDS_PER_MINUTE_PATH.exists(): + with WORDS_PER_MINUTE_PATH.open("w") as words_per_minute_file: + words_per_minute_file.write(DEFAULT_WORDS_PER_MINUTE) + return DEFAULT_WORDS_PER_MINUTE + + with WORDS_PER_MINUTE_PATH.open("r") as words_per_minute_file: + words_per_minute = words_per_minute_file.read().strip() + + return words_per_minute + + if __name__ == "__main__": + words_per_minute = get_words_per_minute() + if not PID_FILE_PATH.exists(): xsel_process = Popen(["xsel", "-p"], stdout=PIPE) speak_ng_process = Popen( - ["speak-ng", "--stdin"], + ["speak-ng", f"-s {words_per_minute}", "--stdin"], stdin=xsel_process.stdout, stdout=PIPE, ) @@ -24,3 +43,5 @@ if __name__ == "__main__": speak_ng_process.wait() except KeyboardInterrupt as e: os.remove(PID_FILE_PATH) + + os.remove(PID_FILE_PATH)