From d83e999f599fded04f72483fd24532e864511c05 Mon Sep 17 00:00:00 2001
From: 游雁 <zhifu.gzf@alibaba-inc.com>
Date: 星期五, 10 十一月 2023 15:16:21 +0800
Subject: [PATCH] funasr-onnx http
---
runtime/python/onnxruntime/funasr_server_http.py | 38 ++++++++++++++++++++++++++++++++++++++
runtime/python/onnxruntime/funasr_client_http.py | 18 ++++++++++++++++++
2 files changed, 56 insertions(+), 0 deletions(-)
diff --git a/runtime/python/onnxruntime/funasr_client_http.py b/runtime/python/onnxruntime/funasr_client_http.py
new file mode 100644
index 0000000..1ddd62c
--- /dev/null
+++ b/runtime/python/onnxruntime/funasr_client_http.py
@@ -0,0 +1,18 @@
+import base64
+import requests
+import threading
+
+
+with open('A2_0.wav','rb') as f:
+ test_wav_bytes=f.read()
+url='http://127.0.0.1:8888/api/asr'
+def send_post(i,url,wav_bytes):
+ r1=requests.post(url,json={'wav_base64':str(base64.b64encode(wav_bytes), 'utf-8')})
+ print('绾跨▼:',i,r1.json())
+
+
+for i in range(100):
+ t = threading.Thread(target=send_post, args=(i,url,test_wav_bytes,))
+ t.start()
+ #t.join()
+print('瀹屾垚娴嬭瘯')
\ No newline at end of file
diff --git a/runtime/python/onnxruntime/funasr_server_http.py b/runtime/python/onnxruntime/funasr_server_http.py
new file mode 100644
index 0000000..e92f302
--- /dev/null
+++ b/runtime/python/onnxruntime/funasr_server_http.py
@@ -0,0 +1,38 @@
+import argparse
+import base64
+import io
+import soundfile as sf
+import uvicorn
+from fastapi import FastAPI, Body
+app = FastAPI()
+
+from funasr_onnx import Paraformer
+model_dir = "damo/speech_paraformer-large_asr_nat-zh-cn-16k-common-vocab8404-onnx"
+model = Paraformer(model_dir, batch_size=1, quantize=True)
+
+async def recognition_onnx(waveform):
+ result=model(waveform)[0]["preds"][0]
+ return result
+@app.post("/api/asr")
+async def asr(item: dict = Body(...)):
+ try:
+ audio_bytes= base64.b64decode(bytes(item['wav_base64'], 'utf-8'))
+ waveform, _ = sf.read(io.BytesIO(audio_bytes))
+ result=await recognition_onnx(waveform)
+ ret = {"results": result, "code": 0}
+ except:
+ print('璇锋眰鍑洪敊锛岃繖閲屾槸澶勭悊鍑洪敊鐨�')
+ ret = {"results": '', "code": 1}
+ return ret
+
+
+if __name__ == '__main__':
+ parser = argparse.ArgumentParser(description='API Service')
+ parser.add_argument('--listen', default='0.0.0.0', type=str, help='the network to listen')
+ parser.add_argument('--port', default=8888, type=int, help='the port to listen')
+ args = parser.parse_args()
+
+ print('start...')
+ print('server on:',args)
+
+ uvicorn.run(app, host=args.listen, port=args.port)
\ No newline at end of file
--
Gitblit v1.9.1