-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a8213da
commit 14a64bf
Showing
10 changed files
with
119 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,3 +14,5 @@ build/ | |
dist | ||
tuxeatpi/locale/messages.pot | ||
*.mo | ||
passive-listen.log | ||
pocketsphinx-data/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
"""Hotword component""" | ||
|
||
import os | ||
from multiprocessing import Process | ||
|
||
import pyaudio | ||
from pocketsphinx.pocketsphinx import Decoder | ||
|
||
|
||
class HotWord(Process): | ||
"""Define hotword component | ||
For now hotword uses pocketsphinx with speech_recognition | ||
""" | ||
def __init__(self, settings, logger): | ||
Process.__init__(self) | ||
# Set logger | ||
self.logger = logger.getChild("Hotword") | ||
self.logger.debug("Initialization") | ||
# Init private attributes | ||
self._settings = settings | ||
self._must_run = False | ||
self._config = Decoder.default_config() | ||
self.prepare_decoder() | ||
|
||
def prepare_decoder(self): | ||
"""Set decoder config""" | ||
# prepare config | ||
self._hotword = self._settings['hotword']['hotword'] | ||
acoustic_model = os.path.join(self._settings['hotword']['model_dir'], | ||
self._settings['speech']['language'], | ||
'acoustic-model', | ||
) | ||
language_model = os.path.join(self._settings['hotword']['model_dir'], | ||
self._settings['speech']['language'], | ||
'language-model.lm.bin', | ||
) | ||
pocket_dict = os.path.join(self._settings['hotword']['model_dir'], | ||
self._settings['speech']['language'], | ||
'pronounciation-dictionary.dict', | ||
) | ||
self._config.set_string('-logfn', "/dev/null") | ||
self._config.set_string('-hmm', acoustic_model) | ||
self._config.set_string('-lm', language_model) | ||
self._config.set_string('-dict', pocket_dict) | ||
self._decoder = Decoder(self._config) | ||
self._decoder.set_keyphrase('wakeup', self._hotword) | ||
self._decoder.set_search('wakeup') | ||
|
||
def stop(self): | ||
"""Stop process""" | ||
self._must_run = False | ||
self.terminate() | ||
|
||
def run(self): | ||
"""Text to speech""" | ||
self._must_run = True | ||
rerun = True | ||
self.logger.debug("starting listening hotword %s", self._hotword) | ||
while rerun: | ||
rerun = False | ||
self._paudio = pyaudio.PyAudio() | ||
stream = self._paudio.open(format=pyaudio.paInt16, channels=1, rate=16000, | ||
input=True, frames_per_buffer=1024) | ||
stream.start_stream() | ||
self._paudio.get_default_input_device_info() | ||
|
||
self._decoder.start_utt() | ||
while self._must_run: | ||
buf = stream.read(1024) | ||
self._decoder.process_raw(buf, False, False) | ||
if self._decoder.hyp() and self._decoder.hyp().hypstr == self._hotword: | ||
self.logger.debug("Hotword detected") | ||
# TODO run nlu audio detection | ||
rerun = True | ||
break | ||
self._decoder.end_utt() | ||
|
||
|
||
class HotWordError(Exception): | ||
"""Base class for voice exceptions""" | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters