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.
This commit is contained in:
2025-03-24 14:26:24 +01:00
parent 36bad26e91
commit 92d66fb46c
2 changed files with 36 additions and 8 deletions

22
notify.py Normal file
View File

@@ -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)

View File

@@ -10,19 +10,25 @@ from PyQt5.QtWidgets import QApplication, QSystemTrayIcon, QMenu, QAction
from PyQt5.QtGui import QIcon from PyQt5.QtGui import QIcon
from PyQt5.QtCore import QThread, pyqtSignal from PyQt5.QtCore import QThread, pyqtSignal
from configuration import read_configurations from configuration import read_configurations
from notify import notify
CONFIGURATION = read_configurations() CONFIGURATION = read_configurations()
CURRENT_PRESET = CONFIGURATION["presets"][0] # Default to first preset 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): 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) finished = pyqtSignal(str)
def run(self): def run(self):