refactor(voice_to_text_tray): improve configuration handling
- Replace direct usage of global configuration dictionaries with local variables for better readability and maintainability. - Update all references to use the newly introduced local variables. Signed-off-by: Max P. <Mail@MPassarello.de>
This commit is contained in:
@@ -32,15 +32,18 @@ class WhisperWorker(QThread):
|
||||
finished = pyqtSignal(str)
|
||||
|
||||
def run(self):
|
||||
CURENT_CONFIGURATION_LOCALE = CONFIGURATION
|
||||
CURRENT_PRESET_LOCALE = CURRENT_PRESET
|
||||
|
||||
try:
|
||||
# Whisper ausführen
|
||||
whisper_cmd = [
|
||||
CONFIGURATION["whisper_path"],
|
||||
"-m", CURRENT_PRESET["whisper_model"],
|
||||
"-f", CONFIGURATION["audio_file"],
|
||||
"-l", CURRENT_PRESET["language"],
|
||||
CURENT_CONFIGURATION_LOCALE["whisper_path"],
|
||||
"-m", CURRENT_PRESET_LOCALE["whisper_model"],
|
||||
"-f", CURENT_CONFIGURATION_LOCALE["audio_file"],
|
||||
"-l", CURRENT_PRESET_LOCALE["language"],
|
||||
"-otxt",
|
||||
"-of", CONFIGURATION["output_file"].replace(".txt", "")
|
||||
"-of", CURENT_CONFIGURATION_LOCALE["output_file"].replace(".txt", "")
|
||||
]
|
||||
try:
|
||||
subprocess.run(whisper_cmd, check=True)
|
||||
@@ -50,7 +53,7 @@ class WhisperWorker(QThread):
|
||||
return
|
||||
|
||||
try:
|
||||
with open(CONFIGURATION["output_file"], "r") as f:
|
||||
with open(CURENT_CONFIGURATION_LOCALE["output_file"], "r") as f:
|
||||
raw_result = "\n".join(line.strip() for line in f.readlines())
|
||||
except Exception as e:
|
||||
print(f"Datei Fehler: {e}")
|
||||
@@ -60,24 +63,24 @@ class WhisperWorker(QThread):
|
||||
print("Whisper Transkript erhalten.")
|
||||
|
||||
# --- An Ollama schicken ---
|
||||
if CURRENT_PRESET["ollama"] != "disable":
|
||||
if isinstance(CURRENT_PRESET["ollama_prompt"], list):
|
||||
prompt = "\n".join(CURRENT_PRESET["ollama_prompt"])
|
||||
if CURRENT_PRESET_LOCALE["ollama"] != "disable":
|
||||
if isinstance(CURRENT_PRESET_LOCALE["ollama_prompt"], list):
|
||||
prompt = "\n".join(CURRENT_PRESET_LOCALE["ollama_prompt"])
|
||||
else:
|
||||
prompt = CURRENT_PRESET["ollama_prompt"]
|
||||
prompt = CURRENT_PRESET_LOCALE["ollama_prompt"]
|
||||
|
||||
payload = {
|
||||
"model": CURRENT_PRESET["ollama_model"],
|
||||
"model": CURRENT_PRESET_LOCALE["ollama_model"],
|
||||
"messages": [
|
||||
{"role": "system", "content": prompt},
|
||||
{"role": "user", "content": raw_result}
|
||||
],
|
||||
"options": {
|
||||
"num_ctx": CURRENT_PRESET["ollama_context"]
|
||||
"num_ctx": CURRENT_PRESET_LOCALE["ollama_context"]
|
||||
},
|
||||
"stream": False
|
||||
}
|
||||
ollama_endpoint = f"{CONFIGURATION['ollama_url']}:{CONFIGURATION['ollama_port']}/api/chat"
|
||||
ollama_endpoint = f"{CURENT_CONFIGURATION_LOCALE['ollama_url']}:{CURENT_CONFIGURATION_LOCALE['ollama_port']}/api/chat"
|
||||
response = requests.post(ollama_endpoint, json=payload)
|
||||
|
||||
try:
|
||||
@@ -96,14 +99,14 @@ class WhisperWorker(QThread):
|
||||
print("Kein Ollama Prompt angegeben, nur Whisper Ergebnis verwendet.")
|
||||
|
||||
# Ergebnis ins Clipboard kopieren
|
||||
if CURRENT_PRESET.get("mode") == "journal":
|
||||
if CURRENT_PRESET_LOCALE.get("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")
|
||||
journal_path = os.path.join(CURENT_CONFIGURATION_LOCALE["journal_path"], f"{today} - {CURRENT_PRESET_LOCALE['journal_name']}.md")
|
||||
now = datetime.datetime.now().strftime("%H:%M:%S")
|
||||
if not os.path.exists(journal_path):
|
||||
try:
|
||||
with open(journal_path, "w") as f:
|
||||
f.write(f"# {CURRENT_PRESET['journal_name']} - {today}\n\n")
|
||||
f.write(f"# {CURRENT_PRESET_LOCALE['journal_name']} - {today}\n\n")
|
||||
except Exception as e:
|
||||
print(f"Journal Erstellungsfehler: {e}")
|
||||
notify("Fehler", "Ein Fehler beim Erstellen des Journals ist aufgetreten!")
|
||||
|
Reference in New Issue
Block a user