try to fix config;
exe build config (spec)
This commit is contained in:
parent
b6741716ff
commit
452561fb5b
1
.gitignore
vendored
1
.gitignore
vendored
@ -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
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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():
|
||||
config_path = os.path.join(os.path.dirname(__file__), 'config.json')
|
||||
with open(config_path, 'r') as config_file:
|
||||
return json5.load(config_file)
|
||||
"""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:
|
||||
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)
|
||||
|
||||
# Simulate typing the transcribed text
|
||||
print("Typing transcribed text...")
|
||||
simulate_keypress(transcribed_text)
|
||||
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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user