python部署funasr非实时识别服务高并发问题

部署了一个funasr的中文音频非实时识别的服务接口,出现以下几种情况:

  1. 多次请求时接口未响应
  2. 音频文件135(1h)时响应很慢
  3. 用135M的音频文件请求接口,要一分钟后接口才收到请求

测试用例如下:

1. 单例#

asr_example(1 min/2M)
山路.mp3(1.34h/135M)

import time
import requests


import socket
import urllib3


def allowed_gai_family():
    return socket.AF_INET

# 用于取消ipv6请求
urllib3.util.connection.allowed_gai_family = allowed_gai_family

audio_file=r"D:\pycharm_project\ai-meeting-assistant\example\asr_example.wav"
audio_file=r"D:\pycharm_project\ai-meeting-assistant\example\山路.mp3"
funasr_url="http://xxx:11111/recognition"
with open(audio_file, 'rb') as file:
    audio_data = file.read()  # 读取整个文件的二进制数据
form_data={
    'audio': ('asr_example.wav',audio_data,'audio/wav')
}
start_time=time.time()

response=requests.post(funasr_url,files=form_data)
audio_text=response.json()['text']

end_time=time.time()
print("耗时",end_time-start_time)
audio_text

大文件请求结果

(.venv) (base) PS E:\asr\test> python .\single_test.py
耗时 217.44692373275757
(.venv) (base) PS E:\asr\test> python .\single_test.py
耗时 210.00433087348938

服务构建:
runtime/python/http/server.py

尝试使用官方镜像+ws构建

作者:Gim

出处:https://www.cnblogs.com/Gimm/p/18589492

版权:本作品采用「署名-非商业性使用-相同方式共享 4.0 国际」许可协议进行许可。

posted @   踩坑大王  阅读(146)  评论(0编辑  收藏  举报
more_horiz
keyboard_arrow_up dark_mode palette
选择主题
menu
点击右上角即可分享
微信分享提示