the hole code here is to detect the mask and no mask, if its detect that the person is not wearing mask then it will trigger pttsx3.say() but when am using in the code its suddenly giving me a dead kernel after properly execution. but when am using the pttsx3.say() independently its working fine I don't know what's wrong any help will be highly appreciated. as I have spend lots of time struggling with it and seriously not getting,
or any suggestion of real time text to voice app, in python is highly appreciated
code:
def main_function():
engine=pyttsx3.init()
voices = engine.getProperty('voices')
engine.setProperty('rate',210)
engine.setProperty('voice', voices[7].id)
#loading the pretrained model weights
model1 = keras.models.load_model('/Users/draculalemon/Documents/macbook file/all project /deepLearning/mask_file.h5')
#loading the pretrained cascade
face_cascade=cv2.CascadeClassifier('/Users/draculalemon/Documents/haarcascade_frontalface_default.xml')
vide=cv2.VideoCapture(0) # starting the webcam
#now we need to read the video in the loop frame persecond
while True:
_,frame=vide.read()
#haarcascade code to defect face
video_face=face_cascade.detectMultiScale(frame,1.8,5)
#this will draw square around the detected face
for (x_cordinates,y_cordinates,width,height) in video_face:
cv2.rectangle(frame,(x_cordinates,y_cordinates),(x_cordinates+width,y_cordinates+height),
(255,255,102),3)
try:
#try block so out code dosent stop abruptly when it dosent detect face
np.argmax(video_face) #here we have to put cv2.text
cv2.putText(frame,"FACE DETECTED",(20,100),1,2,(124,252,0),4)
except ValueError:
# cv2.putText(frame,"FACE NOT DETECTED",(20,100),1,2,(1,1,255),4)
pass
#code which predict whether a person is wearing mask or not
imgr1=cv2.resize(frame,(224,224))
imgrgb1=cv2.cvtColor(imgr1,cv2.COLOR_BGR2RGB)
final_format1=np.array([imgrgb1]).astype('float64')/255.0
predd=model1.predict(final_format1)
index=np.argmax(predd[0])
new_proba=str(round(np.max(predd[0]*100),2))
label_name=['MASK ON','MASK OFF']
labels=label_name[index]
if labels=="MASK ON":
cv2.putText(frame,f'{labels}',(20,50),1,3,(124,252,0),4)
else:
try:
engine=pyttsx3.init()
voices = engine.getProperty('voices')
engine.setProperty('rate',210)
engine.setProperty('voice', voices[7].id)
engine.say('Please bring your hand near to sanitizer machine')
engine.runAndWait()
engine.endLoop() # add this line
engine.stop()
except:
pass
cv2.putText(frame,f'{labels}',(20,50),1,3,(1,1,255),4)
pass
cv2.imshow('imgg',frame)
if cv2.waitKey(1) & 0XFF == ('d'):
break
cap.release()
cv2.waitKey(0)