From 585172c9ec754330f4865f4a042bdb0c8bb54c08 Mon Sep 17 00:00:00 2001
From: 北念 <lzr265946@alibaba-inc.com>
Date: 星期二, 21 二月 2023 11:18:02 +0800
Subject: [PATCH] support grpc+onnxruntime

---
 funasr/runtime/python/onnxruntime/rapid_paraformer/utils/frontend.py |   15 +++++++++++++++
 1 files changed, 15 insertions(+), 0 deletions(-)

diff --git a/funasr/runtime/python/onnxruntime/rapid_paraformer/utils/frontend.py b/funasr/runtime/python/onnxruntime/rapid_paraformer/utils/frontend.py
index eb8a7c8..a3ca729 100644
--- a/funasr/runtime/python/onnxruntime/rapid_paraformer/utils/frontend.py
+++ b/funasr/runtime/python/onnxruntime/rapid_paraformer/utils/frontend.py
@@ -134,3 +134,18 @@
         vars = np.array(vars_list).astype(np.float64)
         cmvn = np.array([means, vars])
         return cmvn
+
+def load_bytes(input):
+    middle_data = np.frombuffer(input, dtype=np.int16)
+    middle_data = np.asarray(middle_data)
+    if middle_data.dtype.kind not in 'iu':
+        raise TypeError("'middle_data' must be an array of integers")
+    dtype = np.dtype('float32')
+    if dtype.kind != 'f':
+        raise TypeError("'dtype' must be a floating point type")
+
+    i = np.iinfo(middle_data.dtype)
+    abs_max = 2 ** (i.bits - 1)
+    offset = i.min + abs_max
+    array = np.frombuffer((middle_data.astype(dtype) - offset) / abs_max, dtype=np.float32)
+    return array
\ No newline at end of file

--
Gitblit v1.9.1