working software
This commit is contained in:
commit
9a800bb839
7 changed files with 907 additions and 0 deletions
65
main.py
Normal file
65
main.py
Normal file
|
@ -0,0 +1,65 @@
|
|||
import pyautogui as pg
|
||||
from pynput import keyboard
|
||||
import speech_recognition as sr
|
||||
from string import punctuation
|
||||
from slang import replacements
|
||||
import re
|
||||
from time import sleep
|
||||
|
||||
r = sr.Recognizer()
|
||||
|
||||
with sr.Microphone() as source:
|
||||
r.adjust_for_ambient_noise(source)
|
||||
|
||||
def recognize_text() -> str:
|
||||
|
||||
with sr.Microphone() as source:
|
||||
print("Say something!")
|
||||
audio = r.listen(source)
|
||||
|
||||
result = r.recognize_faster_whisper(audio, model="distil-small.en", beam_size=5, language="en", condition_on_previous_text=False)
|
||||
|
||||
return result
|
||||
|
||||
def on_press(key):
|
||||
if key is not keyboard.Key.home:
|
||||
return
|
||||
|
||||
print("triggered!")
|
||||
command = recognize_text()
|
||||
|
||||
print(f"Heard: {command}")
|
||||
|
||||
# cleanup command
|
||||
command = command.lower()
|
||||
for char in punctuation:
|
||||
command = command.replace(char, '')
|
||||
|
||||
for original, new in replacements.items():
|
||||
command = command.replace(original, new)
|
||||
|
||||
print(f"Cleaned up command: {command}")
|
||||
|
||||
if "chat" in command:
|
||||
message = re.search(r"type (.+?)(in |\n|$)", command).groups(0)[0].strip()
|
||||
print(f"Typing: {message} in team chat")
|
||||
pg.keyDown("enter")
|
||||
sleep(0.041)
|
||||
pg.keyUp("enter")
|
||||
pg.typewrite(message, 0.048)
|
||||
pg.keyDown("enter")
|
||||
sleep(0.074)
|
||||
pg.keyUp("enter")
|
||||
|
||||
elif any(keyword in command for keyword in ["maximum", "pulse", "balls", "remove", "eliminate", "murder"]):
|
||||
print("MAXIMUM PULSE!!!!")
|
||||
pg.keyDown("q")
|
||||
sleep(0.032)
|
||||
pg.keyUp("q")
|
||||
|
||||
|
||||
# Collect events until released
|
||||
with keyboard.Listener(
|
||||
on_press=on_press,
|
||||
on_release=lambda event: None) as listener:
|
||||
listener.join()
|
Loading…
Add table
Add a link
Reference in a new issue