Ejemplo n.º 1
0
    def __init__(self):
        recognizer = Recognizer()
        recognizer.dynamic_energy_threshold = False
        recognizer.energy_threshold = 1000
        self.recognizer = recognizer
        self.microphone = Microphone()
        self.susi = susi

        try:
            res = requests.get('http://ip-api.com/json').json()
            self.susi.update_location(longitude=res['lon'],
                                      latitude=res['lat'])

        except ConnectionError as e:
            logging.error(e)

        self.config = json_config.connect('config.json')

        if self.config['hotword_engine'] == 'Snowboy':
            from main.hotword_engine import SnowboyDetector
            self.hotword_detector = SnowboyDetector()
        else:
            from main.hotword_engine import PocketSphinxDetector
            self.hotword_detector = PocketSphinxDetector()

        if self.config['wake_button'] == 'enabled':
            if self.config['device'] == 'RaspberryPi':
                from ..hardware_components import RaspberryPiWakeButton
                self.wake_button = RaspberryPiWakeButton()
            else:
                self.wake_button = None
        else:
            self.wake_button = None
Ejemplo n.º 2
0
    def __init__(self, renderer=None):
        try:
            import RPi.GPIO as GPIO
            GPIO.setmode(GPIO.BCM)
            GPIO.setup(17, GPIO.OUT)
            GPIO.setup(27, GPIO.OUT)
            GPIO.setup(22, GPIO.OUT)
        except ImportError:
            print("Only available for devices with GPIO ports ")
        except RuntimeError:
            pass

        recognizer = Recognizer()
        recognizer.dynamic_energy_threshold = False
        recognizer.energy_threshold = 1000
        self.recognizer = recognizer
        self.microphone = Microphone()
        self.susi = susi
        self.renderer = renderer

        try:
            res = requests.get('http://ip-api.com/json').json()
            self.susi.update_location(
                longitude=res['lon'], latitude=res['lat'], country_name=res['country'], country_code=res['countryCode'])

        except ConnectionError as e:
            logging.error(e)

        self.config = json_config.connect('config.json')

        if self.config['usage_mode'] == 'authenticated':
            try:
                susi.sign_in(email=self.config['login_credentials']['email'],
                             password=self.config['login_credentials']['password'])
            except Exception:
                print('Some error occurred in login. Check you login details in config.json')

        if self.config['hotword_engine'] == 'Snowboy':
            from main.hotword_engine.snowboy_detector import SnowboyDetector
            self.hotword_detector = SnowboyDetector()
        else:
            from main.hotword_engine.sphinx_detector import PocketSphinxDetector
            self.hotword_detector = PocketSphinxDetector()

        if self.config['WakeButton'] == 'enabled':
            print("\nSusi has the wake button enabled")
            if self.config['Device'] == 'RaspberryPi':
                print("\nSusi runs on a RaspberryPi")
                from ..hardware_components import RaspberryPiWakeButton
                self.wake_button = RaspberryPiWakeButton()
            else:
                print("\nSusi is not running on a RaspberryPi")
                self.wake_button = None
        else:
            print("\nSusi has the wake button disabled")
            self.wake_button = None
Ejemplo n.º 3
0
    def __init__(self, renderer=None):
        GPIO.setmode(GPIO.BCM)
        GPIO.setup(17, GPIO.OUT)
        GPIO.setup(27, GPIO.OUT)
        GPIO.setup(22, GPIO.OUT)

        recognizer = Recognizer()
        recognizer.dynamic_energy_threshold = False
        recognizer.energy_threshold = 1000
        self.recognizer = recognizer
        self.microphone = Microphone()
        self.susi = susi
        self.renderer = renderer

        try:
            res = requests.get('http://ip-api.com/json').json()
            self.susi.update_location(longitude=res['lon'],
                                      latitude=res['lat'])

        except ConnectionError as e:
            logging.error(e)

        self.config = json_config.connect('config.json')

        if self.config['usage_mode'] == 'authenticated':
            try:
                susi.sign_in(
                    email=self.config['login_credentials']['email'],
                    password=self.config['login_credentials']['password'])
            except Exception:
                print(
                    'Some error occurred in login. Check you login details in config.json'
                )

        if self.config['hotword_engine'] == 'Snowboy':
            from main.hotword_engine import SnowboyDetector
            self.hotword_detector = SnowboyDetector()
        else:
            from main.hotword_engine import PocketSphinxDetector
            self.hotword_detector = PocketSphinxDetector()

        if self.config['wake_button'] == 'enabled':
            if self.config['device'] == 'RaspberryPi':
                from ..hardware_components import RaspberryPiWakeButton
                self.wake_button = RaspberryPiWakeButton()
            else:
                self.wake_button = None
        else:
            self.wake_button = None
Ejemplo n.º 4
0
    def __init__(self):
        recognizer = Recognizer()
        recognizer.dynamic_energy_threshold = False
        recognizer.energy_threshold = 1000
        self.recognizer = recognizer
        self.microphone = Microphone()
        self.susi = susi
        self.config = json_config.connect('config.json')

        if self.config['hotword_engine'] == 'Snowboy':
            from main.hotword_engine import SnowboyDetector
            self.hotword_detector = SnowboyDetector()
        else:
            from main.hotword_engine import PocketSphinxDetector
            self.hotword_detector = PocketSphinxDetector()

        if self.config['wake_button'] == 'enabled':
            if self.config['device'] == 'RaspberryPi':
                from ..hardware_components import RaspberryPiWakeButton
                self.wake_button = RaspberryPiWakeButton()
            else:
                self.wake_button = None
        else:
            self.wake_button = None
Ejemplo n.º 5
0
    def __init__(self, renderer=None):
        if GPIO:
            try:
                GPIO.setmode(GPIO.BCM)
                GPIO.setup(27, GPIO.OUT)
                GPIO.setup(22, GPIO.OUT)
            except RuntimeError as e:
                logger.error(e)

        thread1 = Thread(target=self.server_checker, name="ServerCheckerThread")
        thread1.daemon = True
        thread1.start()

        recognizer = Recognizer()
        # this was False in the old state machine, but reading the API docs
        # https://github.com/Uberi/speech_recognition/blob/master/reference/library-reference.rst
        # it seems that True is actually better!
        recognizer.dynamic_energy_threshold = True
        recognizer.energy_threshold = 2000
        self.recognizer = recognizer
        self.susi = susi
        self.renderer = renderer
        self.server_url = "https://127.0.0.1:4000"
        self.action_schduler = ActionScheduler()
        self.action_schduler.start()
        self.event_queue = queue.Queue()
        self.idle = True

        try:
            res = requests.get('http://ip-api.com/json').json()
            self.susi.update_location(
                longitude=res['lon'], latitude=res['lat'],
                country_name=res['country'], country_code=res['countryCode'])

        except ConnectionError as e:
            logger.error(e)

        self.susi_config = SusiConfig()
        self.path_base = self.susi_config.get('path.base')
        self.sound_detection = os.path.abspath(
                                   os.path.join(self.path_base,
                                                self.susi_config.get('path.sound.detection')))
        self.sound_problem = os.path.abspath(
                                   os.path.join(self.path_base,
                                                self.susi_config.get('path.sound.problem')))
        self.sound_error_recognition = os.path.abspath(
                                   os.path.join(self.path_base,
                                                self.susi_config.get('path.sound.error.recognition')))
        self.sound_error_timeout = os.path.abspath(
                                   os.path.join(self.path_base,
                                                self.susi_config.get('path.sound.error.timeout')))

        if self.susi_config.get('susi.mode') == 'authenticated':
            try:
                susi.sign_in(email=self.susi_config.get('susi.user'),
                             password=self.susi_config.get('susi.pass'))
            except Exception as e:
                logger.error('Some error occurred in login. Check you login details with susi-config.\n%s', e)

        if self.susi_config.get('hotword.engine') == 'Snowboy':
            from .hotword_engine.snowboy_detector import SnowboyDetector
            hotword_model = "susi.pmdl"
            if self.susi_config.get('hotword.model'):
                logger.debug("Using configured hotword model: " + self.susi_config.get('hotword.model'))
                hotword_model = self.susi_config.get('hotword_model')
            self.hotword_detector = SnowboyDetector(model=hotword_model)
        else:
            from .hotword_engine.sphinx_detector import PocketSphinxDetector
            self.hotword_detector = PocketSphinxDetector()

        if self.susi_config.get('wakebutton') == 'enabled':
            logger.info("Susi has the wake button enabled")
            if self.susi_config.get('device') == 'RaspberryPi':
                logger.info("Susi runs on a RaspberryPi")
                from .hardware_components.rpi_wake_button import RaspberryPiWakeButton
                self.wake_button = RaspberryPiWakeButton()
            else:
                logger.warning("Susi is not running on a RaspberryPi")
                self.wake_button = None
        else:
            logger.warning("Susi has the wake button disabled")
            self.wake_button = None


        if self.susi_config.get('stt') == 'deepspeech-local':
            self.microphone = Microphone(sample_rate=16000)
        else:
            self.microphone = Microphone()

        if self.hotword_detector is not None:
            self.hotword_detector.subject.subscribe(
                on_next=lambda x: self.hotword_detected_callback())
        if self.wake_button is not None:
            self.wake_button.subject.subscribe(
                on_next=lambda x: self.hotword_detected_callback())
        if self.renderer is not None:
            self.renderer.subject.subscribe(
                on_next=lambda x: self.hotword_detected_callback())
        if self.action_schduler is not None:
            self.action_schduler.subject.subscribe(
                on_next=lambda x: self.queue_event(x))
Ejemplo n.º 6
0
    def __init__(self, renderer=None):
        try:
            import RPi.GPIO as GPIO
            GPIO.setmode(GPIO.BCM)
            GPIO.setup(27, GPIO.OUT)
            GPIO.setup(22, GPIO.OUT)
        except ImportError:
            logger.warning("This device doesn't have GPIO port")
        except RuntimeError as e:
            logger.error(e)
            pass
        thread1 = Thread(target=self.server_checker, name="Thread1")
        thread1.daemon = True
        thread1.start()

        recognizer = Recognizer()
        recognizer.dynamic_energy_threshold = False
        recognizer.energy_threshold = 1000
        self.recognizer = recognizer
        self.microphone = Microphone()
        self.susi = susi
        self.renderer = renderer
        self.server_url = "https://127.0.0.1:4000"
        self.action_schduler = ActionScheduler()
        self.action_schduler.start()

        try:
            res = requests.get('http://ip-api.com/json').json()
            self.susi.update_location(
                longitude=res['lon'], latitude=res['lat'],
                country_name=res['country'], country_code=res['countryCode'])

        except ConnectionError as e:
            logger.error(e)

        self.config = json_config.connect('config.json')

        if self.config['usage_mode'] == 'authenticated':
            try:
                susi.sign_in(email=self.config['login_credentials']['email'],
                             password=self.config['login_credentials']['password'])
            except Exception as e:
                logger.error('Some error occurred in login. Check you login details in config.json.\n%s', e)

        if self.config['hotword_engine'] == 'Snowboy':
            from ..hotword_engine.snowboy_detector import SnowboyDetector
            self.hotword_detector = SnowboyDetector()
        else:
            from ..hotword_engine.sphinx_detector import PocketSphinxDetector
            self.hotword_detector = PocketSphinxDetector()

        if self.config['WakeButton'] == 'enabled':
            logger.info("Susi has the wake button enabled")
            if self.config['Device'] == 'RaspberryPi':
                logger.info("Susi runs on a RaspberryPi")
                from ..hardware_components import RaspberryPiWakeButton
                self.wake_button = RaspberryPiWakeButton()
            else:
                logger.warning("Susi is not running on a RaspberryPi")
                self.wake_button = None
        else:
            logger.warning("Susi has the wake button disabled")
            self.wake_button = None