loop untill cloesd, button AND mouse
This commit is contained in:
parent
7b8e864f5d
commit
400bccfeec
1
.gitignore
vendored
1
.gitignore
vendored
@ -12,3 +12,4 @@ agent-mobile/artimobile/supervisord.pid
|
|||||||
agent-pyter/lag-llama
|
agent-pyter/lag-llama
|
||||||
agent-pyter/google-chrome-stable_current_amd64.deb
|
agent-pyter/google-chrome-stable_current_amd64.deb
|
||||||
web/.node-persist/*
|
web/.node-persist/*
|
||||||
|
agent-mAId/output.wav
|
||||||
|
@ -11,6 +11,7 @@ import pystray
|
|||||||
from pystray import MenuItem as item
|
from pystray import MenuItem as item
|
||||||
from PIL import Image
|
from PIL import Image
|
||||||
import ctypes
|
import ctypes
|
||||||
|
import time
|
||||||
|
|
||||||
# Constants
|
# Constants
|
||||||
API_KEY = "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" # Make sure to use your actual API key
|
API_KEY = "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" # Make sure to use your actual API key
|
||||||
@ -21,7 +22,7 @@ AUTO_START_PATH = os.path.expanduser(r"~\AppData\Roaming\Microsoft\Windows\Start
|
|||||||
client = Groq(api_key=API_KEY)
|
client = Groq(api_key=API_KEY)
|
||||||
|
|
||||||
def record_audio(filename):
|
def record_audio(filename):
|
||||||
# Setup audio recording
|
"""Records audio when BUTTON or mouse button is pressed."""
|
||||||
audio = pyaudio.PyAudio()
|
audio = pyaudio.PyAudio()
|
||||||
stream = audio.open(format=pyaudio.paInt16, channels=1, rate=44100, input=True, frames_per_buffer=1024)
|
stream = audio.open(format=pyaudio.paInt16, channels=1, rate=44100, input=True, frames_per_buffer=1024)
|
||||||
|
|
||||||
@ -29,7 +30,7 @@ def record_audio(filename):
|
|||||||
print("Recording...")
|
print("Recording...")
|
||||||
|
|
||||||
# Record while button or mouse is pressed
|
# Record while button or mouse is pressed
|
||||||
while keyboard.is_pressed(BUTTON) or mouse.is_pressed(button='left'):
|
while keyboard.is_pressed(BUTTON) and mouse.is_pressed(button='left'):
|
||||||
data = stream.read(1024)
|
data = stream.read(1024)
|
||||||
frames.append(data)
|
frames.append(data)
|
||||||
|
|
||||||
@ -47,40 +48,21 @@ def record_audio(filename):
|
|||||||
wave_file.close()
|
wave_file.close()
|
||||||
|
|
||||||
def transcribe_audio(filename):
|
def transcribe_audio(filename):
|
||||||
# Open the audio file
|
"""Transcribes the recorded audio using the Groq Whisper model."""
|
||||||
with open(filename, "rb") as file:
|
with open(filename, "rb") as file:
|
||||||
# Create a transcription of the audio file
|
|
||||||
transcription = client.audio.transcriptions.create(
|
transcription = client.audio.transcriptions.create(
|
||||||
file=(filename, file.read()), # Required audio file
|
file=(filename, file.read()),
|
||||||
model="distil-whisper-large-v3-en", # Required model to use for transcription
|
model="distil-whisper-large-v3-en",
|
||||||
prompt="Specify context or spelling", # Optional
|
prompt="Specify context or spelling",
|
||||||
response_format="json", # Optional
|
response_format="json",
|
||||||
temperature=0.0 # Optional
|
temperature=0.0
|
||||||
)
|
)
|
||||||
|
|
||||||
# Access the transcription text using dot notation
|
|
||||||
return transcription.text
|
return transcription.text
|
||||||
|
|
||||||
def simulate_keypress(text):
|
def simulate_keypress(text):
|
||||||
# Simulate keypress for each character in text
|
"""Simulates typing of transcribed text quickly."""
|
||||||
for char in text:
|
pyautogui.typewrite(text, interval=0.01) # Reduce interval between characters for faster typing
|
||||||
pyautogui.typewrite(char)
|
# pyautogui.press('enter')
|
||||||
pyautogui.press('enter')
|
|
||||||
|
|
||||||
def main():
|
|
||||||
filename = "output.wav"
|
|
||||||
|
|
||||||
print("Press and hold the button or left mouse button to record...")
|
|
||||||
# Wait for button or mouse press
|
|
||||||
while not (keyboard.is_pressed(BUTTON) or mouse.is_pressed(button='left')):
|
|
||||||
pass
|
|
||||||
record_audio(filename)
|
|
||||||
|
|
||||||
print("Transcribing audio...")
|
|
||||||
transcribed_text = transcribe_audio(filename)
|
|
||||||
|
|
||||||
print("Entering text...")
|
|
||||||
simulate_keypress(transcribed_text)
|
|
||||||
|
|
||||||
def add_to_autostart():
|
def add_to_autostart():
|
||||||
"""Registers the app to autostart on login."""
|
"""Registers the app to autostart on login."""
|
||||||
@ -99,26 +81,43 @@ def quit_app(icon):
|
|||||||
|
|
||||||
def setup_tray_icon():
|
def setup_tray_icon():
|
||||||
"""Setup system tray icon and menu."""
|
"""Setup system tray icon and menu."""
|
||||||
# Create an icon image
|
|
||||||
icon_image = Image.new('RGB', (64, 64), color=(255, 0, 0)) # Red icon as an example
|
icon_image = Image.new('RGB', (64, 64), color=(255, 0, 0)) # Red icon as an example
|
||||||
|
|
||||||
# Define menu items for the tray
|
|
||||||
menu = (
|
menu = (
|
||||||
item('Register to Autostart', add_to_autostart),
|
item('Register to Autostart', add_to_autostart),
|
||||||
item('Exit', lambda: quit_app(icon))
|
item('Exit', lambda: quit_app(icon))
|
||||||
)
|
)
|
||||||
|
|
||||||
# Create the tray icon
|
|
||||||
icon = pystray.Icon("my_app", icon_image, menu=pystray.Menu(*menu))
|
icon = pystray.Icon("my_app", icon_image, menu=pystray.Menu(*menu))
|
||||||
|
|
||||||
# Run the tray icon
|
|
||||||
icon.run()
|
icon.run()
|
||||||
|
|
||||||
|
def main_loop():
|
||||||
|
"""Continuously listen for key or mouse press and transcribe audio."""
|
||||||
|
filename = "output.wav"
|
||||||
|
|
||||||
|
while True:
|
||||||
|
print("Waiting for button or mouse press...")
|
||||||
|
|
||||||
|
# Wait for button or mouse press
|
||||||
|
while not (keyboard.is_pressed(BUTTON) or mouse.is_pressed(button='left')):
|
||||||
|
time.sleep(0.1) # Small sleep to avoid busy-waiting
|
||||||
|
|
||||||
|
# Record audio
|
||||||
|
record_audio(filename)
|
||||||
|
|
||||||
|
# Transcribe audio
|
||||||
|
print("Transcribing audio...")
|
||||||
|
transcribed_text = transcribe_audio(filename)
|
||||||
|
|
||||||
|
# Simulate typing the transcribed text
|
||||||
|
print("Typing transcribed text...")
|
||||||
|
simulate_keypress(transcribed_text)
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
# Start the tray icon in a separate thread so it doesn't block the main functionality
|
# Start the tray icon in a separate thread so it doesn't block the main functionality
|
||||||
tray_thread = threading.Thread(target=setup_tray_icon)
|
tray_thread = threading.Thread(target=setup_tray_icon)
|
||||||
tray_thread.daemon = True
|
tray_thread.daemon = True
|
||||||
tray_thread.start()
|
tray_thread.start()
|
||||||
|
|
||||||
# Run the main function
|
# Run the main loop that listens for key or mouse presses in the background
|
||||||
main()
|
main_loop()
|
||||||
|
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user