From 92d66fb46c69edd5bb9bed9cdcbb6599afc3bbb1 Mon Sep 17 00:00:00 2001 From: "Max P." Date: Mon, 24 Mar 2025 14:26:24 +0100 Subject: [PATCH] Extracts notification logic into a reusable utility Moves desktop notification functionality to a separate module for better code reuse and maintainability. Updates the main application to use the new utility. --- notify.py | 22 ++++++++++++++++++++++ voice_to_text_tray.py | 22 ++++++++++++++-------- 2 files changed, 36 insertions(+), 8 deletions(-) create mode 100644 notify.py diff --git a/notify.py b/notify.py new file mode 100644 index 0000000..32df16d --- /dev/null +++ b/notify.py @@ -0,0 +1,22 @@ +import subprocess + +def notify(title: str, message: str) -> None: + """ + Sends a desktop notification using the `notify-send` command. + + Args: + title (str): The title of the notification. + message (str): The message content of the notification. + + Raises: + subprocess.CalledProcessError: If the `notify-send` command fails. + + Note: + This function requires the `notify-send` command to be available on the system. + It is typically available on Linux systems with a notification daemon running. + """ + try: + subprocess.run(["notify-send", "-a", "Voice to Text", "-i", "audio-input-microphone", title, message], check=True) + except subprocess.CalledProcessError as e: + print("Fehler beim Benachrichtigen mit 'notify-send'.") + print(e) \ No newline at end of file diff --git a/voice_to_text_tray.py b/voice_to_text_tray.py index 77d720d..890b81c 100755 --- a/voice_to_text_tray.py +++ b/voice_to_text_tray.py @@ -10,19 +10,25 @@ from PyQt5.QtWidgets import QApplication, QSystemTrayIcon, QMenu, QAction from PyQt5.QtGui import QIcon from PyQt5.QtCore import QThread, pyqtSignal from configuration import read_configurations +from notify import notify CONFIGURATION = read_configurations() CURRENT_PRESET = CONFIGURATION["presets"][0] # Default to first preset -def notify(title: str, message: str) -> None: - try: - subprocess.run(["notify-send", "-a", "Voice to Text", "-i", "audio-input-microphone", title, message], check=True) - except subprocess.CalledProcessError as e: - print("Fehler beim Benachrichtigen mit 'notify-send'.") - print(e) - -# === Worker Thread for Whisper + Ollama === class WhisperWorker(QThread): + """ + A PyQt QThread subclass that handles the transcription of audio files using Whisper + and processes the result with Ollama. The final output is copied to the clipboard + and a signal is emitted upon completion. + Signals: + finished (pyqtSignal): Emitted with the formatted transcription result as a string + when the process is successfully completed. + Methods: + run(): + Executes the transcription process using Whisper, sends the result to Ollama + for further processing, and copies the final output to the clipboard. Handles + errors at various stages and provides notifications for failures. + """ finished = pyqtSignal(str) def run(self):