lovemefan / fsmn-vad

A enterprise-grade Voice Activity Detector from modelscope and funasr.
MIT License
63 stars 6 forks source link

不支持多线程 #3

Open ben-8878 opened 1 year ago

ben-8878 commented 1 year ago
File "/home/ybZhang/miniconda3/lib/python3.8/site-packages/funasr_onnx/vad_bin.py", line 116, in __call__
    segments_part = self.vad_scorer(scores, waveform_package, is_final=is_final, max_end_sil=self.max_end_sil, online=False)
  File "/home/ybZhang/miniconda3/lib/python3.8/site-packages/funasr_onnx/utils/e2e_vad.py", line 459, in __call__
    self.DetectCommonFrames()
  File "/home/ybZhang/miniconda3/lib/python3.8/site-packages/funasr_onnx/utils/e2e_vad.py", line 502, in DetectCommonFrames
    frame_state = self.GetFrameState(self.frm_cnt - 1 - i)
  File "/home/ybZhang/miniconda3/lib/python3.8/site-packages/funasr_onnx/utils/e2e_vad.py", line 422, in GetFrameState
    sil_pdf_scores = [self.scores[0][t - self.idx_pre_chunk][sil_pdf_id] for sil_pdf_id in self.sil_pdf_ids]
  File "/home/ybZhang/miniconda3/lib/python3.8/site-packages/funasr_onnx/utils/e2e_vad.py", line 422, in <listcomp>
    sil_pdf_scores = [self.scores[0][t - self.idx_pre_chunk][sil_pdf_id] for sil_pdf_id in self.sil_pdf_ids]
IndexError: index 6513 is out of bounds for axis 0 with size 6000
ERROR:uvicorn.error:Exception in ASGI application
Traceback (most recent call last):
  File "/home/ybZhang/miniconda3/lib/python3.8/site-packages/uvicorn/protocols/http/httptools_impl.py", line 398, in run_asgi
    result = await app(self.scope, self.receive, self.send)
  File "/home/ybZhang/miniconda3/lib/python3.8/site-packages/uvicorn/middleware/proxy_headers.py", line 45, in __call__
    return await self.app(scope, receive, send)
  File "/home/ybZhang/miniconda3/lib/python3.8/site-packages/fastapi/applications.py", line 199, in __call__
    await super().__call__(scope, receive, send)
  File "/home/ybZhang/miniconda3/lib/python3.8/site-packages/starlette/applications.py", line 112, in __call__
    await self.middleware_stack(scope, receive, send)
  File "/home/ybZhang/miniconda3/lib/python3.8/site-packages/starlette/middleware/errors.py", line 181, in __call__
    raise exc from None
  File "/home/ybZhang/miniconda3/lib/python3.8/site-packages/starlette/middleware/errors.py", line 159, in __call__
    await self.app(scope, receive, _send)
  File "/home/ybZhang/miniconda3/lib/python3.8/site-packages/starlette/exceptions.py", line 82, in __call__
    raise exc from None
  File "/home/ybZhang/miniconda3/lib/python3.8/site-packages/starlette/exceptions.py", line 71, in __call__
    await self.app(scope, receive, sender)
  File "/home/ybZhang/miniconda3/lib/python3.8/site-packages/starlette/routing.py", line 580, in __call__
    await route.handle(scope, receive, send)
  File "/home/ybZhang/miniconda3/lib/python3.8/site-packages/starlette/routing.py", line 241, in handle
    await self.app(scope, receive, send)
  File "/home/ybZhang/miniconda3/lib/python3.8/site-packages/starlette/routing.py", line 52, in app
    response = await func(request)
  File "/home/ybZhang/miniconda3/lib/python3.8/site-packages/fastapi/routing.py", line 201, in app
    raw_response = await run_endpoint_function(
  File "/home/ybZhang/miniconda3/lib/python3.8/site-packages/fastapi/routing.py", line 150, in run_endpoint_function
    return await run_in_threadpool(dependant.call, **values)
  File "/home/ybZhang/miniconda3/lib/python3.8/site-packages/starlette/concurrency.py", line 40, in run_in_threadpool
    return await loop.run_in_executor(None, func, *args)
  File "/home/ybZhang/miniconda3/lib/python3.8/concurrent/futures/thread.py", line 57, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/data/disk0/zyb/gitcodes/400zhijian/asr_server_kefu_v9_fsmn_mutith.py", line 866, in recognize
    bounds_of_speechs_right = get_vad_speechs(wav_bytes_right_raw)
  File "/data/disk0/zyb/gitcodes/400zhijian/asr_server_kefu_v9_fsmn_mutith.py", line 382, in get_vad_speechs
    bounds_of_speechs = vad(bytes2numpy(wav_bytes))
  File "/home/ybZhang/miniconda3/lib/python3.8/site-packages/funasr_onnx/vad_bin.py", line 116, in __call__
    segments_part = self.vad_scorer(scores, waveform_package, is_final=is_final, max_end_sil=self.max_end_sil, online=False)
  File "/home/ybZhang/miniconda3/lib/python3.8/site-packages/funasr_onnx/utils/e2e_vad.py", line 459, in __call__
    self.DetectCommonFrames()
  File "/home/ybZhang/miniconda3/lib/python3.8/site-packages/funasr_onnx/utils/e2e_vad.py", line 502, in DetectCommonFrames
    frame_state = self.GetFrameState(self.frm_cnt - 1 - i)
  File "/home/ybZhang/miniconda3/lib/python3.8/site-packages/funasr_onnx/utils/e2e_vad.py", line 422, in GetFrameState
    sil_pdf_scores = [self.scores[0][t - self.idx_pre_chunk][sil_pdf_id] for sil_pdf_id in self.sil_pdf_ids]
  File "/home/ybZhang/miniconda3/lib/python3.8/site-packages/funasr_onnx/utils/e2e_vad.py", line 422, in <listcomp>
    sil_pdf_scores = [self.scores[0][t - self.idx_pre_chunk][sil_pdf_id] for sil_pdf_id in self.sil_pdf_ids]
IndexError: index 6513 is out of bounds for axis 0 with size 6000
lovemefan commented 1 year ago

File "/home/ybZhang/miniconda3/lib/python3.8/site-packages/funasr_onnx/vad_bin.py", line 116, in call segments_part = self.vad_scorer(scores, waveform_package, is_final=is_final, max_end_sil=self.max_end_sil, online=False) File "/home/ybZhang/miniconda3/lib/python3.8/site-packages/funasr_onnx/utils/e2e_vad.py", line 459, in call self.DetectCommonFrames() File "/home/ybZhang/miniconda3/lib/python3.8/site-packages/funasr_onnx/utils/e2e_vad.py", line 502, in DetectCommonFrames frame_state = self.GetFrameState(self.frm_cnt - 1 - i) File "/home/ybZhang/miniconda3/lib/python3.8/site-packages/funasr_onnx/utils/e2e_vad.py", line 422, in GetFrameState sil_pdf_scores = [self.scores[0][t - self.idx_pre_chunk][sil_pdf_id] for sil_pdf_id in self.sil_pdf_ids] File "/home/ybZhang/miniconda3/lib/python3.8/site-packages/funasr_onnx/utils/e2e_vad.py", line 422, in sil_pdf_scores = [self.scores[0][t - self.idx_pre_chunk][sil_pdf_id] for sil_pdf_id in self.sil_pdf_ids] IndexError: index 6513 is out of bounds for axis 0 with size 6000 ERROR:uvicorn.error:Exception in ASGI application Traceback (most recent call last): File "/home/ybZhang/miniconda3/lib/python3.8/site-packages/uvicorn/protocols/http/httptools_impl.py", line 398, in run_asgi result = await app(self.scope, self.receive, self.send) File "/home/ybZhang/miniconda3/lib/python3.8/site-packages/uvicorn/middleware/proxy_headers.py", line 45, in call return await self.app(scope, receive, send) File "/home/ybZhang/miniconda3/lib/python3.8/site-packages/fastapi/applications.py", line 199, in call await super().call(scope, receive, send) File "/home/ybZhang/miniconda3/lib/python3.8/site-packages/starlette/applications.py", line 112, in call await self.middleware_stack(scope, receive, send) File "/home/ybZhang/miniconda3/lib/python3.8/site-packages/starlette/middleware/errors.py", line 181, in call raise exc from None File "/home/ybZhang/miniconda3/lib/python3.8/site-packages/starlette/middleware/errors.py", line 159, in call await self.app(scope, receive, _send) File "/home/ybZhang/miniconda3/lib/python3.8/site-packages/starlette/exceptions.py", line 82, in call raise exc from None File "/home/ybZhang/miniconda3/lib/python3.8/site-packages/starlette/exceptions.py", line 71, in call await self.app(scope, receive, sender) File "/home/ybZhang/miniconda3/lib/python3.8/site-packages/starlette/routing.py", line 580, in call await route.handle(scope, receive, send) File "/home/ybZhang/miniconda3/lib/python3.8/site-packages/starlette/routing.py", line 241, in handle await self.app(scope, receive, send) File "/home/ybZhang/miniconda3/lib/python3.8/site-packages/starlette/routing.py", line 52, in app response = await func(request) File "/home/ybZhang/miniconda3/lib/python3.8/site-packages/fastapi/routing.py", line 201, in app raw_response = await run_endpoint_function( File "/home/ybZhang/miniconda3/lib/python3.8/site-packages/fastapi/routing.py", line 150, in run_endpoint_function return await run_in_threadpool(dependant.call, values) File "/home/ybZhang/miniconda3/lib/python3.8/site-packages/starlette/concurrency.py", line 40, in run_in_threadpool return await loop.run_in_executor(None, func, args) File "/home/ybZhang/miniconda3/lib/python3.8/concurrent/futures/thread.py", line 57, in run result = self.fn(self.args, self.kwargs) File "/data/disk0/zyb/gitcodes/400zhijian/asr_server_kefu_v9_fsmn_mutith.py", line 866, in recognize bounds_of_speechs_right = get_vad_speechs(wav_bytes_right_raw) File "/data/disk0/zyb/gitcodes/400zhijian/asr_server_kefu_v9_fsmn_mutith.py", line 382, in get_vad_speechs bounds_of_speechs = vad(bytes2numpy(wav_bytes)) File "/home/ybZhang/miniconda3/lib/python3.8/site-packages/funasr_onnx/vad_bin.py", line 116, in call segments_part = self.vad_scorer(scores, waveform_package, is_final=is_final, max_end_sil=self.max_end_sil, online=False) File "/home/ybZhang/miniconda3/lib/python3.8/site-packages/funasr_onnx/utils/e2e_vad.py", line 459, in call self.DetectCommonFrames() File "/home/ybZhang/miniconda3/lib/python3.8/site-packages/funasr_onnx/utils/e2e_vad.py", line 502, in DetectCommonFrames frame_state = self.GetFrameState(self.frm_cnt - 1 - i) File "/home/ybZhang/miniconda3/lib/python3.8/site-packages/funasr_onnx/utils/e2e_vad.py", line 422, in GetFrameState sil_pdf_scores = [self.scores[0][t - self.idx_pre_chunk][sil_pdf_id] for sil_pdf_id in self.sil_pdf_ids] File "/home/ybZhang/miniconda3/lib/python3.8/site-packages/funasr_onnx/utils/e2e_vad.py", line 422, in sil_pdf_scores = [self.scores[0][t - self.idx_pre_chunk][sil_pdf_id] for sil_pdf_id in self.sil_pdf_ids] IndexError: index 6513 is out of bounds for axis 0 with size 6000

这个问题我也遇到过,我猜测原因waveform长度在提取特征等操作的时候,wavform长度变了,导致index error ,你可以测试一下我的这个项目,和官方的代码上有一点不同,多线程官方是不支持的,而且vad有内存泄漏的风险,我在另一个项目paraformer-python有优化,多线程可以考虑后续支持

lovemefan commented 1 year ago

能否提供音频复现该问题?如果不能提供,能否使用本项目单独测试该音频

ben-8878 commented 5 months ago

能否提供音频复现该问题?如果不能提供,能否使用本项目单独测试该音频

应该和具体是哪个音频没关系,随便找个音频就可以,使用fastapi搭建一个服务,因为fastapi本身是多线程,然后客户端同时请求多个音频,就能看到错误了。 另外使用你的代码测试了下,和modelscope的那一套差不多,都报类似的错误。