From 0a808a84715f37410cac9d9589b9cf54d33f5a69 Mon Sep 17 00:00:00 2001 From: "Max P." Date: Wed, 30 Apr 2025 15:18:22 +0200 Subject: [PATCH] feat(voice_to_text_tray): add journal saving for transcription results - Add functionality to save transcription results to a journal file. - Use current date and time to organize entries in the journal. - Retain clipboard copy behavior for non-journal modes. - Enhance error handling for journal writing operations. Signed-off-by: Max P. --- src/pyvtt/voice_to_text_tray.py | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/src/pyvtt/voice_to_text_tray.py b/src/pyvtt/voice_to_text_tray.py index 5f5493a..f2bf2ca 100755 --- a/src/pyvtt/voice_to_text_tray.py +++ b/src/pyvtt/voice_to_text_tray.py @@ -1,3 +1,4 @@ +import datetime import sys import subprocess import os @@ -95,12 +96,25 @@ class WhisperWorker(QThread): print("Kein Ollama Prompt angegeben, nur Whisper Ergebnis verwendet.") # Ergebnis ins Clipboard kopieren - try: - subprocess.run(["wl-copy"], input=formatted_result.encode(), check=True) - except subprocess.CalledProcessError as e: - print(f"Clipboard Fehler: {e}") - notify("Fehler", "Ein Fehler beim Kopieren des Ergebnisses ist aufgetreten!") - return + if CURRENT_PRESET["mode"] == "journal": + today = datetime.date.today().strftime("%Y.%m.%d") + journal_path = os.path.join(CONFIGURATION["journal_path"], f"{today} - {CURRENT_PRESET['journal_name']}.md") + now = datetime.datetime.now().strftime("%H:%M") + try: + with open(journal_path, "a") as f: + f.write(f"## {now}\n") + f.write(f"{formatted_result}\n\n") + except Exception as e: + print(f"Journal Fehler: {e}") + notify("Fehler", "Ein Fehler beim Schreiben ins Journal ist aufgetreten!") + return + else: + try: + subprocess.run(["wl-copy"], input=formatted_result.encode(), check=True) + except subprocess.CalledProcessError as e: + print(f"Clipboard Fehler: {e}") + notify("Fehler", "Ein Fehler beim Kopieren des Ergebnisses ist aufgetreten!") + return notify("Spracherkennung", "Transkription abgeschlossen!") play_sound()