From 23b1bc9cf1e9aa78453feb11e27d5dafe26de068 Mon Sep 17 00:00:00 2001 From: Martin Weinelt Date: Wed, 27 Sep 2023 05:16:58 +0200 Subject: [PATCH] Allow tensorflow in place of tflite As a distro we are packaging tensorflow, but not tflite. The latter is a small cut-out of tensorflow, so they share the same entrypoint. This allows us to provide tensorflow in place of tflite, at the cost of a higher runtime closure size, but reduced maintenance load. --- programs/wake/openwakeword-lite/bin/server/openwakeword.py | 5 ++++- .../server/wyoming_openwakeword/openwakeword.py | 5 ++++- programs/wake/precise-lite/bin/precise_shared.py | 5 ++++- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/programs/wake/openwakeword-lite/bin/server/openwakeword.py b/programs/wake/openwakeword-lite/bin/server/openwakeword.py index 0cfd22d..3c21c0d 100644 --- a/programs/wake/openwakeword-lite/bin/server/openwakeword.py +++ b/programs/wake/openwakeword-lite/bin/server/openwakeword.py @@ -3,7 +3,10 @@ from typing import List import numpy as np -import tflite_runtime.interpreter as tflite +try: + import tflite_runtime.interpreter as tflite +except ModuleNotFoundError: + import tensorflow.lite as tflite from wyoming.wake import Detection diff --git a/programs/wake/openwakeword-lite/server/wyoming_openwakeword/openwakeword.py b/programs/wake/openwakeword-lite/server/wyoming_openwakeword/openwakeword.py index 00a8f25..dd9c2ed 100644 --- a/programs/wake/openwakeword-lite/server/wyoming_openwakeword/openwakeword.py +++ b/programs/wake/openwakeword-lite/server/wyoming_openwakeword/openwakeword.py @@ -4,7 +4,10 @@ from typing import List, Optional, TextIO import numpy as np -import tflite_runtime.interpreter as tflite +try: + import tflite_runtime.interpreter as tflite +except ModuleNotFoundError: + import tensorflow.lite as tflite from wyoming.wake import Detection diff --git a/programs/wake/precise-lite/bin/precise_shared.py b/programs/wake/precise-lite/bin/precise_shared.py index ebe0754..25f3314 100644 --- a/programs/wake/precise-lite/bin/precise_shared.py +++ b/programs/wake/precise-lite/bin/precise_shared.py @@ -24,7 +24,10 @@ from typing import Any, Optional, Union import numpy as np -import tflite_runtime.interpreter as tflite +try: + import tflite_runtime.interpreter as tflite +except ModuleNotFoundError: + import tensorflow.lite as tflite from sonopy import mfcc_spec MAX_WAV_VALUE = 32768