Skip to content
This repository has been archived by the owner on Aug 30, 2020. It is now read-only.

Commit

Permalink
Update /api/listen-for-wake to enable/disable wake word
Browse files Browse the repository at this point in the history
  • Loading branch information
synesthesiam committed Feb 6, 2020
1 parent 1041651 commit 9974566
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 7 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## [2.4.18] - Unreleased

### Added

- /api/listen-for-wake accepts "on" and "off" as POST data to enable/disable wake word

## [2.4.17] - 2020 Jan 21

### Added
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.4.17
2.4.18
7 changes: 5 additions & 2 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,8 +269,11 @@ async def api_speakers() -> Response:
async def api_listen_for_wake() -> str:
"""Make Rhasspy listen for a wake word"""
assert core is not None
core.listen_for_wake()
return "OK"
enabled_str = (await request.data).decode().strip().lower()
enabled = enabled_str not in ["false", "off"]
core.listen_for_wake(enabled)

return str(enabled)


# -----------------------------------------------------------------------------
Expand Down
3 changes: 2 additions & 1 deletion docs/reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ Application authors may want to use the [rhasspy-client](https://pypi.org/projec
* `?timeout=<seconds>` - override default command timeout
* `?entity=<entity>&value=<value>` - set custom entity/value in recognized intent
* `/api/listen-for-wake-word`
* POST to wake Rhasspy up and return immediately
* POST "on" to have Rhasspy listen for a wake word
* POST "off" to disable wake word
* `/api/lookup`
* POST word as plain text to look up or guess pronunciation
* `?n=<number>` - return at most `n` guessed pronunciations
Expand Down
9 changes: 7 additions & 2 deletions rhasspy/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
SentenceSpoken,
SpeakSentence,
SpeakWord,
StopListeningForWakeWord,
StartRecordingToBuffer,
StopRecordingToBuffer,
TestMicrophones,
Expand Down Expand Up @@ -162,10 +163,14 @@ async def get_speakers(self, system: Optional[str] = None) -> Dict[Any, Any]:

# -------------------------------------------------------------------------

def listen_for_wake(self) -> None:
def listen_for_wake(self, enabled: bool = True) -> None:
"""Tell Rhasspy to start listening for a wake word."""
assert self.actor_system is not None
self.actor_system.tell(self.dialogue_manager, ListenForWakeWord())

if enabled:
self.actor_system.tell(self.dialogue_manager, ListenForWakeWord())
else:
self.actor_system.tell(self.dialogue_manager, StopListeningForWakeWord())

async def listen_for_command(
self,
Expand Down
3 changes: 3 additions & 0 deletions rhasspy/dialogue.py
Original file line number Diff line number Diff line change
Expand Up @@ -732,6 +732,9 @@ def handle_any(self, message: Any, sender: RhasspyActor) -> None:
elif isinstance(message, GetProblems):
# Report problems from child actors
self.send(sender, Problems(self.problems))
elif isinstance(message, (ListenForWakeWord, StopListeningForWakeWord)):
# Forward to wake actor
self.send(self.wake, message)
else:
self.handle_forward(message, sender)

Expand Down
5 changes: 4 additions & 1 deletion rhasspy/wake.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ def load_decoder(self) -> None:
with open(dict_path, "r") as dict_file:
word_dict = read_dict(dict_file)

# TODO: Use dictionary_casing instead
dict_upper = self.profile.get("speech_to_text.dictionary_upper", False)
for word in keyphrase_words:
if dict_upper:
Expand Down Expand Up @@ -570,7 +571,9 @@ def in_listening(self, message: Any, sender: RhasspyActor) -> None:
self.prediction_sem = threading.Semaphore()
for _ in range(num_chunks):
chunk = self.audio_buffer[: self.chunk_size]
self.stream.write(chunk)
if chunk:
self.stream.write(chunk)

self.audio_buffer = self.audio_buffer[self.chunk_size :]

if self.send_not_detected:
Expand Down

0 comments on commit 9974566

Please sign in to comment.