diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 8343da4..0000000 --- a/.gitattributes +++ /dev/null @@ -1,2 +0,0 @@ -*.onnx filter=lfs diff=lfs merge=lfs -text -*.tflite filter=lfs diff=lfs merge=lfs -text \ No newline at end of file diff --git a/MANIFEST.in b/MANIFEST.in deleted file mode 100644 index eef6e33..0000000 --- a/MANIFEST.in +++ /dev/null @@ -1,2 +0,0 @@ -recursive-include openwakeword *.onnx -recursive-include openwakeword *.tflite \ No newline at end of file diff --git a/README.md b/README.md index 7e5f4f5..be2d18f 100644 --- a/README.md +++ b/README.md @@ -41,16 +41,20 @@ Many thanks to [TeaPoly](https://github.com/TeaPoly/speexdsp-ns-python) for thei # Usage -For quick local testing, clone this repository and use the included [example script](examples/detect_from_microphone.py) to try streaming detection from a local microphone. **Important note!** The model files are stored in this repo using [git-lfs](https://git-lfs.com/); make sure it is installed on your system and if needed use `git-lfs fetch --all` to make sure the the models download correctly. +For quick local testing, clone this repository and use the included [example script](examples/detect_from_microphone.py) to try streaming detection from a local microphone. Adding openWakeWord to your own Python code requires just a few lines: ```python +import openwakeword from openwakeword.model import Model -# Instantiate the model +# One-time download of all pre-trained models (or only select models) +openwakeword.utils.download_models() + +# Instantiate the model(s) model = Model( - wakeword_models=["path/to/model.onnx"], # can also leave this argument empty to load all of the included pre-trained models + wakeword_models=["path/to/model.tflite"], # can also leave this argument empty to load all of the included pre-trained models ) # Get audio data containing 16-bit 16khz PCM audio data from a file, microphone, network stream, etc. diff --git a/openwakeword/resources/models/alexa_v0.1.onnx b/openwakeword/resources/models/alexa_v0.1.onnx deleted file mode 100644 index f52240e..0000000 --- a/openwakeword/resources/models/alexa_v0.1.onnx +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:6ff566a01d12670e8d9e3c59da32651db1575d17272a601b7f8a39283dfbae3e -size 854246 diff --git a/openwakeword/resources/models/alexa_v0.1.tflite b/openwakeword/resources/models/alexa_v0.1.tflite deleted file mode 100644 index 5d516e2..0000000 --- a/openwakeword/resources/models/alexa_v0.1.tflite +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:7333a317a790070a7f3432b81d9439c779481cc4ebd67c73da7174ea3cf48397 -size 855312 diff --git a/openwakeword/resources/models/embedding_model.onnx b/openwakeword/resources/models/embedding_model.onnx deleted file mode 100644 index 2c928ee..0000000 --- a/openwakeword/resources/models/embedding_model.onnx +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:70d164290c1d095d1d4ee149bc5e00543250a7316b59f31d056cff7bd3075c1f -size 1326578 diff --git a/openwakeword/resources/models/embedding_model.tflite b/openwakeword/resources/models/embedding_model.tflite deleted file mode 100644 index 52a5336..0000000 --- a/openwakeword/resources/models/embedding_model.tflite +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:c0aea21eb84a4ce90a08c870da41b7a7173b45269e6a3207c71d67c40f3a59d8 -size 1330312 diff --git a/openwakeword/resources/models/hey_jarvis_v0.1.onnx b/openwakeword/resources/models/hey_jarvis_v0.1.onnx deleted file mode 100644 index a45f1de..0000000 --- a/openwakeword/resources/models/hey_jarvis_v0.1.onnx +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:94a13cfe60075b132f6a472e7e462e8123ee70861bc3fb58434a73712ee0d2cb -size 1271370 diff --git a/openwakeword/resources/models/hey_jarvis_v0.1.tflite b/openwakeword/resources/models/hey_jarvis_v0.1.tflite deleted file mode 100644 index d155242..0000000 --- a/openwakeword/resources/models/hey_jarvis_v0.1.tflite +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:14bff778604985e1b5c19f0f7bbe477a69cf281d8db34b232b3b972411f710e2 -size 1278912 diff --git a/openwakeword/resources/models/hey_mycroft_v0.1.onnx b/openwakeword/resources/models/hey_mycroft_v0.1.onnx deleted file mode 100644 index b9952b3..0000000 --- a/openwakeword/resources/models/hey_mycroft_v0.1.onnx +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:c2a311e8fa1338de89c31b3b46dc4dffd4af2f9a8d6ddead48893c2d301b1f18 -size 857691 diff --git a/openwakeword/resources/models/hey_mycroft_v0.1.tflite b/openwakeword/resources/models/hey_mycroft_v0.1.tflite deleted file mode 100644 index 53b373c..0000000 --- a/openwakeword/resources/models/hey_mycroft_v0.1.tflite +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:bf9e43136afd3ca323698820a6e32a47f885ef4c30a3b8b577ec71688a9d64d8 -size 860300 diff --git a/openwakeword/resources/models/hey_rhasspy_v0.1.onnx b/openwakeword/resources/models/hey_rhasspy_v0.1.onnx deleted file mode 100644 index dea9d9d..0000000 --- a/openwakeword/resources/models/hey_rhasspy_v0.1.onnx +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:5a9b3ed3be2910e35780e097905aa9f35a9c10038df47914cf2b3ec4d670f6ea -size 204081 diff --git a/openwakeword/resources/models/hey_rhasspy_v0.1.tflite b/openwakeword/resources/models/hey_rhasspy_v0.1.tflite deleted file mode 100644 index 4fb9b6c..0000000 --- a/openwakeword/resources/models/hey_rhasspy_v0.1.tflite +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:01d2526b45068f565aa3849d6ec2b7abae099154fc1b496f9ef20de9ef241fe9 -size 416140 diff --git a/openwakeword/resources/models/melspectrogram.onnx b/openwakeword/resources/models/melspectrogram.onnx deleted file mode 100644 index be0643d..0000000 --- a/openwakeword/resources/models/melspectrogram.onnx +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:ba2b0e0f8b7b875369a2c89cb13360ff53bac436f2895cced9f479fa65eb176f -size 1087958 diff --git a/openwakeword/resources/models/melspectrogram.tflite b/openwakeword/resources/models/melspectrogram.tflite deleted file mode 100644 index c0f0ab8..0000000 --- a/openwakeword/resources/models/melspectrogram.tflite +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:96fa0adccb6e8cf95cb14465409a1a2898ee4a96a85bb9ed3c7eb0e68bf163e8 -size 1092516 diff --git a/openwakeword/resources/models/silero_vad.onnx b/openwakeword/resources/models/silero_vad.onnx deleted file mode 100755 index 664012e..0000000 --- a/openwakeword/resources/models/silero_vad.onnx +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:a35ebf52fd3ce5f1469b2a36158dba761bc47b973ea3382b3186ca15b1f5af28 -size 1807522 diff --git a/openwakeword/resources/models/timer_v0.1.onnx b/openwakeword/resources/models/timer_v0.1.onnx deleted file mode 100644 index 5603f7d..0000000 --- a/openwakeword/resources/models/timer_v0.1.onnx +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:371e44535470a29248b3b8f1bbbbaf2525c86417fd8f75c67fcf02ae0b9626df -size 1742475 diff --git a/openwakeword/resources/models/timer_v0.1.tflite b/openwakeword/resources/models/timer_v0.1.tflite deleted file mode 100644 index 11a7d50..0000000 --- a/openwakeword/resources/models/timer_v0.1.tflite +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:21d5b0267e97df64870b7aca312e2043ebed248d365698926a115a3694ff9626 -size 1743316 diff --git a/openwakeword/resources/models/weather_v0.1.onnx b/openwakeword/resources/models/weather_v0.1.onnx deleted file mode 100644 index 6c5599e..0000000 --- a/openwakeword/resources/models/weather_v0.1.onnx +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:8441da8e746899e8d969528d5bad5651cdd563079c05962788f77753041f60e7 -size 1149158 diff --git a/openwakeword/resources/models/weather_v0.1.tflite b/openwakeword/resources/models/weather_v0.1.tflite deleted file mode 100644 index 95dab6e..0000000 --- a/openwakeword/resources/models/weather_v0.1.tflite +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:4178991c7aeb76670f5a56559eb4129a6f3ae6207886db8bd8094fea7d362c3f -size 1150224 diff --git a/openwakeword/utils.py b/openwakeword/utils.py index ff89c42..aa649bb 100644 --- a/openwakeword/utils.py +++ b/openwakeword/utils.py @@ -540,7 +540,7 @@ def download_file(url, target_directory, file_size=None): total_size = int(r.headers.get('content-length', 0)) progress_bar = tqdm(total=total_size, unit='iB', unit_scale=True, desc=f"{local_filename}") - with open(local_filename, 'wb') as f: + with open(os.path.join(target_directory, local_filename), 'wb') as f: for chunk in r.iter_content(chunk_size=8192): f.write(chunk) progress_bar.update(len(chunk)) @@ -566,6 +566,8 @@ def download_models( Returns: None """ + if not isinstance(model_names, list): + raise ValueError("The model_names argument must be a list of strings") # Always download melspectrogram and embedding models, if they don't already exist for feature_model in openwakeword.FEATURE_MODELS.values(): @@ -588,6 +590,7 @@ def download_models( if url != []: if not os.path.exists(os.path.join(target_directory, url[0].split("/")[-1])): download_file(url[0], target_directory) + download_file(url[0].replace(".tflite", ".onnx"), target_directory) else: print(official_model_urls) for official_model_url in official_model_urls: diff --git a/tests/test_custom_verifier_model.py b/tests/test_custom_verifier_model.py index d5665e5..53f02ce 100644 --- a/tests/test_custom_verifier_model.py +++ b/tests/test_custom_verifier_model.py @@ -34,6 +34,9 @@ import scipy.io.wavfile import tempfile import pytest +# Download models needed for tests +openwakeword.utils.download_models(model_names=["alexa_v0.1", "hey_mycroft_v0.1"]) + # Tests class TestModels: diff --git a/tests/test_models.py b/tests/test_models.py index c38ecb8..e728065 100644 --- a/tests/test_models.py +++ b/tests/test_models.py @@ -40,6 +40,9 @@ import pickle import tempfile import mock +# Download models needed for tests +openwakeword.utils.download_models() + # Tests class TestModels: