Skip to content

Commit

Permalink
feat: trigger wakeword on <space> key press
Browse files Browse the repository at this point in the history
  • Loading branch information
hugoamalric authored and croumegous committed Apr 27, 2023
1 parent 0f752f8 commit 13443b3
Show file tree
Hide file tree
Showing 3 changed files with 139 additions and 3 deletions.
14 changes: 12 additions & 2 deletions assistant/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

from precise_runner import PreciseEngine, PreciseRunner
from os.path import abspath
from pynput import keyboard

# Logging setup
warnings.filterwarnings("ignore")
Expand Down Expand Up @@ -97,7 +98,7 @@ def parse_args() -> argparse.Namespace:
def main():
logger.info("Polyxia is started")
logger.info(
f"{bcolors.GREEN}Polyxia (fr): Je suis prête, dites Polyxia ! {bcolors.ENDC}")
f"{bcolors.GREEN}Polyxia (fr): Je suis prête, dites Polyxia ! (Ou appuyez sur <espace>){bcolors.ENDC}")
text_to_speech("Je suis prête, dites Polyxia !", "fr")
try:
# Parse args
Expand Down Expand Up @@ -138,7 +139,7 @@ def voice_assist():
# Listening to the wake word again
with noalsaerr():
logger.info(
f"{bcolors.GREEN}Polyxia (fr): Souhaitez-vous autre chose ? Dites Polyxia !{bcolors.ENDC}")
f"{bcolors.GREEN}Polyxia (fr): Souhaitez-vous autre chose ? Dites Polyxia ! (Ou appuyez sur <espace>){bcolors.ENDC}")
text_to_speech(
"Souhaitez-vous autre chose ? Dites Polyxia !", "fr")
runner.start()
Expand All @@ -157,6 +158,15 @@ def trigger_wakeword():
), sensitivity=0.8, trigger_level=10)
runner.start()

# Handle wakeword with keyboard
def on_release(key):
if key == keyboard.Key.space:
trigger_wakeword()
return False

with keyboard.Listener(on_release=on_release) as listener:
listener.join()

while True:
time.sleep(0.1)
global trigger_voice
Expand Down
127 changes: 126 additions & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ pyaudio = "^0.2.13"
transformers = "^4.27.1"
pygobject = "^3.44.1"
precise-runner = {file = "packages/precise_runner-0.3.1-py3-none-any.whl"}
pynput = "^1.7.6"

[[tool.poetry.source]]
name = "torch"
Expand Down

0 comments on commit 13443b3

Please sign in to comment.