diff options
| author | Abdellah El Morabit <nsrddyn@gmail.com> | 2024-11-05 18:40:27 +0100 |
|---|---|---|
| committer | Abdellah El Morabit <nsrddyn@gmail.com> | 2024-11-05 18:40:27 +0100 |
| commit | fa7007d00c04fc73f668e2b7f339c3f60a64d055 (patch) | |
| tree | 1c054d4f10759201134d496dbe170e2cfe49bfe5 /sec.py | |
| parent | d7b8b6ae21c07fe52e691e9090c24de0d09a401f (diff) | |
did alot :)
Diffstat (limited to 'sec.py')
| -rw-r--r-- | sec.py | 83 |
1 files changed, 0 insertions, 83 deletions
| @@ -1,83 +0,0 @@ | |||
| 1 | # A speach transcriber using the google speech recognizer and then dsplaying it on the lcd of a raspberry pi | ||
| 2 | |||
| 3 | from rpi_lcd import LCD | ||
| 4 | import RPi.GPIO as GPIO | ||
| 5 | import speech_recognition as sr | ||
| 6 | from time import sleep | ||
| 7 | import sounddevice | ||
| 8 | import os | ||
| 9 | |||
| 10 | r = sr.Recognizer() | ||
| 11 | lcd = LCD() | ||
| 12 | mic = sr.Microphone() | ||
| 13 | |||
| 14 | beepPin = 17 | ||
| 15 | allow = False | ||
| 16 | |||
| 17 | def stream(): | ||
| 18 | print("starting live steam") | ||
| 19 | # starting the motion live stream | ||
| 20 | os.system('motion') | ||
| 21 | |||
| 22 | # Listening to the user's voice and putting it into a variable | ||
| 23 | def listen_voice(): | ||
| 24 | global audio | ||
| 25 | with mic as source: | ||
| 26 | r.adjust_for_ambient_noise(source) | ||
| 27 | audio = r.listen(source) | ||
| 28 | return audio | ||
| 29 | |||
| 30 | # Transcribing the audio to text and printing it out | ||
| 31 | # Using the google speech recognizer | ||
| 32 | # Google speech recognizer does require a internet connection | ||
| 33 | def recognize_speech(audio): | ||
| 34 | error = "400" | ||
| 35 | r_error = "401" | ||
| 36 | |||
| 37 | try: | ||
| 38 | words = r.recognize_google(audio) | ||
| 39 | lcd.text(words, 1) | ||
| 40 | print(f"Printing on screen: {words}") | ||
| 41 | password = "linux" | ||
| 42 | while allow == False: | ||
| 43 | if words == password: | ||
| 44 | allow = True | ||
| 45 | print("That's the password!!!") | ||
| 46 | stream() | ||
| 47 | |||
| 48 | except sr.UnknownValueError: | ||
| 49 | lcd.text(error, 1) | ||
| 50 | print(error) | ||
| 51 | except sr.RequestError: | ||
| 52 | lcd.text(r_error, 1) | ||
| 53 | print(r_error) | ||
| 54 | |||
| 55 | def setup(): | ||
| 56 | print("clearing the lcd screen") | ||
| 57 | lcd.clear() | ||
| 58 | print("setting up the system") | ||
| 59 | GPIO.setmode(GPIO.BCM) | ||
| 60 | GPIO.setup(beepPin, GPIO.OUT, initial=GPIO.HIGH) | ||
| 61 | |||
| 62 | def main(): | ||
| 63 | while True: | ||
| 64 | audio = listen_voice() | ||
| 65 | recognize_speech(audio) | ||
| 66 | GPIO.output(beepPin,GPIO.HIGH) | ||
| 67 | sleep(0.5) | ||
| 68 | GPIO.output(beepPin,GPIO.LOW) | ||
| 69 | |||
| 70 | |||
| 71 | |||
| 72 | def destroy(): | ||
| 73 | lcd.clear() | ||
| 74 | |||
| 75 | if __name__ == '__main__': | ||
| 76 | # Clearing the lcd before starting the program | ||
| 77 | |||
| 78 | print("setting up the alarm") | ||
| 79 | setup() | ||
| 80 | try: | ||
| 81 | main() | ||
| 82 | except KeyboardInterrupt: | ||
| 83 | destroy() | ||
