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