fix:修复FunASR多设备连接时声纹识别配置相互覆盖的问题

This commit is contained in:
3030332422
2025-07-16 15:42:21 +08:00
parent 953a232654
commit 1a411da133
2 changed files with 26 additions and 20 deletions
+6 -11
View File
@@ -17,7 +17,6 @@ from core.handle.receiveAudioHandle import startToChat
from core.handle.reportHandle import enqueue_asr_report
from core.utils.util import remove_punctuation_and_length
from core.handle.receiveAudioHandle import handleAudioMessage
from core.utils.voiceprint_provider import VoiceprintProvider
TAG = __name__
logger = setup_logging()
@@ -25,13 +24,7 @@ logger = setup_logging()
class ASRProviderBase(ABC):
def __init__(self):
self.voiceprint_provider = None
def init_voiceprint(self, voiceprint_config: dict):
"""初始化声纹识别"""
if voiceprint_config:
self.voiceprint_provider = VoiceprintProvider(voiceprint_config)
logger.bind(tag=TAG).info("声纹识别模块已初始化")
pass # 将声纹识别从ASR实例分离,移到连接级别管理
# 打开音频通道
async def open_audio_channels(self, conn):
@@ -94,7 +87,8 @@ class ASRProviderBase(ABC):
# 预先准备WAV数据
wav_data = None
if self.voiceprint_provider and combined_pcm_data:
# 使用连接的声纹识别提供者
if conn.voiceprint_provider and combined_pcm_data:
wav_data = self._pcm_to_wav(combined_pcm_data)
@@ -129,8 +123,9 @@ class ASRProviderBase(ABC):
loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)
try:
# 使用连接的声纹识别提供者
result = loop.run_until_complete(
self.voiceprint_provider.identify_speaker(wav_data, conn.session_id)
conn.voiceprint_provider.identify_speaker(wav_data, conn.session_id)
)
return result
finally:
@@ -145,7 +140,7 @@ class ASRProviderBase(ABC):
with concurrent.futures.ThreadPoolExecutor(max_workers=2) as thread_executor:
asr_future = thread_executor.submit(run_asr)
if self.voiceprint_provider and wav_data:
if conn.voiceprint_provider and wav_data:
voiceprint_future = thread_executor.submit(run_voiceprint)
# 等待两个线程都完成