Skip to content
This repository has been archived by the owner on Sep 21, 2023. It is now read-only.

Commit

Permalink
use multiple hotwords for Alexa/Assistant, fixed crash on runtime
Browse files Browse the repository at this point in the history
  • Loading branch information
xtools-at committed May 17, 2017
1 parent 8314548 commit 845852f
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 4 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,13 @@ To change the hotwords (currently *Alexa* and *Google*), either change both thes

or `/etc/opt/AlexaPi/config.yaml` and `/opt/AlexaPi/src/keyphrase.list` **after** setup.

In the `config.yaml`, you may use a single String or an Array of Strings for your **phrase_assistant** (only). Every string there will trigger Assistant, everything else in your `keyphrase.list` will trigger Alexa.

In the `keyphrase.list`, you can also tweak the sensitivity of the hotword recognition. From the [CMUSphinx Wiki](https://cmusphinx.github.io/wiki/faq/#q-how-to-implement-hot-word-listening):
> Threshold must be tuned for every keyphrase on a test data to get the right balance missed detections and false alarms. You can try values like 1e-5 to 1e-50.
> For the best accuracy it is better to have keyphrase with 3-4 syllables. Too short phrases are easily confused.
You can also combine wakewords, e.g. "ok google". Also make sure that your new hotwords are included in the language model. Check the following directory for a file with `.dict` or `.dic` extension and add your hotwords if not already there: `/usr/local/lib/python2.7/dist-packages/pocketsphinx/model/`
You can also combine wakewords, e.g. "ok google" and/or "hey google". Also make sure that your new hotwords are included in the language model. Check the following directory for a file with `.dict` or `.dic` extension and add your hotwords if not already there: `/usr/local/lib/python2.7/dist-packages/pocketsphinx/model/`


### Change Hotword language
Expand Down
5 changes: 4 additions & 1 deletion src/alexapi/triggers/pocketsphinxtrigger.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,10 @@ def thread(self):

if triggered:
### Assistant Starts Here
voice_command = self._decoder.hyp().hypstr
try:
voice_command = self._decoder.hyp().hypstr
except:
voice_command = ""
self._trigger_callback(self, voice_command)
###

Expand Down
6 changes: 6 additions & 0 deletions src/config.template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,15 @@ triggers:
enabled: true
voice_confirm: true

# add your Hotwords to ./keyphrase.list too (in lowercase)!
## 'phrase' string only
phrase: "alexa"
## 'phrase_assistant' can be a string or string[] (lowercase)
## all howtwords here will trigger Assistant, everything else in your ./keyphrase.lst will trigger Alexa
## phrase_assistant = ["ok google", "hey google"]
phrase_assistant: "google"
threshold: 1e-10 # unused, change in ./keyphrase.list

language: "en-us"
dictionary: "cmudict-en-us.dict"

Expand Down
7 changes: 5 additions & 2 deletions src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -337,11 +337,14 @@ def alexa_speech_recognizer_generate_data(audio, boundary):
### AssistantPi
def assistant_handler(voice_command):
# clean voice_command
voice_command = voice_command.rstrip()
if voice_command is None or voice_command is "":
return False
else:
voice_command = voice_command.rstrip()
logger.debug('Pocketsphinx triggered with hotword: **' + voice_command + '**')
# compare to phrase_assistant from config
voice_command_assistant = config['triggers']['pocketsphinx']['phrase_assistant']
if voice_command == voice_command_assistant:
if voice_command in voice_command_assistant:
global p
if p is not None:
# SDK is ready, start recording
Expand Down

0 comments on commit 845852f

Please sign in to comment.