def door_bell(): os.system("sudo chown root.gpio /dev/gpiomem") os.system("sudo chmod g+rw /dev/gpiomem") GPIO.setmode(GPIO.BCM) door_bell_pin = 21 GPIO.setup(door_bell_pin, GPIO.IN, pull_up_down=GPIO.PUD_UP) # while True: input_state = GPIO.input(door_bell_pin) if input_state == 0: # Listen for the first press while input_state == 0: input_state = GPIO.input(door_bell_pin) time.sleep(2) # Wait for two seconds input_state = GPIO.input(door_bell_pin) if input_state == 0: # if the bell is pushed for more than 2 seconds speak("omxplayer {0}".format( os.path.join( audio_path, 'afriend.ogg'))) # say someone we know is at door while input_state == GPIO.input(door_bell_pin): input_state = GPIO.input(door_bell_pin) else: speak("omxplayer {0}".format( os.path.join( audio_path, "stranger.ogg"))) # say a stranger is at the door
def sing_song(track=None, audio_path=audio_commands, num_play=0, cb=audio_transcribe): def play_song(default_path): os.system('omxplayer {0}'.format(default_path)) talk = cb song = Song() all_song = song.song_list # this is a list of all songs num_song = len(all_song) index_song = num_song - 1 sample = random.randint(0, index_song) # this generates a random indexer to select a random song from the list sample = abs(sample - index_song) # Further randomizes the song path2 = os.path.join(base_dir2, 'music') # This gets the root folder containing the music default_path = os.path.join(path2, all_song[sample]) # this indexes a random song from the list and creates a path to it song_name = song.song_name # get the song's name from the instance of the Song class. speak('omxplayer {0}'.format(os.path.join(audio_commands, 'confirmation.ogg'))) # says "Sure just a second" try: song_path = os.path.join(path2, track) os.system('omxplayer {0}'.format(song_path)) except Exception: default_song = os.path.basename(default_path) default_song = song_name[default_song] talk("I am about playing {0};".format(default_song)) play_song(default_path=default_path)
def turn_on_fan(audio_path=audio_commands, cb=audio_transcribe, room_number=None): enable_root() talk = cb GPIO.setmode(GPIO.BCM) GPIO.setup(fan_pin, GPIO.OUT) GPIO.setwarnings(False) GPIO.output(fan_pin, GPIO.HIGH) speak('omxplayer {0}'.format(os.path.join(audio_path, 'fan_on.ogg')))
def turn_off_light(audio_path=audio_commands, cb=audio_transcribe, room_number=None): enable_root() def off_light(led_pin): talk = cb GPIO.setmode(GPIO.BCM) GPIO.setup(led_pin, GPIO.OUT) GPIO.setwarnings(False) GPIO.output(led_pin, False) if room_number == 1 or room_number is None: off_light(room_1_light1) off_light(room_1_light2) off_light(room_1_light3) speak('omxplayer {0}'.format(os.path.join(audio_path, 'light_off.ogg'))) if room_number == 2: off_light(room_2_light) speak('omxplayer {0}'.format(os.path.join(audio_path, 'light_off.ogg'))) if room_number == 3: off_light(room_3_light) speak('omxplayer {0}'.format(os.path.join(audio_path, 'light_off.ogg')))
print("nobody detected going in") elif isinstance(distance2, int) and distance2 < ultrasonic_distance_range: if isinstance(distance1, int) and distance1 < ultrasonic_distance_range: number_of_people -= 1 else: print("nobody detected going out") message = listener_par.recv( ) # Receives transcribe audio from listener class. print(message) if "Annah" in message or "Anna" in message: # This line ensures that Annah only responds to commands when it hears it's name def handle_effector(message): return_value = call_effector( message ) # calls the effector function with the transcribed audio text if return_value: listener.unheard() message = listener_par.recv() print(message) handle_effector(message) handle_effector(message) speak('omxplayer {0}'.format( os.path.join(audio_path, 'next_command.ogg')) ) # Says I am waiting for your next command print("I am waiting for your next command")
def enable_root(): speak("sudo chown root.gpio /dev/gpiomem") speak("sudo chmod g+rw /dev/gpiomem")