From 28ccfbfc51068a663a80764e14074df5edf2b5ba Mon Sep 17 00:00:00 2001
From: kongdeqiang <kongdeqiang960204@163.com>
Date: 星期五, 13 三月 2026 17:41:41 +0800
Subject: [PATCH] 提交

---
 runtime/python/onnxruntime/funasr_server_http.py |   31 ++++++++++++++++++-------------
 1 files changed, 18 insertions(+), 13 deletions(-)

diff --git a/runtime/python/onnxruntime/funasr_server_http.py b/runtime/python/onnxruntime/funasr_server_http.py
index e92f302..a610722 100644
--- a/runtime/python/onnxruntime/funasr_server_http.py
+++ b/runtime/python/onnxruntime/funasr_server_http.py
@@ -4,35 +4,40 @@
 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]
+    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'))
+        audio_bytes = base64.b64decode(bytes(item["wav_base64"], "utf-8"))
         waveform, _ = sf.read(io.BytesIO(audio_bytes))
-        result=await recognition_onnx(waveform)
+        result = await recognition_onnx(waveform)
         ret = {"results": result, "code": 0}
     except:
-        print('璇锋眰鍑洪敊锛岃繖閲屾槸澶勭悊鍑洪敊鐨�')
-        ret = {"results": '', "code": 1}
+        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')
+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
+    print("start...")
+    print("server on:", args)
+
+    uvicorn.run(app, host=args.listen, port=args.port)

--
Gitblit v1.9.1