Commit 3f6bb430 authored by Matt Clarkson's avatar Matt Clarkson

Merge branch '14-create-timer-in-thread'

parents cb54d9ed 4f3f46b7
Pipeline #3356 passed with stages
in 13 minutes and 45 seconds
......@@ -54,7 +54,7 @@ class VoiceRecognitionService(QObject):
model_file_path = os.environ['PORCUPINE_PARAMS']
keyword_file_paths = [os.environ['PORCUPINE_KEYWORD']]
sensitivities = [1.0]
self.interval = 10
self.handle = Porcupine(library_path,
model_file_path,
keyword_file_paths=keyword_file_paths,
......@@ -81,11 +81,9 @@ class VoiceRecognitionService(QObject):
# to use it later for the SpeechRecognition set up
self.timeout_for_command = timeout_for_command
# initialize a timer to call the listen_to_keyword method every 10ms
self.timer = QTimer()
self.timer.timeout.connect(self.listen_for_keyword)
self.timer.setInterval(10)
self.stop_timer.connect(self.__stop)
# Creating timer later, in the context of the running thread.
self.timer = None
LOGGER.info("Created Voice Recognition Service")
def run(self):
......@@ -94,6 +92,13 @@ class VoiceRecognitionService(QObject):
background
"""
LOGGER.info("run method executed")
# Creating the timer in the context of the running thread.
self.timer = QTimer()
self.timer.setInterval(self.interval)
self.timer.timeout.connect(self.listen_for_keyword)
self.stop_timer.connect(self.__stop)
# start the timer to start the background listening
self.timer.start()
......@@ -103,14 +108,16 @@ class VoiceRecognitionService(QObject):
"""
LOGGER.info("Requesting VoiceRecognitionService to stop timer.")
self.stop_timer.emit()
QThread.msleep(self.interval * 3)
while self.timer.isActive():
QThread.msleep(100)
QThread.msleep(self.interval * 3)
LOGGER.info("Requested VoiceRecognitionService to stop timer.")
@Slot()
def __stop(self):
LOGGER.info("Stopping VoiceRecognitionService timer.")
self.timer.stop()
QThread.msleep(self.interval * 3)
LOGGER.info("Stopped VoiceRecognitionService timer.")
def listen_for_keyword(self):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment