OpenVoiceOS / ovos-ww-plugin-openWakeWord

Apache License 2.0
1 stars 3 forks source link

Downloading melspectrogram, embedding, and VAD models to non-existent folder #8

Closed mikejgray closed 5 months ago

mikejgray commented 5 months ago

Since the pre-packaged models have been removed, the folder that models get downloaded to by default no longer exists. That causes model loads to fail:

2024-04-17 21:34:19.323 - voice - ovos_plugin_manager.wakewords:create_hotword:197 - ERROR - Could not open '/Users/Mike/Library/Caches/pypoetry/virtualenvs/ovos-mac-4gtofNfg-py3.10/lib/python3.10/site-packages/openwakeword/resources/models/melspectrogram.tflite'.
Traceback (most recent call last):
  File "/Users/Mike/Library/Caches/pypoetry/virtualenvs/ovos-mac-4gtofNfg-py3.10/lib/python3.10/site-packages/ovos_plugin_manager/wakewords.py", line 194, in create_hotword
    return cls.load_module(module, hotword, ww_config, lang, loop)
  File "/Users/Mike/Library/Caches/pypoetry/virtualenvs/ovos-mac-4gtofNfg-py3.10/lib/python3.10/site-packages/ovos_plugin_manager/wakewords.py", line 173, in load_module
    return clazz(hotword, hotword_config, lang=lang)
  File "/Users/Mike/Library/Caches/pypoetry/virtualenvs/ovos-mac-4gtofNfg-py3.10/lib/python3.10/site-packages/ovos_ww_plugin_openwakeword/__init__.py", line 31, in __init__
    self.model = openwakeword.Model(
  File "/Users/Mike/Library/Caches/pypoetry/virtualenvs/ovos-mac-4gtofNfg-py3.10/lib/python3.10/site-packages/openwakeword/utils.py", line 690, in wrapped
    return func(*args, **new_kwargs)
  File "/Users/Mike/Library/Caches/pypoetry/virtualenvs/ovos-mac-4gtofNfg-py3.10/lib/python3.10/site-packages/openwakeword/model.py", line 222, in __init__
    self.preprocessor = AudioFeatures(inference_framework=inference_framework, **kwargs)
  File "/Users/Mike/Library/Caches/pypoetry/virtualenvs/ovos-mac-4gtofNfg-py3.10/lib/python3.10/site-packages/openwakeword/utils.py", line 117, in __init__
    self.melspec_model = tflite.Interpreter(model_path=melspec_model_path, num_threads=ncpu)
  File "/Users/Mike/Library/Caches/pypoetry/virtualenvs/ovos-mac-4gtofNfg-py3.10/lib/python3.10/site-packages/tensorflow/lite/python/interpreter.py", line 464, in __init__
    self._interpreter = _interpreter_wrapper.CreateWrapperFromFile(
ValueError: Could not open '/Users/Mike/Library/Caches/pypoetry/virtualenvs/ovos-mac-4gtofNfg-py3.10/lib/python3.10/site-packages/openwakeword/resources/models/melspectrogram.tflite'.

openwakeword.utils.download_models:

    # Always download melspectrogram and embedding models, if they don't already exist
    if not os.path.exists(target_directory):
        os.makedirs(target_directory)
    for feature_model in openwakeword.FEATURE_MODELS.values():
        if not os.path.exists(os.path.join(target_directory, feature_model["download_url"].split("/")[-1])):
            download_file(feature_model["download_url"], target_directory)
            download_file(feature_model["download_url"].replace(".tflite", ".onnx"), target_directory)

    # Always download VAD models, if they don't already exist
    for vad_model in openwakeword.VAD_MODELS.values():
        if not os.path.exists(os.path.join(target_directory, vad_model["download_url"].split("/")[-1])):
            download_file(vad_model["download_url"], target_directory)

openwakeword.utils.download_file:

        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))

Not sure how you'd like this approached, but it may be best to either drop the models in an XDG-compliant folder that is created by the code if it doesn't exist, or validate that the target_directory exists and create it if it doesn't.

mikejgray commented 5 months ago

Wrong repo!