# Path: scarlett/events.py
# def scarlett_event(event_type, data=None, origin=EVENT_LOCAL,
#                    make_dict=False):
#     """ Returns a dict representation of this Event. """
#     if make_dict:
#         _data = dict(data)
#     else:
#         _data = data
# 
#     return {
#         'event_type': event_type,
#         'data': _data,
#         'origin': str(origin)
#     }
# 
# Path: scarlett/constants.py
# EVENT_SCARLETT_START = "scarlett_start"
# 
# EVENT_SCARLETT_STOP = "scarlett_stop"
# 
# EVENT_STATE_CHANGED = "state_changed"
# 
# EVENT_TIME_CHANGED = "time_changed"
# 
# EVENT_CALL_SERVICE = "call_service"
# 
# EVENT_SERVICE_EXECUTED = "service_executed"
# 
# EVENT_SERVICE_REGISTER = "service_register"
# 
# EVENT_PLATFORM_DISCOVERED = "platform_discovered"
# 
# EVENT_SCARLETT_SAY = "scarlett_speak"
# 
# EVENT_BRAIN_UPDATE = "scarlett_brain_update"
# 
# EVENT_BRAIN_CHECK = "scarlett_brain_check"


import scarlett
import pygst
import gobject
import dbus
import dbus.service
import gst
import os
import threading
import time
import logging
        import gst
        import gst
        import gst
        import gst
from transitions import Machine
from scarlett.events import scarlett_event
from colorama import init, Fore, Back, Style
from scarlett.constants import (
    EVENT_SCARLETT_START,
    EVENT_SCARLETT_STOP,
    EVENT_STATE_CHANGED,
    EVENT_TIME_CHANGED,
    EVENT_CALL_SERVICE,
    EVENT_SERVICE_EXECUTED,
    EVENT_SERVICE_REGISTER,
    EVENT_PLATFORM_DISCOVERED,
    EVENT_SCARLETT_SAY,
    EVENT_BRAIN_UPDATE,
    EVENT_BRAIN_CHECK
)

            # TODO: Change this to emit to main thread
            # scarlett.basics.voice.play_block('pi-listening')

        else:
            failed_temp = self.do_get_property('failed') + 1
            self.do_set_property('failed', failed_temp)
            scarlett.log.debug(
                Fore.YELLOW +
                "self.failed = %i" %
                (self.do_get_property('failed')))
            if self.do_get_property('failed') > 4:
                # reset pipline
                self.scarlett_reset_listen()
                # TODO: Change this to emit text data to main thread
                # ScarlettTalk.speak(
                #     " %s , if you need me, just say my name." %
                #     (self.config.get('scarlett', 'owner')))

    def run_cmd(self, hyp, uttid):
        scarlett.log.debug(Fore.YELLOW + "Inside run_cmd function")
        scarlett.log.debug(Fore.YELLOW + "KEYWORD IDENTIFIED BABY")
        scarlett.log.debug(
            Fore.RED +
            "self.kw_found = %i" %
            (self.do_get_property('kw-found')))
        if hyp == 'CANCEL':
            self.cancel_listening()
        else:
            # TODO: Change this into emit hypothesis instead

# Path: scarlett/events.py
# def scarlett_event(event_type, data=None, origin=EVENT_LOCAL,
#                    make_dict=False):
#     """ Returns a dict representation of this Event. """
#     if make_dict:
#         _data = dict(data)
#     else:
#         _data = data
# 
#     return {
#         'event_type': event_type,
#         'data': _data,
#         'origin': str(origin)
#     }
# 
# Path: scarlett/constants.py
# EVENT_SCARLETT_START = "scarlett_start"
# 
# EVENT_SCARLETT_STOP = "scarlett_stop"
# 
# EVENT_STATE_CHANGED = "state_changed"
# 
# EVENT_TIME_CHANGED = "time_changed"
# 
# EVENT_CALL_SERVICE = "call_service"
# 
# EVENT_SERVICE_EXECUTED = "service_executed"
# 
# EVENT_SERVICE_REGISTER = "service_register"
# 
# EVENT_PLATFORM_DISCOVERED = "platform_discovered"
# 
# EVENT_SCARLETT_SAY = "scarlett_speak"
# 
# EVENT_BRAIN_UPDATE = "scarlett_brain_update"
# 
# EVENT_BRAIN_CHECK = "scarlett_brain_check"


# Path: scarlett/listener/gstlistenerfsm.py
import scarlett
import pygst
import gobject
import dbus
import dbus.service
import gst
import os
import threading
import time
import logging
        import gst
        import gst
        import gst
        import gst
from transitions import Machine
from scarlett.events import scarlett_event
from colorama import init, Fore, Back, Style
from scarlett.constants import (
    EVENT_SCARLETT_START,
    EVENT_SCARLETT_STOP,
    EVENT_STATE_CHANGED,
    EVENT_TIME_CHANGED,
    EVENT_CALL_SERVICE,
    EVENT_SERVICE_EXECUTED,
    EVENT_SERVICE_REGISTER,
    EVENT_PLATFORM_DISCOVERED,
    EVENT_SCARLETT_SAY,
    EVENT_BRAIN_UPDATE,
    EVENT_BRAIN_CHECK
)


            # TODO: Change this to emit to main thread
            # scarlett.basics.voice.play_block('pi-listening')

        else:
            failed_temp = self.do_get_property('failed') + 1
            self.do_set_property('failed', failed_temp)
            scarlett.log.debug(
                Fore.YELLOW +
                "self.failed = %i" %
                (self.do_get_property('failed')))
            if self.do_get_property('failed') > 4:
                # reset pipline
                self.scarlett_reset_listen()
                # TODO: Change this to emit text data to main thread
                # ScarlettTalk.speak(
                #     " %s , if you need me, just say my name." %
                #     (self.config.get('scarlett', 'owner')))

    def run_cmd(self, hyp, uttid):
        scarlett.log.debug(Fore.YELLOW + "Inside run_cmd function")
        scarlett.log.debug(Fore.YELLOW + "KEYWORD IDENTIFIED BABY")
        scarlett.log.debug(
            Fore.RED +
            "self.kw_found = %i" %
            (self.do_get_property('kw-found')))
        if hyp == 'CANCEL':
            self.cancel_listening()
        else:
            # TODO: Change this into emit hypothesis instead

            hyp_event = scarlett_event(