#Importing required libraries....
import time
import machine
import pip
pip import speech_recognition
import speech_recognition as sr
from time import sleep
from machine import Pin, PWM
time.sleep(0.1) # Wait for USB to activate
whoareyou = sr.Recognizer()
relays = (1: ON, 2: OFF)
#Recording the audio (a.k.a waiting to recognise the voice commands from the user)
class: AUDRECOR
def record_audio():
with sr.Microphone() as source:
print("Listening...")
saysmth = whoareyou.listen(source)
return saysmth
#Recognising the voice command from the user
class: AUDRECOG
def recognize_speech(saysmth):
try:
read = recognizer.recognize_google(saysmth)
#If the user attempts tp use an unknown command
if sr.UnknownValueError:
machine.sleep
elif sr.RequestError:
machine.sleep
#Class for motor movement
class: motor
#Motor moves 90 degrees down if the switch is being turned on
if read = ON:
machine.PinWake
pwm.pin = PWM(Pin(0))
pwm.pin.freq(50)
def rotate_servo(position):
pwm_pin.duty_u16(position)
sleep(0.01)
while True:
for pos in range(1000, 9000, -90)
rotate_servo(pos)
#Motor moves the servo 90 degrees up if the switch is being turned off
else:
for pos in range(9000, 1000, 90)
rotate_servo(pos)