From 13443b3091db34566f02f47bf2997cf35b473381 Mon Sep 17 00:00:00 2001 From: hugoamalric Date: Thu, 27 Apr 2023 17:59:05 +0200 Subject: [PATCH] feat: trigger wakeword on key press --- assistant/app.py | 14 +++++- poetry.lock | 127 ++++++++++++++++++++++++++++++++++++++++++++++- pyproject.toml | 1 + 3 files changed, 139 insertions(+), 3 deletions(-) diff --git a/assistant/app.py b/assistant/app.py index a4a52a2..297216e 100644 --- a/assistant/app.py +++ b/assistant/app.py @@ -24,6 +24,7 @@ from precise_runner import PreciseEngine, PreciseRunner from os.path import abspath +from pynput import keyboard # Logging setup warnings.filterwarnings("ignore") @@ -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 ){bcolors.ENDC}") text_to_speech("Je suis prête, dites Polyxia !", "fr") try: # Parse args @@ -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 ){bcolors.ENDC}") text_to_speech( "Souhaitez-vous autre chose ? Dites Polyxia !", "fr") runner.start() @@ -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 diff --git a/poetry.lock b/poetry.lock index 30643fa..e046e12 100644 --- a/poetry.lock +++ b/poetry.lock @@ -430,6 +430,17 @@ files = [ {file = "distlib-0.3.6.tar.gz", hash = "sha256:14bad2d9b04d3a36127ac97f30b12a19268f211063d8f8ee4f47108896e11b46"}, ] +[[package]] +name = "evdev" +version = "1.6.1" +description = "Bindings to the Linux input handling subsystem" +category = "main" +optional = false +python-versions = "*" +files = [ + {file = "evdev-1.6.1.tar.gz", hash = "sha256:299db8628cc73b237fc1cc57d3c2948faa0756e2a58b6194b5bf81dc2081f1e3"}, +] + [[package]] name = "filelock" version = "3.12.0" @@ -1007,6 +1018,105 @@ files = [ [package.dependencies] pycairo = ">=1.16,<2.0" +[[package]] +name = "pynput" +version = "1.7.6" +description = "Monitor and control user input devices" +category = "main" +optional = false +python-versions = "*" +files = [ + {file = "pynput-1.7.6-py2.py3-none-any.whl", hash = "sha256:19861b2a0c430d646489852f89500e0c9332e295f2c020e7c2775e7046aa2e2f"}, + {file = "pynput-1.7.6.tar.gz", hash = "sha256:3a5726546da54116b687785d38b1db56997ce1d28e53e8d22fc656d8b92e533c"}, +] + +[package.dependencies] +evdev = {version = ">=1.3", markers = "sys_platform in \"linux\""} +pyobjc-framework-ApplicationServices = {version = ">=8.0", markers = "sys_platform == \"darwin\""} +pyobjc-framework-Quartz = {version = ">=8.0", markers = "sys_platform == \"darwin\""} +python-xlib = {version = ">=0.17", markers = "sys_platform in \"linux\""} +six = "*" + +[[package]] +name = "pyobjc-core" +version = "9.1.1" +description = "Python<->ObjC Interoperability Module" +category = "main" +optional = false +python-versions = ">=3.7" +files = [ + {file = "pyobjc-core-9.1.1.tar.gz", hash = "sha256:4b6cb9053b5fcd3c0e76b8c8105a8110786b20f3403c5643a688c5ec51c55c6b"}, + {file = "pyobjc_core-9.1.1-cp310-cp310-macosx_10_9_universal2.whl", hash = "sha256:4bd07049fd9fe5b40e4b7c468af9cf942508387faf383a5acb043d20627bad2c"}, + {file = "pyobjc_core-9.1.1-cp311-cp311-macosx_10_9_universal2.whl", hash = "sha256:1a8307527621729ff2ab67860e7ed84f76ad0da881b248c2ef31e0da0088e4ba"}, + {file = "pyobjc_core-9.1.1-cp37-cp37m-macosx_10_9_x86_64.whl", hash = "sha256:083004d28b92ccb483a41195c600728854843b0486566aba2d6e63eef51f80e6"}, + {file = "pyobjc_core-9.1.1-cp38-cp38-macosx_10_9_x86_64.whl", hash = "sha256:d61e9517d451bc062a7fae8b3648f4deba4fa54a24926fa1cf581b90ef4ced5a"}, + {file = "pyobjc_core-9.1.1-cp38-cp38-macosx_11_0_universal2.whl", hash = "sha256:1626909916603a3b04c07c721cf1af0e0b892cec85bb3db98d05ba024f1786fc"}, + {file = "pyobjc_core-9.1.1-cp39-cp39-macosx_10_9_universal2.whl", hash = "sha256:2dde96462b52e952515d142e2afbb6913624a02c13582047e06211e6c3993728"}, +] + +[[package]] +name = "pyobjc-framework-applicationservices" +version = "9.1.1" +description = "Wrappers for the framework ApplicationServices on macOS" +category = "main" +optional = false +python-versions = ">=3.7" +files = [ + {file = "pyobjc-framework-ApplicationServices-9.1.1.tar.gz", hash = "sha256:50c613bee364150bbd6cd992ca32b0848a780922cb57d112f6a4a56e29802e19"}, + {file = "pyobjc_framework_ApplicationServices-9.1.1-cp310-cp310-macosx_10_9_universal2.whl", hash = "sha256:f9286c05d80a6aafc7388a4c2a35801db9ea6bab960acf2df079110debb659cb"}, + {file = "pyobjc_framework_ApplicationServices-9.1.1-cp311-cp311-macosx_10_9_universal2.whl", hash = "sha256:3db1c79d7420052320529432e8562cd339a7ef0841df83a85bbf3648abb55b6b"}, + {file = "pyobjc_framework_ApplicationServices-9.1.1-cp37-cp37m-macosx_10_9_x86_64.whl", hash = "sha256:baf5a0d72c9e2d2a3b402823a2ea53eccdc27b8b9319d61cee7d753a30cb9411"}, + {file = "pyobjc_framework_ApplicationServices-9.1.1-cp38-cp38-macosx_10_9_x86_64.whl", hash = "sha256:7cc5aad93bb6b178f838fe9b78cdcf1217c7baab157b1f3525e0acf696cc3490"}, + {file = "pyobjc_framework_ApplicationServices-9.1.1-cp38-cp38-macosx_11_0_universal2.whl", hash = "sha256:a03434605873b9f83255a0b16bbc539d06afd77f5969a3b11a1fc293dfd56680"}, + {file = "pyobjc_framework_ApplicationServices-9.1.1-cp39-cp39-macosx_10_9_universal2.whl", hash = "sha256:9f18e9b92674be0e503a2bd451a328693450e6f80ee510bbc375238b14117e24"}, +] + +[package.dependencies] +pyobjc-core = ">=9.1.1" +pyobjc-framework-Cocoa = ">=9.1.1" +pyobjc-framework-Quartz = ">=9.1.1" + +[[package]] +name = "pyobjc-framework-cocoa" +version = "9.1.1" +description = "Wrappers for the Cocoa frameworks on macOS" +category = "main" +optional = false +python-versions = ">=3.7" +files = [ + {file = "pyobjc-framework-Cocoa-9.1.1.tar.gz", hash = "sha256:345c32b6d1f3db45f635e400f2d0d6c0f0f7349d45ec823f76fc1df43d13caeb"}, + {file = "pyobjc_framework_Cocoa-9.1.1-cp310-cp310-macosx_10_9_universal2.whl", hash = "sha256:9176a4276f3b4b4758e9b9ca10698be5341ceffaeaa4fa055133417179e6bc37"}, + {file = "pyobjc_framework_Cocoa-9.1.1-cp311-cp311-macosx_10_9_universal2.whl", hash = "sha256:5e1e96fb3461f46ff951413515f2029e21be268b0e033db6abee7b64ec8e93d3"}, + {file = "pyobjc_framework_Cocoa-9.1.1-cp37-cp37m-macosx_10_9_x86_64.whl", hash = "sha256:083b195c496d30c6b9dd86126a6093c4b95e0138e9b052b13e54103fcc0b4872"}, + {file = "pyobjc_framework_Cocoa-9.1.1-cp38-cp38-macosx_10_9_x86_64.whl", hash = "sha256:a1b3333b1aa045608848bd68bbab4c31171f36aeeaa2fabeb4527c6f6f1e33cd"}, + {file = "pyobjc_framework_Cocoa-9.1.1-cp38-cp38-macosx_11_0_universal2.whl", hash = "sha256:54c017354671f0d955432986c42218e452ca69906a101c8e7acde8510432303a"}, + {file = "pyobjc_framework_Cocoa-9.1.1-cp39-cp39-macosx_10_9_universal2.whl", hash = "sha256:10c0075688ce95b92caf59e368585fffdcc98c919bc345067af070222f5d01d2"}, +] + +[package.dependencies] +pyobjc-core = ">=9.1.1" + +[[package]] +name = "pyobjc-framework-quartz" +version = "9.1.1" +description = "Wrappers for the Quartz frameworks on macOS" +category = "main" +optional = false +python-versions = ">=3.7" +files = [ + {file = "pyobjc-framework-Quartz-9.1.1.tar.gz", hash = "sha256:8d03bc52bd6d90f00f274fd709b82e53dc5dfca19f3fc744997634e03faaa159"}, + {file = "pyobjc_framework_Quartz-9.1.1-cp310-cp310-macosx_10_9_universal2.whl", hash = "sha256:32602f46353a5eadb0843a0940635c8ec103f47d5b1ce84284604e01c6393fa8"}, + {file = "pyobjc_framework_Quartz-9.1.1-cp311-cp311-macosx_10_9_universal2.whl", hash = "sha256:7b3a56f52f9bb7fbd45c5a5f0de312ee9c104dfce6e1731015048d9e65a95e43"}, + {file = "pyobjc_framework_Quartz-9.1.1-cp37-cp37m-macosx_10_9_x86_64.whl", hash = "sha256:b3138773dfb269e6e3894e20dcfaf90102bad84ba44aa2bba8683b8426a69cdd"}, + {file = "pyobjc_framework_Quartz-9.1.1-cp38-cp38-macosx_10_9_x86_64.whl", hash = "sha256:3b583e6953e9c65525db908c33c1c97cead3ac8aa0cf2759fcc568666a1b7373"}, + {file = "pyobjc_framework_Quartz-9.1.1-cp38-cp38-macosx_11_0_universal2.whl", hash = "sha256:c3efcbba62e9c5351c2a9469faabb7f400f214cd8cf98f57798d6b6c93c76efb"}, + {file = "pyobjc_framework_Quartz-9.1.1-cp39-cp39-macosx_10_9_universal2.whl", hash = "sha256:a82d43c6c5fe0f5d350cfc97212bef7c572e345aa9c6e23909d23dace6448c99"}, +] + +[package.dependencies] +pyobjc-core = ">=9.1.1" +pyobjc-framework-Cocoa = ">=9.1.1" + [[package]] name = "python-dotenv" version = "1.0.0" @@ -1022,6 +1132,21 @@ files = [ [package.extras] cli = ["click (>=5.0)"] +[[package]] +name = "python-xlib" +version = "0.33" +description = "Python X Library" +category = "main" +optional = false +python-versions = "*" +files = [ + {file = "python-xlib-0.33.tar.gz", hash = "sha256:55af7906a2c75ce6cb280a584776080602444f75815a7aff4d287bb2d7018b32"}, + {file = "python_xlib-0.33-py2.py3-none-any.whl", hash = "sha256:c3534038d42e0df2f1392a1b30a15a4ff5fdc2b86cfa94f072bf11b10a164398"}, +] + +[package.dependencies] +six = ">=1.10.0" + [[package]] name = "pyyaml" version = "6.0" @@ -1574,4 +1699,4 @@ multidict = ">=4.0" [metadata] lock-version = "2.0" python-versions = ">=3.8,<3.10" -content-hash = "84826e6b200f13a74b81b8d3deeee5c62ebca9510c28265e05b7c3ef9c613400" +content-hash = "d021a26655b63496152410fbbbc1a4e003b0ea5300f79ee791bbee03add6ba3c" diff --git a/pyproject.toml b/pyproject.toml index 4789d63..3e46e6e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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"