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