-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfilebr.py
94 lines (90 loc) · 3.92 KB
/
filebr.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
import keyboard
import speech_recognition as sr
from nltk.tokenize import word_tokenize
import tkinter.filedialog as fd ## filedialogue for opening files imported twice
import threading
##########################################################################################################
def fileopo():
flag = "start"
def controll():
global commandValue
while flag == "start":
listenit_thread.start()
listenit_thread.join()
command = commandValue
tokens = word_tokenize(command)
print(tokens)
key=["up", "down", "right", "tab" ,"left","stop","next","back","backwards","select","backwards","previous", "enter","open"]
new_name = None
for i in tokens:
if i in key:
##### Up
if i == "up":
keyboard.press_and_release('up')
##### Down
elif i == "down":
keyboard.press_and_release('down')
##### Next
elif i == "right" or i == "next":
keyboard.press_and_release('right')
##### Prevoius
elif i == "left" or i == "previous":
keyboard.press_and_release('left')
##### Change tab
elif i == "tab":
keyboard.press_and_release('tab')
##### Space
elif i == "space":
keyboard.press_and_release('space')
##### Delete
elif i == "delete":
keyboard.press_and_release('delete')
##### Esacpe
elif i == "escape":
keyboard.press_and_release('esc')
##### Back
elif i =="back" or i == "backward" or i == "backwards":
keyboard.press_and_release('backspace')
##### Select file
elif i =="open" or i == "enter" or i == "select":
keyboard.press_and_release('enter')
##### Give name directly
else:
new_name = command
print ("command = "+new_name)
if new_name is not None:
keyboard.write(new_name)
print("write"+command)
keyboard.press_and_release('enter')
controll_thread = threading.Thread(target=controll)
controll_thread.start()
name = fd.askopenfilename(filetypes=[('Image Files', ['.jpeg','.jpg','.png','.gif','.tiff','.tif','.bmp'])],title='Please select a picture to Elementize') ## shows only these extentions
if name is not None:
flag = "stop"
print("fileopo "+name)
listenit_thread.join()
controll_thread.join()
def listenit():
global commandValue
r = sr.Recognizer()
with sr.Microphone() as source:
print("Please wait. Calibrating microphone...")
r.adjust_for_ambient_noise(source, duration=5)
print("Say something!")
audio = r.listen(source)
# recognize speech using google
try:
commandValue = r.recognize_google(audio)
print("elements thinks you said '" + commandValue)
except sr.UnknownValueError:
print("elements could not understand audio")
except sr.RequestError as e:
print("elements error; {0}".format(e))
listenit_thread = threading.Thread(target=listenit)
if __name__ == "__main__":
t1 = threading.Thread(target=fileopo)
t1.start()
t1.join()
############################################################################
###########3 if therer is no file ?
#### to backward current directory