diff options
| author | nsrddyn@gmail.com <nsrddyn@gmail.com> | 2024-10-23 09:35:29 +0200 |
|---|---|---|
| committer | nsrddyn@gmail.com <nsrddyn@gmail.com> | 2024-10-23 09:35:29 +0200 |
| commit | 6198d0333d432b4e0dad7e8da2c2395473a12995 (patch) | |
| tree | f049031b60bbec1c132892da70466bfa6c4adbf4 | |
| parent | 9ee6cc3e55aa855b0f2daa1db9a162d8bac0e864 (diff) | |
added most of the function only thing i need to do now i seem to link them in some way and then also define the real io pin im going to use and also think about a good use case for the security system
| -rw-r--r-- | sec.py | 55 |
1 files changed, 45 insertions, 10 deletions
| @@ -1,18 +1,24 @@ | |||
| 1 | # A speach transcriber using the google speech recognizer and then dsplaying it on the lcd of a raspberry pi | 1 | # A speach transcriber using the google speech recognizer and then dsplaying it on the lcd of a raspberry pi |
| 2 | 2 | ||
| 3 | from rpi_lcd import LCD | 3 | from rpi_lcd import LCD |
| 4 | fro | 4 | import RPi.GPIO as GPIO |
| 5 | import speech_recognition as sr | 5 | import speech_recognition as sr |
| 6 | from time import sleep | 6 | from time import sleep |
| 7 | import sounddevice | 7 | import sounddevice |
| 8 | from motion import comp | 8 | import os |
| 9 | 9 | ||
| 10 | r = sr.Recognizer() | 10 | r = sr.Recognizer() |
| 11 | lcd = LCD() | 11 | lcd = LCD() |
| 12 | mic = sr.Microphone() | 12 | mic = sr.Microphone() |
| 13 | 13 | ||
| 14 | # Clearing the lcd before starting the program | 14 | beepPin = 17 |
| 15 | lcd.clear() | 15 | allow = False |
| 16 | |||
| 17 | def stream(): | ||
| 18 | print("starting live steam") | ||
| 19 | # starting the motion live stream | ||
| 20 | os.system('motion') | ||
| 21 | |||
| 16 | 22 | ||
| 17 | # Listening to the user's voice and putting it into a variable | 23 | # Listening to the user's voice and putting it into a variable |
| 18 | def listen_voice(): | 24 | def listen_voice(): |
| @@ -33,18 +39,47 @@ def recognize_speech(audio): | |||
| 33 | words = r.recognize_google(audio) | 39 | words = r.recognize_google(audio) |
| 34 | lcd.text(words, 1) | 40 | lcd.text(words, 1) |
| 35 | print(f"Printing on screen: {words}") | 41 | print(f"Printing on screen: {words}") |
| 42 | password = "linux" | ||
| 43 | while allow == False: | ||
| 44 | if words == password: | ||
| 45 | allow = True | ||
| 46 | print("That's the password!!!") | ||
| 47 | stream() | ||
| 48 | |||
| 36 | except sr.UnknownValueError: | 49 | except sr.UnknownValueError: |
| 37 | lcd.text(error, 1) | 50 | lcd.text(error, 1) |
| 38 | print(error) | 51 | print(error) |
| 39 | except sr.RequestError: | 52 | except sr.RequestError: |
| 40 | lcd.text(r_error, 1) | 53 | lcd.text(r_error, 1) |
| 41 | print(r_error) | 54 | print(r_error) |
| 42 | 55 | ||
| 43 | 56 | def setup(): | |
| 44 | while True: | 57 | print("clearing the lcd screen") |
| 45 | audio = listen_voice() | 58 | lcd.clear() |
| 46 | recognize_speech(audio) | 59 | print("setting up the system") |
| 60 | GPIO.setmode(GPIO.BCM) | ||
| 61 | GPIO.setup(beepPin, GPIO.OUT, initial=GPIO.HIGH) | ||
| 47 | 62 | ||
| 63 | def main(): | ||
| 64 | while True: | ||
| 65 | audio = listen_voice() | ||
| 66 | recognize_speech(audio) | ||
| 67 | GPIO.output(beepPin,GPIO.HIGH) | ||
| 68 | sleep(0.5) | ||
| 69 | GPIO.output(beepPin,GPIO.LOW) | ||
| 48 | 70 | ||
| 49 | 71 | ||
| 50 | 72 | ||
| 73 | def destroy(): | ||
| 74 | lcd.clear() | ||
| 75 | |||
| 76 | if __name__ == '__main__': | ||
| 77 | # Clearing the lcd before starting the program | ||
| 78 | |||
| 79 | print("setting up the alarm") | ||
| 80 | setup() | ||
| 81 | try: | ||
| 82 | main() | ||
| 83 | except KeyboardInterrupt: | ||
| 84 | destroy() | ||
| 85 | |||
