where it says "hello", it is said by a text to speech and I would like to replace that hello with an mp3 file (music). This being so that when I make some motion, a song will play. I don't really know what I'm doing so if anybody knows a simpler way to do this I would really like to know and I would not redistribute the code in any way. thanks
import cv2 import pyttsx3 import threading # This funtion plays the audio message def thread_voice_alert(engine): engine.say("hello") engine.runAndWait() baseline_image=None status_list=[None,None] video=cv2.VideoCapture(0) #Setting parameters for voice engine = pyttsx3.init() voices = engine.getProperty('voices') engine.setProperty('voice', voices[1].id) engine.setProperty('rate', 150) while True: check, frame = video.read() status=0 gray_frame=cv2.cvtColor(frame,cv2.COLOR_BGR2GRAY) gray_frame=cv2.GaussianBlur(gray_frame,(25,25),0) if baseline_image is None: baseline_image=gray_frame continue delta=cv2.absdiff(baseline_image,gray_frame) threshold=cv2.threshold(delta, 30, 255, cv2.THRESH_BINARY)[1] (contours,_)=cv2.findContours(threshold,cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE) for contour in contours: if cv2.contourArea(contour) < 10000: continue status=1 (x, y, w, h)=cv2.boundingRect(contour) cv2.rectangle(frame, (x, y), (x+w, y+h), (0,255,0), 1) status_list.append(status) if status_list[-1]==1 and status_list[-2]==0: t = threading.Thread(target=thread_voice_alert, args=(engine,)) t.start() cv2.imshow("gray_frame Frame",gray_frame) cv2.imshow("Delta Frame",delta) cv2.imshow("Threshold Frame",threshold) cv2.imshow("Color Frame",frame) key=cv2.waitKey(1) if key==ord('q'): if status==1: times.append(datetime.now()) break #Clean up, Free memory engine.stop() video.release() cv2.destroyAllWindows I DID NOT WRITE THIS CODE. ORIGINAL SOURCE: https://towardsdatascience.com/build-a-motion-triggered-alarm-in-5-minutes-342fbe3d5396
https://stackoverflow.com/questions/66792057/is-there-a-way-i-can-get-this-motion-detector-system-on-my-laptop-to-play-mp3-fi March 25, 2021 at 10:06AM
没有评论:
发表评论