try to fix config;

exe build config (spec)
This commit is contained in:
Dobromir Popov 2024-09-10 14:33:10 +03:00
parent b6741716ff
commit 452561fb5b
5 changed files with 61 additions and 12 deletions

1
.gitignore vendored
View File

@ -14,3 +14,4 @@ agent-pyter/google-chrome-stable_current_amd64.deb
web/.node-persist/*
agent-mAId/output.wav
agent-mAId/build/*
agent-mAId/dist/main.exe

View File

@ -3,6 +3,7 @@
"kb_key": "ctrl",
"mouse_btn": "left",
"model": "distil-whisper-large-v3-en",
"language":"en" // whisper-large-v3 or distil-whisper-large-v3-en
"language":"en", // whisper-large-v3 or distil-whisper-large-v3-en
"action": "type" //type,copy
}

View File

@ -15,12 +15,44 @@ import io
import time
import json5
import wave
import pyperclip
# # Load configuration from config.json
DEFAULT_CONFIG = {
"kb_key": "ctrl",
"mouse_btn": "left",
"model": "distil-whisper-large-v3-en",
"language": "en", # whisper-large-v3 or distil-whisper-large-v3-en
"action": "type" # type, copy
}
# Load configuration from config.json
def load_config():
"""Load the configuration file, adjusting for PyInstaller's temp path when bundled."""
config = DEFAULT_CONFIG.copy() # Start with default configuration
try:
# Determine if the script is running as a PyInstaller bundle
if getattr(sys, 'frozen', False):
# If running in a bundle, use the temp path where PyInstaller extracts files
config_path = os.path.join(sys._MEIPASS, 'config.json')
else:
# If running in development (normal execution), use the local directory
config_path = os.path.join(os.path.dirname(__file__), 'config.json')
print('Trying to load config from:', config_path)
with open(config_path, 'r') as config_file:
return json5.load(config_file)
loaded_config = json5.load(config_file)
# Update the default config with any values from config.json
config.update(loaded_config)
except FileNotFoundError as ex:
print("Config file not found, using defaults." + ex.strerror)
except json5.JSONDecodeError as ex:
print("Error decoding config file, using defaults." + ex.msg)
except Exception as e:
print(f"Unexpected error while loading config: {e}, using defaults.")
return config
# Load the config
config = load_config()
@ -29,6 +61,7 @@ API_KEY = config['api_key']
KB_KEY = config['kb_key']
MOUSE_BTN = config['mouse_btn']
MODEL = config['model']
POST_TRANSCRIBE = config['action']
# Constants
AUTO_START_PATH = os.path.expanduser(r"~\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup") # For autostart
@ -90,7 +123,7 @@ def transcribe_audio(memory_stream):
transcription = client.audio.transcriptions.create(
file=('audio.wav', memory_stream),
model=MODEL,
prompt="Specify context or spelling",
prompt="Transcribe the following audio",
language=config['language'],
response_format="json",
temperature=0.0
@ -159,9 +192,14 @@ def main_loop():
print("Transcribing audio...")
transcribed_text = transcribe_audio(memory_stream)
if POST_TRANSCRIBE == "type":
# Simulate typing the transcribed text
print("Typing transcribed text...")
simulate_keypress(transcribed_text)
elif POST_TRANSCRIBE == "copy":
# Copy the transcribed text to clipboard
pyperclip.copy(transcribed_text)
print("Transcribed text copied to clipboard.")
if __name__ == "__main__":
# Start the tray icon in a separate thread so it doesn't block the main functionality

View File

@ -1,3 +1,10 @@
# to install as an app:
<!-- # to install as an app: -->
pip install pyinstaller
pyinstaller --onefile main.py
pyinstaller main.spec
<!-- to generate reqs.txt -->
pipreqs .
<!-- or -->
pip freeze > requirements.txt

View File

@ -1,7 +1,9 @@
#> pipreqs .
groq==0.11.0
json5==0.9.25
keyboard==0.13.5
mouse==0.7.1
Pillow==10.4.0
PyAudio==0.2.14
PyAutoGUI==0.9.54
pyperclip==1.9.0
pystray==0.19.5