Пример #1
0
class MyRec:
    def __init__(self):
        self.logger = MyLogger(level=logging.DEBUG, get="REC")
        self.logger.add_file_stream_handler("logger.log")
        self.logger.logger.debug("Init REC drivers")
        self.proc = 0

    def record_start(self, cmd="sudo arecord -D sysdefault:CARD=0 -d 2 -r 16000 -f S16_LE /home/pi/temp3.wav"):
        self.thread_button_checker_exit = ButtonCheckAndExit(name="ButtonCheckAndExit")
        self.thread_button_checker_exit.start()
        self.thread_button_checker_exit.join(4)

        # thread_ = threading.Thread(target=self.button())
        # thread_.start()
        thread = threading.Thread(target=self.record(cmd))
        thread.start()
        thread.join(4)

    def record(self, cmd):
        self.logger.logger.debug("recording start")
        self.proc = subprocess.call(cmd, shell=True)
        self.logger.logger.debug("recording completed")

    def __exit__(self):
        self.logger.logger.debug("Exit REC drivers")
Пример #2
0
class Buttonout:
    class Buttonout(Exception):
        pass

    def __init__(self):
        self.button = aiy.voicehat.get_button()
        self.logger = MyLogger(level=logging.DEBUG, get="BUTTON")
        self.logger.add_file_stream_handler('logger.log')

    def __enter__(self):
        self.logger.logger.debug("enter")
        self.run()

    def __exit__(self):
        self.logger.logger.debug("exit")

    def run(self):
        self.logger.logger.debug("detect switch state")
        while True:
            if GPIO.input(self.button.channel):
                raise Buttonout.Buttonout()
# autor : colson (Yeong Jun Kim)
# https://www.github.com/YeongJunKim

from aiy_led import MyLed
from aiy_log import MyLogger
from aiy_play import MyAudio
from aiy_rec import MyRec
import logging
import aiy.voicehat
import datetime
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BCM)

logger = MyLogger(level=logging.DEBUG, get="MAIN")
led = MyLed()
audio = MyAudio()
rec = MyRec()

startFlag = 0
stopFlag = 0


def setup():
    logger.add_file_stream_handler("logger.log")


def button_callback():
    print("button callback")
    global startFlag
    if startFlag == 0:
        startFlag = 1
Пример #4
0
 def __init__(self):
     logger = MyLogger(level=logging.INFO, get="AUDIO")
     logger.logger.debug("Init audio driver")
Пример #5
0
 def __init__(self, led=(0x00, 0x00, 0x00)):
     self.logger = MyLogger(level=logging.INFO, get="LED")
     self.leds = Leds()
     self.leds.update(Leds.rgb_on(led))
     self.logger.logger.debug("Init LED drivers")
 def __init__(self):
     self.button = aiy.voicehat.get_button()
     self.button.__init__(button.channel, GPIO.RISING)
     self.button.on_press(self.raise_buttonout)
     self.logger = MyLogger(level=logging.DEBUG, get="BUTTON")
     self.logger.logger.debug('init')
Пример #7
0
import logging
import time
import aiy.voicehat
import threading
import datetime
import RPi.GPIO as GPIO
from aiy_led import MyLed
from aiy_log import MyLogger
from aiy_play import MyAudio

GPIO.setmode(GPIO.BCM)

button = aiy.voicehat.get_button()
led = MyLed()
play = MyAudio()
logger = MyLogger(level=logging.INFO, get="MAIN")

startFlag = 0
audio = 0
stream = 0
timeCnt = 0
timeout = 0
timerStart = 0
timeExitFlag = 0


def timer():
    global timeCnt
    global timeExitFlag
    global timerStart
    logger.logger.debug("timer_1")
Пример #8
0
import logging
from aiy_log import MyLogger
import threading
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BCM)

logger = MyLogger(level=logging.DEBUG, get="THREAD")


class ButtonCheck(threading.Thread):
    #
    # def __init__(self):
    #     super(ButtonCheck, self).__init__()
    #     logger.logger.debug(threading.currentThread().getName())

    def run(self):
        while True:
            if GPIO.input(23) == 0:
                print(threading.currentThread().getName())


Пример #9
0
 def __init__(self):
     self.button = aiy.voicehat.get_button()
     self.logger = MyLogger(level=logging.DEBUG, get="BUTTON")
     self.logger.add_file_stream_handler('logger.log')
Пример #10
0
 def __init__(self):
     self.logger = MyLogger(level=logging.DEBUG, get="REC")
     self.logger.add_file_stream_handler("logger.log")
     self.logger.logger.debug("Init REC drivers")
     self.proc = 0