Poprawka z emacs Button
This commit is contained in:
parent
060f40001e
commit
60d46656bd
52
voskpl.py
52
voskpl.py
|
@ -13,7 +13,7 @@ model = Model(model_path)
|
|||
recognizer = KaldiRecognizer(model, 16000)
|
||||
|
||||
listening = False # Flaga stanu nasłuchiwania
|
||||
emacs_mode = False # Flaga trybu Emacs
|
||||
|
||||
|
||||
# Funkcja obsługi danych audio
|
||||
def callback(indata, frames, time, status):
|
||||
|
@ -28,30 +28,35 @@ def callback(indata, frames, time, status):
|
|||
print(f"Rozpoznano: {text}")
|
||||
insert_text_with_clipboard(text)
|
||||
|
||||
|
||||
# Funkcja kopiowania do schowka i wklejania
|
||||
def insert_text_with_clipboard(text):
|
||||
try:
|
||||
pyperclip.copy(text) # Kopiowanie tekstu do schowka
|
||||
if emacs_mode:
|
||||
pyautogui.hotkey('shift', 'insert') # Wklejanie w trybie Emacs
|
||||
else:
|
||||
pyautogui.hotkey('ctrl', 'v') # Standardowe wklejanie
|
||||
pyautogui.press('space') # Dodanie spacji (opcjonalne)
|
||||
pyautogui.hotkey("ctrl", "v") # Standardowe wklejanie
|
||||
pyautogui.press("space") # Dodanie spacji (opcjonalne)
|
||||
except Exception as e:
|
||||
print(f"Błąd podczas wklejania tekstu: {e}", file=sys.stderr)
|
||||
|
||||
|
||||
# Funkcja nasłuchiwania i rozpoznawania mowy
|
||||
def listen_and_type():
|
||||
global listening
|
||||
print("Słucham... (naciśnij Stop, aby zatrzymać)")
|
||||
try:
|
||||
with sd.RawInputStream(samplerate=16000, blocksize=8000, dtype='int16',
|
||||
channels=1, callback=callback):
|
||||
with sd.RawInputStream(
|
||||
samplerate=16000,
|
||||
blocksize=8000,
|
||||
dtype="int16",
|
||||
channels=1,
|
||||
callback=callback,
|
||||
):
|
||||
while listening:
|
||||
pass # Nasłuchiwanie trwa w pętli
|
||||
except Exception as e:
|
||||
print(f"Błąd podczas nasłuchiwania: {e}", file=sys.stderr)
|
||||
|
||||
|
||||
# Funkcje sterujące GUI
|
||||
def toggle_listening():
|
||||
global listening
|
||||
|
@ -66,12 +71,6 @@ def toggle_listening():
|
|||
thread.daemon = True
|
||||
thread.start()
|
||||
|
||||
def toggle_emacs_mode():
|
||||
global emacs_mode
|
||||
emacs_mode = not emacs_mode
|
||||
update_emacs_button_state()
|
||||
mode = "Emacs" if emacs_mode else "Standard"
|
||||
print(f"Tryb wklejania: {mode}")
|
||||
|
||||
# Aktualizacja stanu przycisków
|
||||
def update_button_state():
|
||||
|
@ -80,31 +79,31 @@ def update_button_state():
|
|||
else:
|
||||
toggle_button.config(text="Start", bg="lightgrey", fg="black")
|
||||
|
||||
def update_emacs_button_state():
|
||||
if emacs_mode:
|
||||
emacs_button.config(text="Tryb: Emacs", bg="blue", fg="white")
|
||||
else:
|
||||
emacs_button.config(text="Tryb: Standard", bg="lightgrey", fg="black")
|
||||
|
||||
# Funkcja obsługi skrótu klawiszowego
|
||||
def handle_shortcut(event):
|
||||
if event.keysym == 'F1': # F1 jako skrót klawiszowy
|
||||
if event.keysym == "F1": # F1 jako skrót klawiszowy
|
||||
toggle_listening()
|
||||
|
||||
|
||||
# Tworzenie GUI
|
||||
def create_gui():
|
||||
global toggle_button, emacs_button
|
||||
global toggle_button
|
||||
|
||||
root = tk.Tk()
|
||||
root.title("Vosk Rozpoznawanie Mowy")
|
||||
root.geometry("300x200")
|
||||
root.geometry("220x120")
|
||||
|
||||
toggle_button = tk.Button(root, text="Start", command=toggle_listening, width=15, bg="lightgrey", fg="black")
|
||||
toggle_button = tk.Button(
|
||||
root,
|
||||
text="Start",
|
||||
command=toggle_listening,
|
||||
width=15,
|
||||
bg="lightgrey",
|
||||
fg="black",
|
||||
)
|
||||
toggle_button.pack(pady=10)
|
||||
|
||||
emacs_button = tk.Button(root, text="Tryb: Standard", command=toggle_emacs_mode, width=15, bg="lightgrey", fg="black")
|
||||
emacs_button.pack(pady=10)
|
||||
|
||||
exit_button = tk.Button(root, text="Wyjście", command=root.destroy, width=15)
|
||||
exit_button.pack(pady=10)
|
||||
|
||||
|
@ -113,6 +112,7 @@ def create_gui():
|
|||
|
||||
root.mainloop()
|
||||
|
||||
|
||||
# Uruchomienie GUI
|
||||
if __name__ == "__main__":
|
||||
create_gui()
|
||||
|
|
Loading…
Reference in New Issue