From 117556f85e79f2f128041a8f603e49df14f67a2d Mon Sep 17 00:00:00 2001
From: j1nx
Date: Fri, 9 Dec 2022 17:21:58 +0100
Subject: [PATCH] Add playground package whisper-tflite
---
buildroot-external/Config.in | 1 +
.../configs/rpi4_64-gui_defconfig | 1 +
.../0001-Add-CMakeLists.txt.patch | 47 +++++++++++++++++++
.../package/whisper-tflite/Config.in | 9 ++++
.../whisper-tflite/whisper-tflite.hash | 2 +
.../package/whisper-tflite/whisper-tflite.mk | 16 +++++++
6 files changed, 76 insertions(+)
create mode 100644 buildroot-external/package/whisper-tflite/0001-Add-CMakeLists.txt.patch
create mode 100644 buildroot-external/package/whisper-tflite/Config.in
create mode 100644 buildroot-external/package/whisper-tflite/whisper-tflite.hash
create mode 100644 buildroot-external/package/whisper-tflite/whisper-tflite.mk
diff --git a/buildroot-external/Config.in b/buildroot-external/Config.in
index 014cfb03..8f49eac2 100644
--- a/buildroot-external/Config.in
+++ b/buildroot-external/Config.in
@@ -110,6 +110,7 @@ endmenu
source "$BR2_EXTERNAL_OPENVOICEOS_PATH/package/userland-tools/Config.in"
source "$BR2_EXTERNAL_OPENVOICEOS_PATH/package/virtual-touch/Config.in"
source "$BR2_EXTERNAL_OPENVOICEOS_PATH/package/vocalfusion/Config.in"
+ source "$BR2_EXTERNAL_OPENVOICEOS_PATH/package/whisper-tflite/Config.in"
source "$BR2_EXTERNAL_OPENVOICEOS_PATH/package/whispercpp/Config.in"
source "$BR2_EXTERNAL_OPENVOICEOS_PATH/package/wifi-connect/Config.in"
source "$BR2_EXTERNAL_OPENVOICEOS_PATH/package/wiringpi2/Config.in"
diff --git a/buildroot-external/configs/rpi4_64-gui_defconfig b/buildroot-external/configs/rpi4_64-gui_defconfig
index e34994ff..8cd3326e 100644
--- a/buildroot-external/configs/rpi4_64-gui_defconfig
+++ b/buildroot-external/configs/rpi4_64-gui_defconfig
@@ -599,6 +599,7 @@ BR2_PACKAGE_SPOTIFYD=y
BR2_PACKAGE_TENSORFLOW_LITE=y
BR2_PACKAGE_USERLAND_TOOLS=y
BR2_PACKAGE_VOCALFUSION=y
+BR2_PACKAGE_WHISPER_TFLITE=y
BR2_PACKAGE_WHISPERCPP=y
BR2_PACKAGE_WIFI_CONNECT=y
BR2_PACKAGE_WIRINGPI2=y
diff --git a/buildroot-external/package/whisper-tflite/0001-Add-CMakeLists.txt.patch b/buildroot-external/package/whisper-tflite/0001-Add-CMakeLists.txt.patch
new file mode 100644
index 00000000..413af0f6
--- /dev/null
+++ b/buildroot-external/package/whisper-tflite/0001-Add-CMakeLists.txt.patch
@@ -0,0 +1,47 @@
+From 92360d24a61fe9863f74d5906e0272d152611aba Mon Sep 17 00:00:00 2001
+From: j1nx
+Date: Fri, 9 Dec 2022 17:16:42 +0100
+Subject: [PATCH 1/1] Add CMakeLists.txt
+
+---
+ tflite_minimal/CMakeLists.txt | 28 ++++++++++++++++++++++++++++
+ 1 file changed, 28 insertions(+)
+ create mode 100644 tflite_minimal/CMakeLists.txt
+
+diff --git a/tflite_minimal/CMakeLists.txt b/tflite_minimal/CMakeLists.txt
+new file mode 100644
+index 0000000..dc984d3
+--- /dev/null
++++ b/tflite_minimal/CMakeLists.txt
+@@ -0,0 +1,28 @@
++#
++# Copyright 2020 The TensorFlow Authors. All Rights Reserved.
++#
++# Licensed under the Apache License, Version 2.0 (the "License");
++# you may not use this file except in compliance with the License.
++# You may obtain a copy of the License at
++#
++# https://www.apache.org/licenses/LICENSE-2.0
++#
++# Unless required by applicable law or agreed to in writing, software
++# distributed under the License is distributed on an "AS IS" BASIS,
++# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
++# See the License for the specific language governing permissions and
++# limitations under the License.
++
++
++# Builds the minimal Tensorflow Lite example.
++
++cmake_minimum_required(VERSION 3.16)
++project(stream C CXX)
++set(CMAKE_CXX_STANDARD 17)
++
++find_package(tensorflow-lite REQUIRED)
++
++set(TARGET minimal)
++add_executable(${TARGET} minimal.cc)
++target_link_libraries(${TARGET} tensorflow-lite)
++install(TARGETS ${TARGET} DESTINATION bin)
+--
+2.34.1
+
diff --git a/buildroot-external/package/whisper-tflite/Config.in b/buildroot-external/package/whisper-tflite/Config.in
new file mode 100644
index 00000000..be31670d
--- /dev/null
+++ b/buildroot-external/package/whisper-tflite/Config.in
@@ -0,0 +1,9 @@
+config BR2_PACKAGE_WHISPER_TFLITE
+ bool "whisper-tflite"
+ help
+ TensorFlow Lite C++ to run inference on
+ whisper.tflite(~40 MB hybrid model weights
+ are in int8 and activations are in float32)
+
+ https://github.com/usefulsensors/openai-whisper
+
diff --git a/buildroot-external/package/whisper-tflite/whisper-tflite.hash b/buildroot-external/package/whisper-tflite/whisper-tflite.hash
new file mode 100644
index 00000000..a1392652
--- /dev/null
+++ b/buildroot-external/package/whisper-tflite/whisper-tflite.hash
@@ -0,0 +1,2 @@
+# Locally computed
+sha256 9cefee3ef2e2ea3d556c98922cc522e22af527bb76aaccf68fa02cc1d9e8b322 whisper-tflite-b3649ffba57bc226492522c736b1a127e50cdc26.tar.gz
diff --git a/buildroot-external/package/whisper-tflite/whisper-tflite.mk b/buildroot-external/package/whisper-tflite/whisper-tflite.mk
new file mode 100644
index 00000000..2cde1d8f
--- /dev/null
+++ b/buildroot-external/package/whisper-tflite/whisper-tflite.mk
@@ -0,0 +1,16 @@
+################################################################################
+#
+# whisper-tflite
+#
+################################################################################
+
+WHISPER_TFLITE_VERSION = b3649ffba57bc226492522c736b1a127e50cdc26
+WHISPER_TFLITE_SITE = $(call github,usefulsensors,openai-whisper,$(WHISPER_TFLITE_VERSION))
+WHISPER_TFLITE_LICENSE = Apache License 2.0
+WHISPER_TFLITE_SUBDIR = tflite_minimal
+
+WHISPER_TFLITE_INSTALL_STAGING = YES
+WHISPER_TFLITE_DEPENDENCIES = host-pkgconf
+WHISPER_TFLITE_SUPPORTS_IN_SOURCE_BUILD = NO
+
+$(eval $(cmake-package))