diff --git a/openwakeword/model.py b/openwakeword/model.py index 8e9149d..621987a 100755 --- a/openwakeword/model.py +++ b/openwakeword/model.py @@ -119,15 +119,16 @@ class Model(): return tflite_interpreter.get_tensor(output_index)[None, ] except ImportError: - try: + from importlib.util import find_spec + if find_spec("tensorflow") is not None and find_spec("tflite_runtime") is None: + logging.warning("Tried to import the tflite runtime, but it was not found. Using tensorflow instead.") from tensorflow.lite.python import interpreter as tflite def tflite_predict(tflite_interpreter, input_index, output_index, x): tflite_interpreter.set_tensor(input_index, x) tflite_interpreter.invoke() return tflite_interpreter.get_tensor(output_index)[None, ] - - except ImportError: + else: logging.warning("Tried to import the tflite runtime, but it was not found. " "Trying to switching to onnxruntime instead, if appropriate models are available.") if wakeword_models != [] and all(['.onnx' in i for i in wakeword_models]): diff --git a/openwakeword/utils.py b/openwakeword/utils.py index 5845d98..e45c86c 100644 --- a/openwakeword/utils.py +++ b/openwakeword/utils.py @@ -96,9 +96,11 @@ class AudioFeatures(): try: import tflite_runtime.interpreter as tflite except ImportError: - try: + from importlib.util import find_spec + if find_spec("tensorflow") is not None and find_spec("tflite_runtime") is None: + logging.warning("Tried to import the tflite runtime, but it was not found. Using tensorflow instead.") from tensorflow.lite.python import interpreter as tflite - except ImportError: + else: raise ValueError("Tried to import the TFLite runtime, but it was not found." "Neither was the TensorFlow interpreter." "Please install TFLite runtime using `pip install tflite-runtime`")