예제 #1
0
import time
from pixels import Pixels, pixels
#from alexa_led_pattern import AlexaLedPattern
from google_home_led_pattern import GoogleHomeLedPattern

import paho.mqtt.client as mqtt
import paho.mqtt.publish as publish

pixels.pattern = GoogleHomeLedPattern(show=pixels.show)

host = "192.168.1.19"
port = 1883

def pixels_wakeup(client, userdata, msg):
#  print("pixels_wakeup")
  pixels.wakeup()
  time.sleep(3)

def pixels_think(client, userdata, msg):
#    print("pixels_think")
    pixels.think()
    time.sleep(3)

def pixels_speak(client, userdata, msg):
#    print("pixels_speak")
    pixels.speak()
    time.sleep(6)

def pixels_off(client, userdata, msg):
#    print("pixels_off")
    pixels.off()
예제 #2
0
from google_home_led_pattern import GoogleHomeLedPattern

# same to train_data.py
file_model_name = "model_file"

# file of test data
file_test_name = sys.argv[1]
label, data = svm_read_problem(file_test_name)

model = svm_load_model(file_model_name)
p_labels, p_acc, p_vals = svm_predict(label, data, model)
print p_labels
print p_acc
print p_vals
acc = int(p_acc[0])

if acc == 100:
    pixels.pattern = GoogleHomeLedPattern(show=pixels.show, color=1)
else:
    pixels.pattern = GoogleHomeLedPattern(show=pixels.show, color=2)

while True:
    try:
        pixels.speak()
        time.sleep(6)
    except KeyboardInterrupt:
        break

pixels.off()
time.sleep(1)
예제 #3
0
def main():
    # 注册ctrl-c中断
    signal.signal(signal.SIGINT, sigint_handler)
    pixels.pattern = GoogleHomeLedPattern(show=pixels.show)
    #ser = serial.Serial('/dev/ttyUSB0', 115200, timeout=0.5)
    #thread.start_new_thread(thread_water, ())

    #trash_recycle = [u'塑料瓶',u'玻璃杯',u'纸箱']
    #trash_wet = [u'树叶', u'果皮', u'剩饭']
    #trash_dry = [u'骨头', u'陶瓷', u'餐具']
    #trash_harmful = [u'电池', u'灯泡', u'化妆品']
    signal_start = 0

    setup()
    # start serial thread

    while True:
        try:
            #if  str(ser.read(5))== '1':
            #   thr = threading.Thread(target=cameraSendServer)
            #  thr.start()
            # thr.join()

            time.sleep(1)
            outputtext = record()
            outputtext = outputtext.replace(u'。', u'')

            if signal_start == 1 and sort(outputtext) == u'可回收垃圾':
                #        if outputtext in trash_recycle and signal_start == 1:
                # boolWaterlight = 0
                #   ser.write('1'.encode())
                os.system("sudo mpg123 recycle.mp3")
                # data =[255,255,255] * 3
                #pixels.show(data)
                signal_start = 0
                #duoji()

            elif signal_start == 1 and sort(outputtext) == u'干垃圾':
                #   ser.write(b'2')
                #boolWaterlight = 0
                os.system("sudo mpg123 dry.mp3")
                #data =[255,0,0] * 3
                #pixels.show(data)
                signal_start = 0
                #duoji()

            #elif outputtext in trash_wet and signal_start == 1:
            elif signal_start == 1 and sort(outputtext) == u'厨余垃圾':
                #  ser.write(b'3')
                #boolWaterlight = 0
                os.system("sudo mpg123 wet.mp3")
                #data =[0,255,0] * 3
                #pixels.show(data)
                signal_start = 0
                #duoji()

            #elif outputtext in trash_harmful and signal_start == 1:
            elif signal_start == 1 and sort(outputtext) == u'有毒有害垃圾':
                # ser.write(b'4')
                signal_start = 0
                os.system("sudo mpg123 harmful.mp3")
                #boolWaterlight = 1
                #data =[0,0,255] * 3
                #duoji()

            elif (u'垃圾') in outputtext:
                signal_start = 1
                # boolWaterlight = 0
                os.system("sudo mpg123 start.mp3")
                #pixels.off()

            elif signal_start == 1:
                os.system("sudo mpg123 repeat.mp3")

            elif (u'闭嘴') in outputtext:
                exit(1)

        except KeyError:
            stream.close()
            p.terminate()
            GPIO.cleanup()
import speech_recognition as sr
import re  # Regular Expressions

# Platform agnostic TTS using googles library
from gtts import gTTS
from pygame import mixer
mixer.init()  # Needs to be initilised only once

# Adding library's for RESPEAKER colours
# The local libaries were originally found on GitHub here:
# They have been modified to use the APA102_pi library instead of a local file https://github.com/tinue/apa102-pi#use-the-apa102-project-as-a-library
import time
from pixels import Pixels, pixels  # Local library needs files in repo
from google_home_led_pattern import GoogleHomeLedPattern  # Local library needs files in repo

pixels.pattern = GoogleHomeLedPattern(
    show=pixels.show)  # Initilise patern to be googles

# Replace GoogleSheets imports with Custom MongoDB Module
# Current date from datetime module needed when using module
import DBConModule
import datetime

# Seeing what microphones we have available
# for index, name in enumerate(sr.Microphone.list_microphone_names()):
#     print(f"Microphone with name \"{name}\" found for `Microphone(device_index={index})`".format(index, name))


# Create Speaking function
# Updated to be os agnostic
# TODO: See if there are better alternatives, she sounds slow and drunk
def speak(text):