mirror of
https://github.com/xinnan-tech/xiaozhi-esp32-server.git
synced 2026-07-26 09:03:54 +08:00
fix: 同步方法使用线程池避免阻塞
This commit is contained in:
@@ -1,14 +1,16 @@
|
|||||||
import time
|
|
||||||
import os
|
import os
|
||||||
import sys
|
|
||||||
import io
|
import io
|
||||||
|
import sys
|
||||||
|
import time
|
||||||
|
import shutil
|
||||||
import psutil
|
import psutil
|
||||||
|
import asyncio
|
||||||
|
|
||||||
from config.logger import setup_logging
|
from config.logger import setup_logging
|
||||||
from typing import Optional, Tuple, List
|
from typing import Optional, Tuple, List
|
||||||
from core.providers.asr.base import ASRProviderBase
|
|
||||||
from funasr import AutoModel
|
from funasr import AutoModel
|
||||||
from funasr.utils.postprocess_utils import rich_transcription_postprocess
|
from funasr.utils.postprocess_utils import rich_transcription_postprocess
|
||||||
import shutil
|
from core.providers.asr.base import ASRProviderBase
|
||||||
from core.providers.asr.dto.dto import InterfaceType
|
from core.providers.asr.dto.dto import InterfaceType
|
||||||
|
|
||||||
TAG = __name__
|
TAG = __name__
|
||||||
@@ -90,16 +92,17 @@ class ASRProvider(ASRProviderBase):
|
|||||||
else:
|
else:
|
||||||
file_path = self.save_audio_to_file(pcm_data, session_id)
|
file_path = self.save_audio_to_file(pcm_data, session_id)
|
||||||
|
|
||||||
# 语音识别
|
# 语音识别 - 使用线程池避免阻塞事件循环
|
||||||
start_time = time.time()
|
start_time = time.time()
|
||||||
result = self.model.generate(
|
result = await asyncio.to_thread(
|
||||||
|
self.model.generate,
|
||||||
input=combined_pcm_data,
|
input=combined_pcm_data,
|
||||||
cache={},
|
cache={},
|
||||||
language="auto",
|
language="auto",
|
||||||
use_itn=True,
|
use_itn=True,
|
||||||
batch_size_s=60,
|
batch_size_s=60,
|
||||||
)
|
)
|
||||||
text = rich_transcription_postprocess(result[0]["text"])
|
text = await asyncio.to_thread(rich_transcription_postprocess, result[0]["text"])
|
||||||
logger.bind(tag=TAG).debug(
|
logger.bind(tag=TAG).debug(
|
||||||
f"语音识别耗时: {time.time() - start_time:.3f}s | 结果: {text}"
|
f"语音识别耗时: {time.time() - start_time:.3f}s | 结果: {text}"
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user