Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
.DS_Store
.env
File renamed without changes.
File renamed without changes.
File renamed without changes.
1 change: 1 addition & 0 deletions deps.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ tensorflow
numpy
comtypes
pandas
pyspellchecker==0.7.2
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,28 @@
import queue
import platform
import subprocess
from spellchecker import SpellChecker
import os
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
spell = SpellChecker()
current_word = "";

model = tf.keras.models.load_model("asl_cnn_model_rel.h5")
model = tf.keras.models.load_model(os.path.join(BASE_DIR, "../AI_model_and_Prediction/asl_cnn_model_rel.h5"))

class_names = [
'A','B','C','D','E','F','G','H','I','J','K','L','M',
'N','O','P','Q','R','S','T','U','V','W','X','Y','Z',
'del','nothing','space'
]

def auto_correct(word):
# words like i and a:
if len(word) <= 1:
return word
# correcting the letters
corrected = spell.correction(word)
return corrected if corrected else word

lastspoken = None
label_lock = threading.Lock()
landmark_queue = queue.Queue(maxsize=5)
Expand All @@ -26,23 +39,36 @@
single_lower_limit_index = double_letter_frames-first_letter_frames
upper_limit_index = double_letter_frames + 1

def speak(label):
def speak(text):
system = platform.system()
if system == "Darwin":
subprocess.Popen(["say", label])
subprocess.Popen(["say", text])
elif system == "Windows":
import comtypes.client
speaker = comtypes.client.CreateObject("SAPI.SpVoice")
speaker.Speak(label)
speaker.Speak(text)
else:
subprocess.Popen(["spd-say", label])
subprocess.Popen(["spd-say", text])

def process_label(label):
Comment thread
LearnPRG-py marked this conversation as resolved.
global current_word
if label == "space":
if current_word != "":
corrected = auto_correct(current_word)
speak(corrected)
print("Typed:", current_word, "Corrected:", corrected)
current_word = ""
elif label == "del":
current_word = current_word[:-1]
elif label != "nothing":
current_word += label.lower()

BaseOptions = mp.tasks.BaseOptions
HandLandmarker = mp.tasks.vision.HandLandmarker
HandLandmarkerOptions = mp.tasks.vision.HandLandmarkerOptions
VisionRunningMode = mp.tasks.vision.RunningMode

MODEL_PATH = "../hand_landmarker.task"
MODEL_PATH = os.path.join(BASE_DIR, "../hand_landmarker.task")

def hand_callback(result, output_image, timestamp_ms):
if not result.hand_landmarks:
Expand Down Expand Up @@ -93,17 +119,20 @@ def hand_callback(result, output_image, timestamp_ms):
labelbuffer.pop(0)
if len(labelbuffer) < upper_limit_index:
continue
elif len(set(labelbuffer[single_lower_limit_index:upper_limit_index])) == 1 and labelbuffer[single_lower_limit_index] != labelbuffer[single_lower_limit_index - 1]:
stablelabel = labelbuffer[double_letter_frames]
if len(set(labelbuffer[single_lower_limit_index:upper_limit_index])) == 1 and labelbuffer[single_lower_limit_index] != labelbuffer[single_lower_limit_index - 1]:
if lastspoken != labelbuffer[double_letter_frames]:
speak(labelbuffer[double_letter_frames])
lastspoken = labelbuffer[double_letter_frames]
process_label(stablelabel)
lastspoken = stablelabel
elif len(set(labelbuffer[1:upper_limit_index])) == 1 and labelbuffer[1] != labelbuffer[0]:
# allow a duplicate letter here
speak(labelbuffer[double_letter_frames])
lastspoken = labelbuffer[double_letter_frames]
process_label(stablelabel)
lastspoken = stablelabel
except queue.Empty:
pass

cv2.putText(frame, current_word, (50,50),
cv2.FONT_HERSHEY_SIMPLEX, 1,
(0,255,0), 2)
cv2.imshow("Hand Sign Prediction", frame)
if cv2.waitKey(5) & 0xFF == 27:
break
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def UpdateLabelsAndOrientation():
global target_label, target_orientation
try:
target_label = letterhash[input("Enter target label: ").upper()]
except KeyError:
except:
print("Invalid label, might be on Tryjobs, if not on TryJobs, restart the program and give it another try.")
quit()
target_orientation = int(input(
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading