Skip to content

Open-source speech recognition toolkit for training, inference, streaming ASR, VAD, punctuation, speaker diarization pipelines, and OpenAI-compatible/MCP serving.

funasr-onnx http

游雁d83e999f599f
diff --git a/runtime/python/onnxruntime/funasr_client_http.py b/runtime/python/onnxruntime/funasr_client_http.py
new file mode 100644
index 000000000..1ddd62ca1
--- /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 000000000..e92f3022d
--- /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
[email protected]("/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