# Path: src/alexapi/triggers/voicetrigger.py
# class VoiceTrigger(BaseTrigger):
# 	__metaclass__ = ABCMeta
# 
# 	type = triggers.TYPES.VOICE
# 
# 	_detector = None
# 
# 	_enabled_lock = None
# 	_disabled_sync_lock = None
# 
# 	def __init__(self, config, trigger_callback):
# 
# 		super(VoiceTrigger, self).__init__(config, trigger_callback)
# 
# 		self._enabled_lock = threading.Event()
# 		self._disabled_sync_lock = threading.Event()
# 
# 	@abstractmethod
# 	def thread(self):
# 		pass
# 
# 	def run(self):
# 		thread = threading.Thread(target=self.thread, args=())
# 		thread.setDaemon(True)
# 		thread.start()
# 
# 	def enable(self):
# 		self._enabled_lock.set()
# 		self._disabled_sync_lock.clear()
# 
# 	def disable(self):
# 		self._enabled_lock.clear()
# 		self._disabled_sync_lock.wait()


import os
import threading
import logging
import platform
from pocketsphinx import get_model_path
from pocketsphinx.pocketsphinx import Decoder
from .voicetrigger import VoiceTrigger
		ps_config.set_string('-hmm', os.path.join(get_model_path(), 'en-us'))
		ps_config.set_string('-dict', os.path.join(get_model_path(), 'cmudict-en-us.dict'))

		# Specify recognition key phrase
		ps_config.set_string('-keyphrase', self._tconfig['phrase'])
		ps_config.set_float('-kws_threshold', float(self._tconfig['threshold']))

		# Hide the VERY verbose logging information when not in debug
		if logging.getLogger('alexapi').getEffectiveLevel() != logging.DEBUG:

			null_path = '/dev/null'
			if platform.system() == 'Windows':
				null_path = 'nul'

			ps_config.set_string('-logfn', null_path)

		# Process audio chunk by chunk. On keyword detected perform action and restart search
		self._detector = Decoder(ps_config)

	def thread(self):
		while True:
			self._enabled_lock.wait()

			self._capture.handle_init(self.AUDIO_RATE, self.AUDIO_CHUNK_SIZE)

			self._detector.start_utt()

			triggered = False
			while not triggered:


# Path: src/alexapi/triggers/voicetrigger.py
# class VoiceTrigger(BaseTrigger):
# 	__metaclass__ = ABCMeta
# 
# 	type = triggers.TYPES.VOICE
# 
# 	_detector = None
# 
# 	_enabled_lock = None
# 	_disabled_sync_lock = None
# 
# 	def __init__(self, config, trigger_callback):
# 
# 		super(VoiceTrigger, self).__init__(config, trigger_callback)
# 
# 		self._enabled_lock = threading.Event()
# 		self._disabled_sync_lock = threading.Event()
# 
# 	@abstractmethod
# 	def thread(self):
# 		pass
# 
# 	def run(self):
# 		thread = threading.Thread(target=self.thread, args=())
# 		thread.setDaemon(True)
# 		thread.start()
# 
# 	def enable(self):
# 		self._enabled_lock.set()
# 		self._disabled_sync_lock.clear()
# 
# 	def disable(self):
# 		self._enabled_lock.clear()
# 		self._disabled_sync_lock.wait()


# Path: src/alexapi/triggers/pocketsphinxtrigger.py
import os
import threading
import logging
import platform
from pocketsphinx import get_model_path
from pocketsphinx.pocketsphinx import Decoder
from .voicetrigger import VoiceTrigger

		ps_config.set_string('-hmm', os.path.join(get_model_path(), 'en-us'))
		ps_config.set_string('-dict', os.path.join(get_model_path(), 'cmudict-en-us.dict'))

		# Specify recognition key phrase
		ps_config.set_string('-keyphrase', self._tconfig['phrase'])
		ps_config.set_float('-kws_threshold', float(self._tconfig['threshold']))

		# Hide the VERY verbose logging information when not in debug
		if logging.getLogger('alexapi').getEffectiveLevel() != logging.DEBUG:

			null_path = '/dev/null'
			if platform.system() == 'Windows':
				null_path = 'nul'

			ps_config.set_string('-logfn', null_path)

		# Process audio chunk by chunk. On keyword detected perform action and restart search
		self._detector = Decoder(ps_config)

	def thread(self):
		while True:
			self._enabled_lock.wait()

			self._capture.handle_init(self.AUDIO_RATE, self.AUDIO_CHUNK_SIZE)

			self._detector.start_utt()

			triggered = False
			while not triggered:


				if not self._enabled_lock.isSet():