#encoding = utf8

import threading

from .asr_observer import AsrObserver


class AsrBase:
    def __init__(self):
        self._hot_words_file = ''
        self._sample_rate = 32000
        self._samples_per_read = 100
        self._observers = []

        self._stop_event = threading.Event()
        self._thread = threading.Thread(target=self._recognize_loop)
        self._thread.start()

    def _recognize_loop(self):
        pass

    def _notify_process(self, message: str):
        for observer in self._observers:
            observer.process(message)

    def _notify_complete(self, message: str):
        for observer in self._observers:
            observer.completed(message)

    def stop(self):
        self._stop_event.set()
        self._thread.join()

    def attach(self, observer: AsrObserver):
        self._observers.append(observer)

    def detach(self, observer: AsrObserver):
        self._observers.remove(observer)
