diff options
| author | nasrlol <nsrddyn@gmail.com> | 2024-10-22 21:11:11 +0200 |
|---|---|---|
| committer | nasrlol <nsrddyn@gmail.com> | 2024-10-22 21:11:11 +0200 |
| commit | 9ee6cc3e55aa855b0f2daa1db9a162d8bac0e864 (patch) | |
| tree | fba04e540929b4bee0cdcd00943b66527e7e4619 | |
start of my security journey
| -rw-r--r-- | sec.py | 50 |
1 files changed, 50 insertions, 0 deletions
| @@ -0,0 +1,50 @@ | |||
| 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 | fro | ||
| 5 | import speech_recognition as sr | ||
| 6 | from time import sleep | ||
| 7 | import sounddevice | ||
| 8 | from motion import comp | ||
| 9 | |||
| 10 | r = sr.Recognizer() | ||
| 11 | lcd = LCD() | ||
| 12 | mic = sr.Microphone() | ||
| 13 | |||
| 14 | # Clearing the lcd before starting the program | ||
| 15 | lcd.clear() | ||
| 16 | |||
| 17 | # Listening to the user's voice and putting it into a variable | ||
| 18 | def listen_voice(): | ||
| 19 | global audio | ||
| 20 | with mic as source: | ||
| 21 | r.adjust_for_ambient_noise(source) | ||
| 22 | audio = r.listen(source) | ||
| 23 | return audio | ||
| 24 | |||
| 25 | # Transcribing the audio to text and printing it out | ||
| 26 | # Using the google speech recognizer | ||
| 27 | # Google speech recognizer does require a internet connection | ||
| 28 | def recognize_speech(audio): | ||
| 29 | error = "400" | ||
| 30 | r_error = "401" | ||
| 31 | |||
| 32 | try: | ||
| 33 | words = r.recognize_google(audio) | ||
| 34 | lcd.text(words, 1) | ||
| 35 | print(f"Printing on screen: {words}") | ||
| 36 | except sr.UnknownValueError: | ||
| 37 | lcd.text(error, 1) | ||
| 38 | print(error) | ||
| 39 | except sr.RequestError: | ||
| 40 | lcd.text(r_error, 1) | ||
| 41 | print(r_error) | ||
| 42 | |||
| 43 | |||
| 44 | while True: | ||
| 45 | audio = listen_voice() | ||
| 46 | recognize_speech(audio) | ||
| 47 | |||
| 48 | |||
| 49 | |||
| 50 | |||
